Very simple form F # locks on the keyboard

Using the ultra-simple code below, as soon as I press a key on my keyboard when the shape is in focus, the shape is completely locked. I run this inside F # interactive. The only way to close the form is to click "Reset Session" in F # interactive. I tried to add event handlers in KeyPress with the same results. I had no problems adding mouse event handlers, menus, combo boxes, etc.

I have to do something wrong, since it is obvious that pressing a key on a keyboard should probably not be a mistake at this point for F #. Any ideas?

// Add reference to System.Windows.Forms to project
open System.Windows.Forms

let a = new Form()
a.Visible <- true

I am using F # 2.0 for Windows + Visual Studio 2008 (April 2010 release) on Windows XP.

Thank!

+5
source share
3 answers

I think you need to call

Application.Run(a)

but I don’t have time to try and check now.

EDIT:

Useful thing: create a C # Windows Form project and see what code it starts from. This gives you the following:

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }

so of course you can do the same in F #:

open System.Windows.Forms 

let Main() =
    Application.EnableVisualStyles()
    Application.SetCompatibleTextRenderingDefault(false)
    Application.Run(new Form())

[<System.STAThread>]
do
    Main()
+3
source

You definitely don't need to invoke Application.Run(a)F # Interactive because it manages it with its own message loop (you really can't do this).

Creating the form and setting Visibleup trueshould work (and it works on my machine!) Unfortunately, I'm not sure what might cause the problem you reported, but this is definitely not expected behavior (this seems to be some error).

ShowDialog - , , F # Interactive . - F # Interactive - , . :

> let a = new Form();;
val a : Form = System.Windows.Forms.Form, Text: 

> a.Visible <- true;;  // Displays the form 
val it : unit = ()

> a.Text <- "Hello";;  // Changes title of the form
val it : unit = ()

( , .)

+2

F # PITA , Windows Forms. , , F #.

The only advice I can give is to use WPF instead, but getting reliable performance from F # interactive is still quite difficult. This is probably the most useful aspect of our F # library for rendering ...

0
source

All Articles