开发者

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

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 a开发者_如何学Pythont 0,0 throughout the resizing process)

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


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.


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


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;


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.


Just change default MinimumSize in form's properties to a number other that zero (like 10)


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.


Check the Min Widths and Min Heights

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

Designer view:

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

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 :)


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.


I was able to resolve this for myself (found this question while looking for my own answer) by setting the FormBorderStyle to SizableToolWindow. It appears the Sizable border style has some sort of default minimum width baked into it (I couldn't get it below 136), while SizableToolWindow does not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