I am searching a way to put a ComboBox over another Control with xaml. The new combobox should aligned on the right side of the window.
How can I do this?
Best Regards, Thomas
You can use Grid panel. If you do not specify Row/Column of the controls inside the Grid, they will overlap.
Another solution is to use Canvas layout, which is almost like what you have on WinForms, where you can set X/Y of the control and you have more control on where they should appear.
Related
I have two elements in the form, two GridViews.
Both of them are aligned horizontally at the same level.
When my form is resizing, I want both of them to change their width/ height according to the form size.
The problem is, if I try to anchor them, they kinda overlap at some point and I want to avoid that.
My question is, can I anchor one Grid View to the other Grid View and not to the form?
A solution can be a TabelLayoutLabel, but i don't really want to use this.
My question is, can I anchor one Grid View to the other Grid View and not to the form?
no you cannot, and if you could that would be bad practice.
the anchor property description by microsoft:
Gets or sets the edges of the container to which a control is bound
and determines how a control is resized with its parent.
a dataGridView is not a container it's a control.
it sounds like you should use a table layout panel, that would give you the best results.
search for it in the Toolbox:
make sure you set its property to Dock = fill, where ever you want, and
,
next. in the property of the table view, you enter Edit Rows And Columns
and set each column to the percentage that you desire
add your grids to each column,
and set each one's 'Dock' property to Fill, and there you go
you can undock the tableLayoutPanel and change its size,
Hope that was helpful
I have a listview that I want to give the user the chance to resize the height of items similar to a gridsplitter. Is there any such control for this purpose?
I am using wpf and .net 4.5, c#
What you can do is use a canvas with two listviews, and then use a thumb control to allow you to resize those listviews.
Thumb control: http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.thumb(v=vs.110).aspx
The quickest way is to use DataGrid and set its RowHeaderWidth to the desired value to make the splitter area more visible to user.
Why does the WinForms SplitContainer hide all the Buttons in a Panel (in the left Splitter) when I resize on of its panels? Do I have to write specific code for invalidation of the Panel?
Yes, there's a solution. You can use Anchor property of SplitContainer in winforms. Using which you can set the value of the anchor as you required.
EDIT:
Anchor property will make your control fixed to the winforms design. Even if you resize the control, all the controls that the major control is holding will also resize according to it.
I need to create a custom control that has an expandable part as a panel and a textbox part. The expandable part is a panel, that will either be visible or invisible. But when the panel is visible/expanded directly under the textbox, I do not want the adjacent controls to shift down below the panel, but the panel should just overlay the controls that are there just under the custom control. How would I implement this in Winforms C# project?
I am open to using user control for this scenario.
Thanks
Sunil
I think your implementation of expanding and collapsing is not the best, because you are just overlaying the controls instead of hiding them.
One of the disadvantages is that the overlaid controls might by focussed by pressing tab and they might have a value which I think it is out of target.
I would suggest another implementation by creating two panels (one for the header and another one for the content) and when the collapse button is pressed then the content's panel will be hidden by sitting its Visible property to false and its Hight to 0.
I'm new to Windows Forms in Visual Studio, and I am wondering how to automaticly resize controls to the window size.
Say, I have 2 controls in a panel, a List Box and a Button. I want the button to dock to the bottom, and I want the List Box to fit the rest of the space. when the window resizes, the button should be at the bottom (as expected with docking), and the list box should stretch down to the button.
Is there a way to do this without any code?
Thanks.
Dock is pretty easy to use, but I recommend using the Anchor properties instead. Resize your form to a reasonable size in the Designer. Then, place your controls to look the way you want. Then, decide which controls should resize with the form and set the Anchor property as follows:
If you want the control to resize with the form in width, set the Right anchor.
If you want to resize height, set the Bottom anchor.
If you want the control to stay right when the form resizes, unset the Left anchor.
If you want the control to stay bottom when the form resizes, unset the Top anchor.
The problem I have with Docks is that they sometimes act funny when controls are not declared in a specific order, and to get the effect you want, sometimes you have to create extraneous panels just to hold controls.
It really gets messy when you want to maintain the aspect ratio of each control. One way, which is not really up to the mark if you want to get into fixing the details, is to use TableLayoutPanel and use Dock and Anchor wisely to achieve what you want.
Use the dock and fill options on the controls. Look under properties for each object, and containers if they are in any.
You can use SplitContainer
Google for examples. Here is one
Try setting your ListBox's Dock property to Fill.
You'll need to watch for one thing though: by default the ListBox will size itself to display whole list items. If you resize the control so that it displays a partial item it will adjust itself so it will display a complete item. This can make the control appear to lose its 'Dock'ing behavior. The solution for this is to set the ListBox's IntegralHeight property to false, which specifies that the control not resize itself to fit complete items.