Simple question I hope.... I have a Win Form with a Tab Control and 12 tabs. When I added the eight table (and higher), the scroll bar in the tab header appears and you have to scroll with that control to view the extra tabs. How can you change the layout so that the tabs all show, without the scroll bar? Is it possible to have them appear "stacked" or "Multiline"?
Set the Multiline property to true.
tabControl1.Multiline = true;
As simple as that.
I don't think I've seen what you're describing before unless for some reason I've accidentally haven't set the proper width of the control. Have you tried setting the width to something less than the width of the area you're describing....and maybe make sure to use a pixel value vs. a percentage just to narrow it down perhaps.
Related
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.
I already tried putting a back color for each of the tab pages - but the extra space for the buttons of the tab control still takes the default color.
You could make the window smaller overall, to be the width of the list of tabs. Although I'm not sure if you can sacrifice the space.
Other than that, I'm not sure if you can with the default Windows Controls. Try looking into something like Infragistics, which adds on to the default windows controls with their own.
I have 3 buttons in my form. What I need to do is when I make the actual form bigger or smaller, the buttons should change their position and size so they look good, so they wouldn't remain the same size and position. I tried to use the anchors, but that does not work very well. What can I use to solve my problem?
You can check dock and anchor properties
http://www.youtube.com/watch?v=afsx1IJULLI
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock(v=vs.110).aspx
You should set both left and right, or top and bottom anchors to resize control. If you'll set only one anchor from these pairs, then control will be positioned instead of resizing.
Docking will resize control, because it is equivalent of setting three or more anchors.
Try using TableLayoutPanel, put your buttons inside the columns of the table
Look good is different all the time. I like placing buttons in StackPanel and setting AutoSize property to true. This fixes two issues:
If user has 150% font in Windows settings - your UI does not break;
if you resize window to be very small - your buttons do not enforce minimal width/height and adapt to ratio user has chosen
I want to change size of TabPage in my TabControl,
each tab should be in one line without scroll.
the second question is about how to change Text into Image like here (Please, ignore the green line):
edit. I used Winforms.
Ad 1.
There is no way to adjust width of tab pages to fit width you want automatically, so you just have to do some maths to achieve this.
Ad 2.
First you have to create an ImageList object, which you will then pass to your TabControl:
ImageList il = new ImageList();
il.Images.Add("your_graphics_name", Image.FromFile(#"C:\Graphics\example.png"));
(...)
yourTabControl.ImageList = il;
Then you can set specific image from your image list on your tab page by giving it's key:
yourTabControl.TabPages.Add("title", "text", "your_graphics_name");
The size and layout of tabs is quite strictly controlled in WinForms. You can of course change the font and font size which will have an implicit effect on the size of the tabs, but this isn't what you want to do by the sounds of things.
Now apparently Windows does allow you to regulate the minimum default tab width, but you can't do it directly with the out-of-the-box WinForm control. This article explains how: How can i make WinForms TabPage header width fit it's title?.
You may want to consider a 3rd party tab control if this begins to pose a serious problem for you design-wise.
Like others said you can't change width of your tabs. But you can make your tabs for example in two rows, if they don't match the screen:
tabControl.Multiline = true;
im wondering if theres an easy way to get the width of a control in WPF at runtime while the control is collapsed.
when i use control.Width ill get the following result: -1.#IND
and control.actualWidth will return 0.0 because its collapsed.
i want to resize my window and then display the collapsed control.
thanks
Edit:
Some details
i have a grid with 2 columns in my window, the 1st column holds a tab control, the 2nd column holds an expander control. i want to extend the width of my window when expanding the expander control, so the content in the 1st column will remain its size.
Put the control in question inside a container (like a ContentControl) and collapse the container rather than the control itself. Then you should be able to simply call Measure (or use the DesiredSize property) on the control to determine how much room it wants.
What size do you expect to get?
The size is not just dependent on the control but also on its container. So the actual size can not be determined unless the control is actually rendered.
Instead of using Collapsed you could make it Invisible that way it will be sized by its own logic and the logic of the container.
EDIT
In the comments it became clear that what the reason was for needing the size of the control:
I have a grid with 2 columns in my
window, the 1st column holds a tab
control, the 2nd column a holds an
expander control. i want to extend the
width of my window when expanding the
expander control, so the content in
the 1st column will remain its size.
My answer:
Set the SizeToContent of the window to WidthAndHeight and set the width of both grid columns to auto. That should take care of it.
I believe you're going about this the wrong way. You can set the Window Width and height to "Auto" and then it will take care of all the resizing stuff.
The problem arises whenever you directly set the Width property of any control(trust me I've done it). Once you do that, you've told WPF hands off of resizing logic, I know what I'm doing.
If you think something isn't resizing at the right time you can add a handler to some event and then call control.InvalidateVisual() or control.InvalidateMeasurement() which will make it go through a whole new layout pass.
You have to call the UpdateLayout method on the control or conainer of control. After that the things may work properly.
In UWP you can determine size of collapsed control by making it visible for a sec and then hiding it again, change is not noticeable:
var oldVisibility = myBorder.Visibility;
myBorder.Visibility = Visibility.Visible;
myBorder.UpdateLayout();
var height = myBorder.RenderSize.Height;
myBorder.Visibility = oldVisibility;
Post which is marked as an answer actually does not answer the question, it just gives a workaround.
To get the size of the collapsed control you need:
Set control's visibility as Hidden (Collapsed won't evaluate).
Call Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)) method of the control.
Get the size from DesiredSize property of the control.
Then you can Collapse your control back.