Reputation: 16158
I am having some trouble porting this code to f#
public class MyForm : Form
{
public MyForm ()
{
Text = "My Cross-Platform App";
Size = new Size (200, 200);
Content = new Label { Text = "Hello World!" };
}
[STAThread]
static void Main () {
var app = new Application();
app.Initialized += delegate {
app.MainForm = new MyForm ();
app.MainForm.Show ();
};
app.Run ();
}
}
open System
open Eto.Forms
open Eto.Drawing
type MyWindow()=
inherit Form()
override this.Size = Size(500,500)
override this.Text = "test" // no abstract property was found
override this.Content = new Label() // no abstract property was found
[<STAThread>]
[<EntryPoint>]
let main argv =
let app = new Application()
app.Initialized.Add( fun e -> app.MainForm <- new Form()
app.MainForm.Show())
app.Run()
0 // return an integer exit code
I have a few problems:
1.) How do I access members from the base class?
{
Text = "My Cross-Platform App";
Size = new Size (200, 200);
Content = new Label { Text = "Hello World!" };
}
I tried it with override, but it only works for Size and not for Content and Text.
2.) How do I translate this line to f# Content = new Label { Text = "Hello World!" };
Upvotes: 2
Views: 127
Reputation: 25526
So a quick fix
type MyWindow()=
inherit Form()
override this.Size = Size(500,500)
override this.Text = "test" // no abstract property was found
override this.Content = new Label() // no abstract property was found
should be
type MyWindow() as this =
inherit Form()
do this.Size <- Size(500,500)
do this.Text <- "test"
do this.Content <- new Label()
finally,
Content = new Label { Text = "Hello World!" }
is
let Content = new Label(Text = "Hello World!")
Upvotes: 6