what is the best idea/technique to do this and I prefer not to create all these at run time and not using the Tabs control:
let's say we have three radio buttons on the form and based on the user selection we want to show him different GUI stuff ( checkbox, listbox, etc ... ) on the same form.
How to do that?
Set the controls' Visible property to false.
This will be easiest to do if you put the controls on different panels and show / hide the panels instead of hiding each control separately.
Controls have a Visible property, that makes the control disappear when it is set to False. When a button is clicked, you could write some code that sets certain controls to be invisible.
Related
I have created a form that shows data and the filter that has checkbox in it
combobox
I have used a Button and a Panel to do this and found that the panel is only shown in the parent's panel not float like the combobox
or panel can't do like this?
Regards
You want something that cannot be done with parented components (like panels)
I see some options:
(1) owner draw a combobox to include checkboxes, see Codeprojects https://www.codeproject.com/Articles/31105/A-ComboBox-with-a-CheckedListBox-as-a-Dropdown
or
(2) Create a small floating popup form without system menu and a single pixel border. Inside the form, you could place a CheckListBox docked Fill to allow for filter checkboxes for each item.. you may have a look at this topic Is there a simple way to implement a Checked Combobox in WinForms
(3) Both solutions have drawbacks. Actually it may be better to avoid it, find another way to specify your filter options, redesign your UI.
I want to set a certain property (Anchor) of all the controls in my main form at once.
There are around 100 controls and I really don't want to change this property for each single control manually.
I know I can select all available controls at once by typing Ctrl + A. The problem then occuring is that the desired property I want to change is not visible in the Properties window. And normally it should be visible because all the controls are a type of Control, shouldn't it?
I also know that I could do it like this:
foreach(Control ctrl in myForm.Controls)
{
ctrl.Anchor = AnchorStyle.Bottom;
}
But I want to know if thers's a way of doing this using the Designer. Is there any?
Usually if controls derive from the same base, you can select them all at once (using the mouse click and drag or holding down ctrl or shift while selecting them one by one), and then you can set any property that they all share from the base class.
You can multi-select all controls on the form and see the Anchor property in the Property Grid. When you edit that with multiple controls selected, each selected control will be set to the Anchor value you specify.
But be careful with Ctrl-A--it will select visual controls as well as non-visual components. So if you have any components on your form that don't render in the client area of the form (such as the Timer or FolderBrowserDialog form components), the Ctrl-A will continue to show common properties--but because these components don't have an Anchor property, the Anchor property won't appear. The only properties to appear when multiple controls on a form are selected are those share by all selected controls.
I have a pretty simple winforms application. It contains a rich edit box, embedded browser, progress bar, a few buttons etc.
I have the anchors on the controls set to expand in all directions.
When expanding up and down, however, the controls will overlap one another. How do I prevent this from happening?
Thanks
Your best bet is to add a TableLayoutPanel to your form which contains the "layout grid" this should be docked to the form, then you can add your controls into the cells in the table (they can cover multiple rows and columns so you can get the layout you want).
You must set the property Autosize=true on every control, especially on the main form.
Note that some controls like TabControl have this property, but you can't see it with intellisense (Attribute Browseable=false).
In my wpf window I want to change part of it (make different controls visible) when combo box selection is changed. Exactly like TabControl works, just with combobox. I know I could just make some controls visible while hiding the others in the c# code behind but I want to find out if there are other -better solutions.
You can use two Grid or GroupBox (or other container type) controls and put appropriate set of controls in each of them. This way you can just visibility of panels to hide the whole set of controls instead of hiding each control directly.
It may sometimes be appropriate to create a user control for each set of controls. However, this can depend on a specific case.
I have created a Windows form using a Tab Control, but it has a header with it. I want to hide it. I am not able to do it using any properties of the Tab Control. Is there any property defined for hiding the tab header for the Tab Control without going through the code?
Use following code to hide the tabs or set these properties in design.
tabControl.Appearance = TabAppearance.FlatButtons;
tabControl.ItemSize = new Size(0, 1);
tabControl.SizeMode = TabSizeMode.Fixed;
You want the tab panels without the feature allowing a user to switch between them, so I suppose you want to create few separate sets of controls to be shown to the user one at a time. You can achieve this in several ways (you can choose one of them if you find it appropriate in your case):
Use several Panel controls instead of several tabs in the TabControl, however, it would be hard to work in the designer, because all the controls would be visible
Use different Forms instead of tabs to keep the layout parts separated. It can be ok, but you may not want to use multiple Forms, so it depends on a specific case.
and finally, the suggested solution:
Encapsulate each set of controls in a UserControl. This allows you to keep each layout separately, so you can easily design each of them without the other controls getting in the way ;). The the code handling each of the layouts would also be separated. Then just drag those controls in the Form and use set their visibilities appropriately to show the one you want.
If none of those suggestions work for you, let me know, so I can look for other possible solutions.
It's more easy as you think, you just drag the panel's window upper, so will be outside of the form.
Use DrawMode: OwnerDrawFixed will hide TabPage header text DrawMode : OwnerDrawFixed
Another way to achieve the same (or similar) is: You can remove tabs from TabControl.TabPages collection and then add the tab you want to show.
During the Form initialization I remove tabs (so into the designer I can easily manage them) and in some control event (as button click) I show the tab the user has to see.
Something like that:
// During form load:
ctrTab.TabPages.Clear();
// ......
// During button click or some other event:
if(rbSend.Checked)
ctrTab.TabPages.Add(pgSend);
else
ctrTab.TabPages.Add(pgReceive);
In this way the user can still see the header tab but just as title of controls group, he can't change/switch the current active tab.