Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winforms 在窗体中水平居中对齐窗体控件_Winforms_F# - Fatal编程技术网

Winforms 在窗体中水平居中对齐窗体控件

Winforms 在窗体中水平居中对齐窗体控件,winforms,f#,Winforms,F#,如果我有以下代码,并希望将按钮控件与窗体的水平中心对齐 let myForm:Form = new Form() myForm.Text <- "myForm" myForm.Height <- 500 myForm.Width <- 500 let button:Button = new Button() button.Text <- "Click" myForm.Controls.Add(button) button.Location <- Point(20

如果我有以下代码,并希望将按钮控件与窗体的水平中心对齐

let myForm:Form = new Form()
myForm.Text <- "myForm"
myForm.Height <- 500
myForm.Width <- 500  
let button:Button = new Button()
button.Text <- "Click"
myForm.Controls.Add(button)
button.Location <- Point(200, 20) 
// Using this code to align this control to center
let myForm:Form=new Form()
myForm.Text这是我在C#中的做法。也许它能帮助你

Resize += new EventHandler(Form1_Resize);
以及:

这就是我在C#中的做法。也许它能帮助你

Resize += new EventHandler(Form1_Resize);
以及:


将@ispiro的答案转换为F#-如果希望在每次调整表单大小时重新居中

Form1.Resize.Add (fun _ -> button1.Location <- new Point(this.ClientSize.Width / 2 - button1.Width / 2, button1.Location.Y))

Form1.Resize.Add(乐趣->按钮1.Location将@ispiro的答案翻译为F#-如果您想在每次调整表单大小时重新居中

Form1.Resize.Add (fun _ -> button1.Location <- new Point(this.ClientSize.Width / 2 - button1.Width / 2, button1.Location.Y))
Form1.Resize.Add(乐趣->按钮1.位置