c# How to make a button ignore panel vertical scrollbar? - c#

I have a panel on which I placed some ComboBoxes , 2 Buttons and a Scrollbar. I want my buttons to stay where they are, while ComboBoxes will follow the Scrollbar. So far, I've found one solution, on my first Panel I added another one, where I placed my buttons but it's kind of weird. Is there any other solution?

You need to place the buttons outside the Panel; right below it. You can then set their Anchor property as well to ensure they move when the Form is resized. That being said, you'll want to set the Anchor property of the Panel appropriately as well.

Related

TableLayoutPanels inside Panel AutoScroll issue

I currently have a GroupBox, which holds a Panel, which holds multiple TableLayoutPanel controls. The reason i want to do this is so that i can place headers, buttons and options between the table layout panels, but have everything in the GroupBox seem to be "scrollable" even though the Panel is the one handling the scrolling.
A perfect example of this is the "Advanced Settings" for an Application Pool in IIS7... sorry i can't really put this visual into text more than that.
The problem I am having is that the Panel simply does not want to "enable" its AutoScroll even when there are TableLayoutPanel s that very obviously go beyond the bottom of the Panel itself. However, if i place a Label there instead, it works.
Is there a reason why this is happening? Should there be some setting set for the TableLayoutPanel in order to have it register in the Panel control?
It turns out that by having the TableLayoutPanels anchors set to None, the scrolling didn`t work. As soon as i set them to Top, Left, the scrolling enabled.

How do I set dock property of a datagridview properly?

In a datagridview when I set:
Anchor: Top,Left
AutoSizeColumn: Fill
Dock: Fill
Which will expand or shrink the datagridview based on size of the form, and covers the whole form. But what of I have controls on the right side on the form? I don't want to overlap my linkbuttons with my gridview. I know there's a "Margin" and "Default Cell Style" property with padding values (specifically using "right padding" to try and reduce width from the right of the right edge of the form). So I tried messing with that, didn't do anything I want. Or was I working with the right properties, just not setting them right?
Put those controls you want on the right in a Panel.
Set the DockStyle of that panel as DockStyle.Right.
If you can't see the right edge of the Datagrid means, you have to bring the Datagrid to front by selecting it, right click and choose bringToFront.
Or Send the Panel to back.
1.Use a panel to split the form into two sections.
The right section is placed with DataGridView, and the left section is placed with a panel which is used to contain your other controls, like linkbuttons.
2.Set the Dock property of this panel to Right.
3.Set the Dock property of this DataGridView to Fill.

Why do some objects appear on top of others, and not always like that?

I created 2 empty labels, using winforms, to cover some groupboxes
They were created exactly the same way, but they dont behave the same way
The first one:
The second one:
The first covers everything, the second one only covers one groupbox, and displays the other two.
I tried the right click+ send to back /send to front, but I believe this doesn't mean anything in the code, it only purpose is to allow you to visualize better what you are placing in your form, I guess.
Can someone shed some light?
Groubox, Panel, TabPage etc are containers in which we keep controls. Form itself is also a container..
When you drag a label or any other control to place in a form, and if you want to hide the other controls, you should place the label in the form itself and the label should not become child of any of the groupBoxes.
For that the left top corner of the label you drag should not go inside any of the groupBoxes. This is only when you drag. If you want to position at a point inside groupBox, then Drag the control outside the groupBox and then use keyboard arrows to position, this will not let the control to become child of the groupBox. You can also set position on property window.

Prevent Child Components when Overlapping Panel

I have a WinForms application which has two panels which individually contain a usercontrol component (one in each panel). How ever, because both panels are the same size and in the same location, the top most panel becomes a child of the other panel. I want to be able to hide one panel and then show the other panel:
this.panel1.visibile = false;
this.panel2.visibile = true;
But when I hide panel1, the second panel is hidden as well.
How can I make panel2 a non-child of panel1?
I like to keep things simple because I'm new to C# Programming.
This is a common accident in the designer. Dropping the second panel on top of the first one will make it a child of the first panel. Two basic strategies to fix this:
View + Other Windows + Document Outline. Click the second panel in the list and drag it to the form. You'll need to fix up the Location property by hand by typing its value in the Property window.
Keep the upper left corner of the second panel just a bit to the left or top of the first panel. Put it in the right place in the form's constructor by assigning its Location property after the InitializeComponent() call.
Check this answer for a control that works well at design time and lets you easily flip panels at runtime.
The designer will do this automatically because it assumes that when you drag one control over another, you want to make it a child of that control.
What I usually do to get around this is to create the control in a different place on the form, and then use the properties to manually match the positions of sizes of the two controls.

How do I make multiple controls in a Windows Form automatically resize with the window?

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.

Categories