Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

winforms - C# form doesn't size properly

I'm doing a simple c# Windows Form project, and I found a problem in sizing my form.

If the form is smaller than size (872,495), everything's ok, but when I try to increase it, (both axes) it keeps stuck at that size, cutting out the rest of it.

I think I already found the problem, but I'm not very sure about that: I got a Lenovo Ideapad Flex 5 laptop, which has a monitor of 14'', so I think the program make a sort of automatic useless "auto-resize".

In fact, the form is in the same position with the same cuts (but fullscreen this time) when I disable AutoScaleMode to None. Doing this doesn't solve the problem, because I don't want to have the form fullscreen, I don't want the user to scroll through the window, it's uncomfortable.

The only way I found, proving I'm quite right, is going into Display settings of my computer and change everything to 100%, but doing so the text is unreadable, and I have a headache after 5 minutes.
SO, is it a way to maintain the screen zoom to 150% and watch my form just with the original size of c# editor?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In order to make sure it resizes correctly, make sure the following settings are as follows:

//Unless you want a maximum size, in which case, you can set the height and width. 
//When the maximum size is set to 0,0 the form has no limit in size besides the limits of the OS.
this.MaximumSize = new System.Drawing.Size(0, 0); 

//Allows the form to resize itself.
this.AutoSize = true; 

//Allows the form to both grow and shrink
this.AutoSizeMode = AutoSizeMode.GrowAndShrink; 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...