user7530757
user7530757

Reputation:

Why does my Windows Form in F# use a minimum width?

I'm trying to create basically a 100x100 image on the screen without any border or toolbox, but for some reason the minimum size is set at 150 it looks like. I tried using form.MinimumSize <- new Size(100, 100) and it does nothing.

Here's the full code.

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)

Upvotes: 1

Views: 56

Answers (1)

Tomas Petricek
Tomas Petricek

Reputation: 243096

It looks like you need to set the Width after setting the border style and after the form becomes visible. The following does the trick for me:

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

Upvotes: 1

Related Questions