System.Windows.Forms

Editor
Jul 22, 2009 at 4:44 AM

Hello,

 I wanted to use the define-clr-class syntax to do some windows forms programming. I just don't know how to translate from C# or Nemerle to IronScheme. It would come from (in Nermle):

using System.Drawing;
using System.Windows.Forms;
 
class MyFirstForm : Form {
public static Main() : void {
Application.Run(MyFirstForm());
}
}

So really all i need to know is how to declare a class of type Form with the Main method of type void. I should be good with the rest. Thank you. Good day.

Yemi Bedu
Coordinator
Jul 22, 2009 at 7:06 AM

Hi Yemi

Unfortunately, define-clr-class was never finished (or started really). 

I am still thinking about ideas how to handle it, but this is something I will need in the next version of IronScheme.

Sorry :(

leppie

PS: you could always provide a 'stub' class in C# and import that in to IronScheme, and then hook up various procedures. Example

class MyForm : Form
{
   public Callable load;
   protected override void OnLoad(EventArgs e)
   {
      load.Call(this, e);
   }
}

/*
(define (form-load form e)
  ... )
*/

 

 

Editor
Nov 6, 2009 at 4:01 PM

Hello,

 I wanted to revisit using purely IronScheme to define and run my application. I see now under the ironscheme folder that define-clr-class has been completely removed. I don't want to spend my time jumping between C# stubs and my running scheme app.  What is available to help me accomplish this goal? Thank you. Good day.

 

Yemi Bedu

Editor
Nov 6, 2009 at 4:35 PM
Edited Nov 6, 2009 at 4:39 PM

Hello,

 I decided to *not* be impatient and look through the examples under the ironscheme folder. I will write up demonstration application soon. You are excellent. Thank you. Good day.

Yemi Bedu

Editor
Nov 6, 2009 at 8:14 PM

Hello,

 So here is the app and it works as expected  (this forum editor hates tabs):

; BAD SCHEME PROGRAMMING STYLE (LIKE UGLY C STYLE, BUT I LIKE IT)

(import
(rnrs)
(ironscheme clr)
)

(clr-reference System.Windows.Forms)

(clr-using System.Windows.Forms)

(begin
; INITIALIZE
(define mainForm (clr-new Form))
(define btnGo (clr-new Button))
(define mainControls (clr-prop-get Form Controls mainForm))

; SETUP EVENTS
; mouse enter
(define mainForm_MouseEnter
(lambda (s e)
(display "Enter")
(newline)
)
)

; mouse leave
(define mainForm_MouseLeave
(lambda (s e)
(display "Leave")
(newline)
)
)

; click
(define btnGo_Click
(lambda (s e)
(display "GO")
(newline)
)
)

; APPLY EVENTS
(clr-event-add! Form MouseEnter mainForm mainForm_MouseEnter)
(clr-event-add! Form MouseLeave mainForm mainForm_MouseLeave)
(clr-event-add! Button Click btnGo btnGo_Click)

; SET PROPERTIES
(clr-prop-set! Form Text mainForm "Information Viewer")
(clr-prop-set! Button Text btnGo "GO")

(clr-call Form+ControlCollection Add mainControls btnGo)

; SHOW FORM AND RUN PUMP
(clr-static-call System.Console WriteLine "Start")
(clr-static-call Application (Run Form) mainForm)
(clr-static-call System.Console WriteLine "Stop")

; REMOVE CONTROLS
(clr-call Form+ControlCollection Remove mainControls btnGo)

; REMOVE EVENTS
(clr-event-remove! Form MouseEnter mainForm mainForm_MouseEnter)
(clr-event-remove! Form MouseLeave mainForm mainForm_MouseLeave)
(clr-event-remove! Button Click btnGo btnGo_Click)
)

This is one of the greatest dynamic languages for the CLR. Thank you. Good day.

Yemi Bedu

Coordinator
Nov 10, 2009 at 7:21 PM

Yeah, not quite Scheme style, but it works.

And I am still wondering on how to define classes! I have to figure it out soon though, so I can write the entire compiler in Scheme  :)

Cheers

leppie

