我试图在屏幕上创建一个基本上没有任何边框或工具箱的100x100图像,但由于某种原因,最小尺寸设置为150它看起来像。我尝试使用form.MinimumSize <- new Size(100, 100)
,它什么也没做。
这是完整的代码。
open System
open System.Drawing
open System.Windows.Forms
let form = new Form()
form.Width <- 100
form.Height <- 100
form.FormBorderStyle <- System.Windows.Forms.FormBorderStyle.None
form.StartPosition <- FormStartPosition.CenterScreen
let picture = new PictureBox(SizeMode = PictureBoxSizeMode.AutoSize)
let bitmap = new Bitmap(100, 100)
for x in 0 .. 99 do
for y in 0 .. 99 do
bitmap.SetPixel(x, y, Color.Red)
picture.Image <- bitmap
form.Controls.Add(picture)
[<STAThread>]
Application.Run(form)
看起来你需要在设置边框样式后和窗体变得可见后设置Width
。以下是我的诀窍:
let form = new Form()
form.FormBorderStyle <- System.Windows.Forms.FormBorderStyle.None
form.StartPosition <- FormStartPosition.CenterScreen
let picture = new PictureBox(SizeMode = PictureBoxSizeMode.AutoSize)
let bitmap = new Bitmap(100, 100)
for x in 0 .. 99 do
for y in 0 .. 99 do
bitmap.SetPixel(x, y, Color.Red)
picture.Image <- bitmap
form.Controls.Add(picture)
form.Show()
form.Width <- 100
form.Height <- 100