Winform Main Control Too Large - c#

I am developing a Winform application which should occupy the entire screen, the target device having 1920x1080 resolution.
The main control window is defined as follows:
MaximumSize 1920, 1080
Size 1920, 1080
MinimumSize 1918, 1078
StartPosition CenterScreen
To fill the screen I have added the following to the _Load method:
this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
this.Activate();
When I run the application the Control Window begins at the top left, as it should, but the rightmost 5th and the bottom 5th (approximately) of the form is off the screen. The controls that should appear in the cut-off regions are at appropriate locations (e.g. a label at Location 1712, 551, which should be within the boundaries of a 1920x1080 screen).
Can anyone explain? If I knew why this is happening, I'm sure the solution would be obvious.

I have added the following to the _Load method
Using the Load event handler is the problem. You are changing the layout metrics of the window after it was created. A window is maximized by giving it a negative location and a size that's larger than the screen by twice the border width. So that the border isn't visible.
But your code changes FormBorderStyle and now that location and size is not correct anymore. Since the window no longer has a border. So the window is too large and part of the client area is off the screen.
You must move the FormBorderStyle assignment into the constructor of the form so the window is created with the correct border. Setting the property with the designer is simplest.

It is possible your Windows installation is actually scaling the form. This can be done using the DPI settings (a cut-off of 1/5th sounds like a DPI setting of 125%), or by Windows 10 when it is self-adjusting.
The best thing to do is not rely on screen measurements to be correct. Instead, try to use as much panels that are capable of auto-sizing, like TableLayoutPanel and others. In that way you won't need to keep calculating, instead the framework will do that for you.

Related

Cannot Resize Form by Dragging In Designer

I have a Winform I want to resize. Not after launching; I want to resize it in the designer by dragging the edges.
I am aware that I can change the size manually in the form properties. This is not what I want to do. I want to quickly size the default size of the form with my mouse.
The problem appears to be that I cannot grab the edges of the form for some reason. I repeat, this is NOT DURING RUNTIME. It is not that I have disabled/enabled Autosize/Resizing.
It's almost like the edge grabs are a single pixel wide and I just can't hit it. I don't know. I've looked for accessibility settings. The last thing I want to do is reinstall MSVS. It's just maddening.
I've attached a photo. The little boxes on the bottom, right, and bottom-right corner are my targets.
you can try to click the form title before resizing. I think you may have a panel (or any container control) which is full docked in the form, that's why when you click the form body, you selected the panel instead of the form.
Another issue that I encountered was the windows font size was set to 120% (or more), so go to windows display setting and set the font size to 100%.

Lock form size in Windows Form Designer

I have a problem when working with a form that has a fixed size.
When I resize Visual Studio windows, the form resizes as well, even when being locked. It is a huge inconvinience because I can't get an idea of how my design would end up.
I am working with a fixed size aplication, that has a MDI child form.
I need the form to have FormBorderStyle to None, so I can't set it to something fixed.
Image of the form with desired size
Image of the form with deformed size
Set the MinimumSize and MaximumSize properties of the form to the desired size. This makes the from size fixed.
Note, this trick also works for single-line TextBox controls, if you want to set the height to a different height than the one automatically determined from the font size.

Is there a way to leave the resolution of a C# Windows Form Application fixed?

I want to fix the resolution of my main form, I can set the number of pixels using
this.Height = 480;
this.Width = 640;
But I want some way to make it constant, so that even if the frame is enlarged, the number of pixels will not change, but their size.
By setting the option AutoSizeMode to GrowAndShrink I can prevent re-sizing of the form by dragging the edges of the form, but when the maximize button is pressed, the form becomes big and adds new pixels. I want to allow the re-sizing of the form and putting it in maximized or fullscreen mode without changing the number of pixels in the form, or in other words, enlarging the size if the current pixels, instead of adding new pixels.
Is there a way too do it?
Pixels are fixed units. You probably would like WPF since its a vector based system.

create a form with formBorderStyle sizable and prevent resizing

Is it possible to create a form in C# that has formBorderStyle set to sizable but the user can't resize the form?
I know i can set the maximumSize and minimumSize to the same size and this will prevent resizing the form, but the cursor will still changes to resize when hovering over the border. And i don't want that.
I could use formBorderStyle = fixed but i am using sizable so the form looks like a windows 7 window. Is it possible to use "fixed" and apply some styles to the form so it looks like a sizable form (with the borders, transparency and the shade effect).
Thanks in for the reply's,
J.
EDIT:
Found the solution here:
How to create a form with a border, but no title bar? (like volume control on Windows 7)
Is FixedSingle not work for you? Forms are looking in the Windows 7 style too.

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

Categories

Resources