MonthCalendar Control not "obeying"? (CalendarDimensions) - c#

The MonthCalendar's CandendarDimnesions is set to 1,1. But when run in large resolutions the dimensions Y increases. Screenshots are attached for better understanding.
How do I make sure it won't grow?

You have Anchor set to Top, Bottom, Right. If you don't want the Calendar size to change, don't anchor to Top and Bottom - only one or the other.

Related

Stretching controls to take full screen

I am making a video game. I need that it will be available at full screen mode, and with different resolutions.
I already know how to make application maximized and how to remove the built-in user interface, that is not the problem.
The problem is, that when I run it in full mode, all controls simply take the top-left corner, leaving the remaining space empty.
What I want, that controls would be spread evenly across the screen, with new coordinates and sizes, but same proportions.
I tried using anchoring. It works, but only when there is just one control. When there are more controls, and in my menu bar there are 12, and I try using anchoring, they are stretched, but put on top of each other.
Is there a way to get the right result? If so, can you please help me?
Thank you in advance,
Evgenie
Use TableLayoutPanel, anchor it to the left, right and bottom of the form, set ColumnCount=3, RowCount=1, edit column sizes in the Columns property, then drop buttons into corresponding cells and align them using their Dock, Anchor and Padding properties.
There is 'Dock' property for controls. You can add controls to a TabaleLayoutPanel and set the Dock property to DockStyle.Fill.
some ways i remember through which you can achieve it
Dock - MSDN link
Anchor - MSDN link
programitically setting the location according to the screen resolution ration

How to deal with controls and form's stretching in WinForms

Suppose that I have the following form in Designer:
I want to give users the ability to stretch this form as they want and all controls should be located like in the picture, no matter how user changed the size of this form, so they should take the same amount of space and stick to the same controls and borders.
How can I do it in WinForms? I know that there are such things like Docks etc, but I didn't find the correct way to use them in this situation.
You want the Anchor property in this case, not Dock. Anchoring means that a control will always keep the same distance to certain sides (top, left, right, and/or bottom) even if it means that the size must be changed; docking OTOH does not care about margins, it just fills up all available space on one or all sides.
Here's what you might want to do:
Anchor the two image buttons to the top and right.
Anchor the OK button to the right and bottom (I guess).
Anchor the large ListBox to all sides.
Just To Add some notes on good answer of stakx
For Controls Like ListBox that have a limit to their height, setting anchor is not enough and you should set IntegralHeight of them to false.
I reccomend to set MinimumSize of Form to prevent a user from sizing a window to an undesirable size.In your case Set it to a minimum acceptable size to prevent ugly small form with an unusable ListBox.

How to scale the size of textbox in Windows c# form

What I'm trying to do here is to have a textbox that'll grow in size as the tool is maximized.
This is the default size:
This is when I increase the size of the form:
I have used 'Anchor' property for this. Under the 'Target Database' section, the server has Top Anchor property set. While for it's textbox, Top, Left, Right is used.
What exactly I want is for the textbox to grow in size to the right and also move to right.
Is it possible? Please suggest ways to do it. Thanks in advance.
EDITED
Can I change the location of a control in c# when it has left anchor property?
The anchor property tells the runtime to which edges of the window (or the parent control) it keeps the distance constant when the parent size changes.
To have the text box grow, "top, left, right" is the right choice, but the label should at least also have "left" (besides top) added, or it won't move the same way.
I would suggest you add a groupbox for each of your sides, this will probably make things a bit easier, as then each of the two sides are independent. You will probably need "top, left, right, bottom" for the boxes and then "top, left right" for all input controls and "top, left" for the labels. (Hint: "top, left, right, bottom" is not the same as "fill")
You need to put a smart logic in using its Dock ,Anchor properties. Better you have your controls in any suitable Layout Panel .
you can also use the SetBounds() method in the resize event if you maximize window with pre-defined resolution .
You also can read about managing it with Dock and Anchor properties here and here .But you need to be careful about moving controls too.

Anchoring - Make two components take up half of panel each

What I have:
I have a panel (the white space), and two DataGridViews represented by the green and blue squares. The panel is anchored to take up most of the center of my screen, and grows/shrinks with the window size.
What I need:
I would like the green square to always stay with it's right border in the middle of the screen and take up the left half of the screen. Equally, I'd like the blue square to stay with its left border in the middle and to take up the right half of the screen.
Basically, I just want it to always look like this image regardless.
Do I need to do this programmaticly? I can't seem to find a combination of anchoring or docking that makes this happen, and adding more panels as containers yields the same issue in the end.
Not sure if this is what you want:
Creating a SplitContainer on the screen.
Anchor = Top, Bottom, Left, Right
IsSplitterFixed = True (Trick)
Creating another two datagridviews, each a side inside the SplitterContainer
Dock = Fill
I generally use a TableLayoutPanel to accomplish this. It is very easy to use (a simple introduction can be found here).
You create to cells in the first row and set it to 50% width each. In each cell you put one DataGrid and you set their Dock'ing to Fill.
I tried the solution with the TableLayoutPanel, which works ok.
But layouting inside the TableLayoutPanel is a bit unhandy and restricted if you want to use different positioning.
I found another solution which does it with a little of programming effort:
For the left item define anchoring to left
For the right item define no left/right anchoring
This leads into the left item remaining at its location when resizing the form and the right to move staying about the middle location.
The I added an OnSizeChanged handler to the form, which implements these lines:
int widthForItem = Item2.Left - Item1.Left; // you can subtract a distance here
Item1.Width = widthForEachItem;
Item2.Width = widthForEachItem

auto-scaling size with anchors - overlapping controls

I'm having some trouble with resizing and scaling of controls in a windows form. I've set anchors up so that the controls stay in ratio with the form, which works great. However, perhaps i was expecting too much when i thought that the control origin points would also scale and change with the form scaling, but this is not the case and i'm finding my controls overlapping. here's some screenshots;
anyone know of an approach i can take to solve this problem? perhaps i need to set control origins to dynamic drawing points that scale, but then do these redraw on scaling the form, or only on creation?
edit 1: just found this question hidden amongst the internet, Problem: Anchored controls are overlapping perhaps i need to implement something like this, a resize event.
The preferred solution should be the TableLayoutPanel. Handling OnResize is going to be much more fragile.
I wonder if Anchor is really about scaling, it basically anchors the sides of a control to the container and scaling is a by product of this. For eg. if both left & right sides are anchored the control will scale in width because anchor will try to keep the location of left & right sides intact.
keeping that in mind you have to think what do you want when the form is increased in size and you have more space. In the case above you might want the list box lbLog to say remain same size but the panel Simulate take up any sapce created. For such a scenario you would anchor the panel on both left & Right side while you will anchor the list box only the right.
Basically if you want all your controls to proportionally scale (true scaling I would say as opposed to scaling in case of anchoring) then Anchoring is not the right solution.

Categories