Using so many panels in Windows Form and showing one at a time is never an easy task.
Emran Hussain wrote:
programmatically relocate it (Size and Position)
I don't agree: rather than inheriting from something that does not do things the way you want
(basically is too complex), I suggest you build it from simpler things. So make a little class (say
MultiPanel) that inherits from Panel and that holds a List of Panels. All the Panels in the List are
added to the Controls collection of MultiPanel, all same size same location, but only one has
Now give it some properties:
- a Bounds property, that sets the Bounds of each of the Panels
- a SelectedIndex property, that sets all Panels invisible except the one with the matching index
and some methods, including:
FYI: An invisible Panel does not show its contents, and does not consume events. So the whole thing
behaves like the one Panel that is selected. No more, no less.
And if you want to design your panels with Visual Designer, just make them separate classes,
inheriting from Panel, and add them as per above, except you now need a method AddExistingPanel(Panel).
I meant, Microsoft could do this work for us, like they did make MultiPage Control for ASP.NET, same type of control they could make for Windows Forms too! As Creating Wizard is very common type application and I am wondeing how the developers are handling this problem ? Are they creating their own custom control as you described !!!
A button does not hold any data (unless you hide something in its Tag).
The normal approach is to have your data structured somehow and stored in class members.
Then these data may get operated upon by Controls, such as a Button causing an OpenFileDialog to
appear, and a file being read; and an OnPaint method may read the same data to display something
on the Form or one of its Controls (such as a Panel).
I have a user control (which for the purposes of this post is just a container), and several nested user controls. I want to lay out the child controls inside the container in a similar way to the following picture:
I've tried different combinations of Anchor and Dock properties as well as using a Flow Layout Panel, but I can't get it to work.
The two things I know are:
1) The location of each child control on the Y-axis
2) The height of the control
I need some way to assign these controls a combination of properties and have them stack up as shown in the picture. Full width child controls should float to the left, and if there's more than one child control at a Y location (eg: 3 and 4), the available space should be split.
I managed to get it sort of working, but items were overlapping.
Have you looked at adding a SplitContainer into the mix?
I'm thinking that if you dock one panel on the left side of the form (or control), dock a second panel in the upper-right, a third panel in the bottom right, and place a SplitContainer into an area you leave open between the two panels docked on the right, then you can place your #3 and #4 controls in the split container panels, and not worry about any overlap. You could set the IsSplitterFixed property to True to prevent the user from resizing the split, and make the splitterwidth small enough that it is unseen.
Anyways, that is one idea, I won't be surprised if there are better ideas...
yep, do it hierarchically, i.e. split your form in two parts (that would be 1 versus 2+3+4+5) using
either a SplitContainer or two Panels; give those the right anchoring.
Then iterate for the next split (5 versus 2+3+4). Etc.
Thanks for the quick response. I didn't explain myself very well. The number of child controls isn't a fixed value. In the example there are two items with the same Y value, but there may be just one, or four or five.
I don't know which Control would help you split a distance in N equal parts, N being possibly larger than 2 and not a power of 2.
The way I used to do all these things, before I was even aware of anchoring and SplitContainers, is
by calculating Top, Left, Height and Width myself, by code, in the OnResize handler. Takes some code,
but does exactly what you want with no additional Controls to achieve your layout.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
I have an application which displays the fonts in "Segoe UI".
But if I run the same application on another OS on which the font is not available.
It is displaying the font in "Microsoft Sans Serif".
Is there any way to change the default font to "Tahoma" on those machines ?
Thanks in Advance.
"Never explain yourself to anyone.
Because the person who likes you does n't need it.
And the person who dislikes you won't believe it."
You can explicitly set the font on each form so that it will use that font on all operating systems, if available. However, leaving the font settings as is will cause the application to display using the default font for that operating system, which is generally what you want.