What's preventing me from resizing (downsizing) my windows form object?

拟墨画扇 提交于 2019-12-08 14:35:34

问题


I've got a windows form object that contains 3 objects, a treeview, a richtextbox, and a tabcontrol. They are not docked into the windows form, but they are anchored (top+left).

I've written the code to resize them when a form-resize event handler gets called, but it only seems to be working for an increase of form size, that is to say, I can't resize the form to a smaller size. This includes times when I first increase the main windows form and then attempt to return it to its original size.

The sizes of the three objects are manually set after each Form resize with the code below:

        treeView1.Height += (this.Height - oldHeight);
        richTextBox1.Width += (this.Width - oldWidth);
        tabControl1.Width += (this.Width - oldWidth);
        tabControl1.Height += (this.Height - oldHeight);
        oldHeight = this.Height;
        oldWidth = this.Width;

None of the objects have a set minimum size (they are all at 0,0 throughout the resizing process)

What is preventing the form from being resized to a smaller size?


回答1:


Autosize (which was set on the main Form object) was preventing the window from decreasing to a size smaller than the objects contained within it. As the objects within the main Form increased on each expansive resize, the main Form was unable to shrink after any resize growth. By disabling Autosize on the main Form object, I was able to regain full control of resizing.




回答2:


If the above does not solve it, check that the form minimum size is not set to a value larger than you need.




回答3:


Right click your Winform in Visual studio -> select properties ->AutoSize will be set True -> Change it to False

OR

Include this line in your code

this.AutoSize = false;



回答4:


Just put all your Controls into a Panel and set Dock property of the Panel to Fill. I believe it works even with Autosize set to true.




回答5:


Check the Min Widths and Min Heights

Designer view:

As you can see, if you set the Min width and Min height, while having auto size set to false, then the buttons are now the size you want it to be :)




回答6:


I followed all the answers here, none worked for me. I went ahead and added the padding and it worked. head over to properties tab selecting the label and add padding.




回答7:


There may be one more way to correct the behavior of a form which cannot be resized by normal mouse selection.

Related to the discussion above, I discovered (using VB.net in VS2010) that one of my standard Windows forms would not resize with mouse selection. It is as though the FormBorderStyle was set to Fixed . Even changing FormBorderStyle to SizableToolWindow did not give the expected mouse-sizable behavior.

Here are some form settings from the form design Properties:

Autosize: false
AutoSizeMode: growonly
Doublebuffered: true
Enabled: true
FormBorderStyle: Sizable
ImeMode: NoControl
Locked: false
AutoScaleMode: Font
AccessibleRole: default

All of the visible or code Property settings of this form, and all of its Designer property settings too, were identical to other forms in the same project that would properly allow mouse resizing. Cleaning the solution, and Rebuilding it also did not fix the problem of the frozen form. Clicking Maximize did work, and so did click Minimize. The form size could be set by code as expected. Only mouse resizing of the form did not function properly.

I discovered that the desired mouse-selection resizing could be again enabled by setting, in code, by setting the parameter:

myForm.AutoScaleMode = Windows.Forms.AutoScaleMode.Inherit

This parameter had been set to .Font in the design of the form, which was also used in other forms that worked properly.

Then... strangely... changing it back from .Inherit to .Font in code also allowed the form to resize properly.

That setting in code (either to .Inherit, or to .Font) seemed to be the critical element to correct the form resizing trouble, in this case. It seems there are hidden parameters which the system does not show the user that somehow interfere with the expected operation of a form.



来源:https://stackoverflow.com/questions/3571041/whats-preventing-me-from-resizing-downsizing-my-windows-form-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!