Editor
Nov 12, 2009 at 3:19 PM

Hello,

 I am now starting to use the with-clr-type syntax to work on the forms creation and manipulation (sweet). Can you add the clr-event-add! and clr-event-remove! forms to the shorthand library? That would be cool as it is the one other bit that I am still doing heavy typing for.

Also, it would be nice if we could contribute to the documentation as is possible here:

http://ironruby.net/Documentation/.NET/WinForms

Again thank you. Great work. Good day.

Yemi Bedu

Editor
Nov 12, 2009 at 3:24 PM

Hello,

 Newer version, incorporating the with-clr-type form.

; BAD SCHEME PROGRAMMING STYLE (LIKE UGLY C STYLE, BUT I LIKE IT)

(import
    (rnrs)
    (ironscheme clr)
    (ironscheme clr shorthand)
)

(clr-reference System.Windows.Forms)
(clr-reference System.Drawing)

(clr-using System.Windows.Forms)
(clr-using System.Drawing)

(begin
    ; INITIALIZE
    (define mainForm (clr-new Form))
    (define btnGo (clr-new Button))
    (define btnStop (clr-new Button))
    (define mainControls (clr-prop-get Form Controls mainForm))
    
    ; SETUP EVENTS
    ; mouse enter
    (define mainForm_MouseEnter
        (lambda (s e)
            (display "Enter")
            (newline)
        )
    )
    
    ; mouse leave
    (define mainForm_MouseLeave
        (lambda (s e)
            (display "Leave")
            (newline)
        )
    )
    
    ; click
    (define btnGo_Click
        (lambda (s e)
            (display "GO")
            (newline)
        )
    )
    
    ; click
    (define btnStop_Click
        (lambda (s e)
            (display "STOP")
            (newline)
        )
    )
    
    ; APPLY EVENTS
    (clr-event-add! Form MouseEnter mainForm mainForm_MouseEnter)
    (clr-event-add! Form MouseLeave mainForm mainForm_MouseLeave)
    (clr-event-add! Button Click btnGo btnGo_Click)
    (clr-event-add! Button Click btnStop btnStop_Click)
    
    ; SET PROPERTIES
;    (clr-prop-set! Form Text mainForm "Information Viewer")
;    (clr-prop-set! Button Text btnGo "GO")
    
    (let ((mf mainForm))
        (with-clr-type ((mf Form))
            (mf : Text = "Information Viewer")
        )
    )
    
    (let ((bg btnGo) (bs btnStop))
        (with-clr-type ((bg Button) (bs Button))
            (bg : Text = "GO")
            (bg : Location = (clr-new Point 10 20))
            (bs : Text = "STOP")
            (bs : Location = (clr-new Point 100 20))
        )
    )
    
    (let ((mc mainControls))
        (with-clr-type ((mc Form+ControlCollection))
             (mc : Add (btnGo))
             (mc : Add (btnStop))
        )
    )
    
    ;(clr-call Form+ControlCollection Add mainControls btnGo)
    
    ; SHOW FORM AND RUN PUMP
    (clr-static-call System.Console WriteLine "Start")
    (clr-static-call Application (Run Form) mainForm)
    (clr-static-call System.Console WriteLine "Stop")
    
    ; REMOVE CONTROLS
    (let ((mc mainControls))
        (with-clr-type ((mc Form+ControlCollection))
            (mc : Add (btnGo))
        )
    )


    ;(clr-call Form+ControlCollection Remove mainControls btnGo)
    
    ; REMOVE EVENTS
    (clr-event-remove! Form MouseEnter mainForm mainForm_MouseEnter)
    (clr-event-remove! Form MouseLeave mainForm mainForm_MouseLeave)
    (clr-event-remove! Button Click btnGo btnGo_Click)
    (clr-event-remove! Button Click btnStop btnStop_Click)
)

 

Good day.

Yemi Bedu

Coordinator
Nov 13, 2009 at 7:14 AM

Hi Yemi

I am still thinking of a nice syntax for events, it would be handy  :)

I also added you as a wiki editor, so feel free to add any additional info and examples.

Cheers

leppie