Frage

i'm using telerik control. So i want to ask, In winforms application ,Is it possible to add more than one panel in same location and display one at a time just like show/hide property.

War es hilfreich?

Lösung

Make sure you have placed all panel control in same container or form. then you can use Visible property to show and hide panel. BringFront and SendToBack function will be used to bring panel on top or send it to back. If you have placed any panel in another panel then that will be disappeared when you Hide parent panel. So, Make sure all panels' parent control must be same. To determine the parent control simply select that panel and press escape key to select their parent.

private void LoadPanels()
{
    panel1.Location = new Point(10,10);
    panel2.Location = new Point(10,10);
    panel3.Location = new Point(10,10);
    panel4.Location = new Point(10,10);
    panel5.Location = new Point(10,10);

    VisiblePanel("panel1");
}

private void VisiblePanel(string panelName)
{
    string[] panels = new string[]{"panel1","panel2","panel3","panel4","panel5"};
    for (int i=0;i<panels.Length;i++)
        this.Controls[panels[i]].Visible = (panels[i] == panelName);

    this.Controls[panelName].BringToFront(); //Not required you can remove this line.
}

Andere Tipps

Here's a slightly different approach you might want to consider...

Are you wanting to be able to programmatically select the contents of a rectangular area at runtime, selecting among various controls to display? If so, you could use a custom TabControl which has its tabs (not the pages) hidden.

Then you can select which page is displayed by programmatically changing its SelectedIndex property at runtime.

Doing it like this means that your form editor will show a normal tab control, which allows you to much more easily add the content to each page - but at runtime the tabs will be hidden from the user; they will just see the contents of the currently selected page.

See Hans Passant's answer here for how to create such a custom tab control.

(However, you might also want to override the OnKeyDown for the custom tab control in order to ignore Ctrl-Tab.)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top