将此代码移植到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

我有几个问题:

1.)我如何从基类访问成员?
{
    Text = "My Cross-Platform App";
    Size = new Size (200, 200);
    Content = new Label { Text = "Hello World!" };
}

我尝试使用覆盖,但它仅适用于大小,不适用于内容和文本。

2.)我如何将此行转换为f#Content = new Label { Text = "Hello World!" };

最佳答案

所以快速解决

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

应该
type MyWindow() as this =
    inherit Form()
    do this.Size <- Size(500,500)
    do this.Text <- "test"
    do this.Content <- new Label()

最后,
Content = new Label { Text = "Hello World!" }


let Content = new Label(Text = "Hello World!")

关于c# - 处理2个将C#转换为F#的编译器错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21359201/

10-10 02:22