[英]What is the C# version of this simple F# code to construct a basic Windows.Form?
I'm just starting to learn F# and C# together. 我刚开始一起学习F#和C#。 The following F# code is a slightly tweaked example from Chris Smith's Programming F# book.
下面的F#代码是Chris Smith的Programming F#书中略有调整的例子。
What would the equivalent in C# look like? C#中的等价物会是什么样的?
open System.Windows.Forms
let form = new Form(Text="Click Me", TopMost=true)
form.MouseClick.AddHandler(
new MouseEventHandler(
fun sender clickArgs -> printfn "MouseClickEvent @ [%d, %d] %O" clickArgs.X clickArgs.Y clickArgs.Button
)
);;
form.ShowDialog();;
Fumbling in the dark since I don't know F#, but here goes: 因为我不知道F#而在黑暗中摸索,但是这里是:
using System.Windows.Forms;
namespace Answer
{
class Program
{
static void Main(string[] args)
{
Form form = new Form { Text = "Click Me", TopMost = true };
form.MouseClick += (s, e) => {
System.Console.WriteLine("MouseClickEvent @ [{0}, {1}] {2}",
e.X.ToString("d"),
e.Y.ToString("d"),
e.Button.ToString()
);
};
form.ShowDialog();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.