tags:

views:

795

answers:

4

Hey,

I have an annoying problem - I want to use a listview with images as Menu. Let's say the listview contained 3 "images".

  • Image 1. ) "Main"
  • Image 2. ) "Options"
  • Image 3. ) "Misc"

Now when I click the "Main" image, I would display the "Main" panel, same for "Options" image where I display the "Options" panel. but here's the annoying part. I have 3 panels on my form. So whenever I want to edit one panel, I have to resize the other two just so i can edit the first one, since they are all thrown on the form. It gets really annoying to edit the panels.

Is there some kind of control equivalent to the wxWidgets wxListBook control? Or does anyone have an idea how to solve this? I'm asking about design time

Thank you!

+1  A: 

You could just display the current item panel and hide the other panels. On your form, add an empty panel which is the container for your list view item panels.

private Panel container;

private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
    //get the item panel associated with the current selection.
    Panel itemPanel = GetItemPanelFromSelection(); 

    container.Controls.Clear();
    container.Controls.Add(itemPanel);
    itemPanel.Dock = DockStyle.Fill;
}

Personnally, I would create an user control for each type of panel that you want. The advantage is you can edit them easily. After that, you can use the same code above.

Francis B.
I've done something similar for this, just inherit from panel for each control. I also created a simple method extension to bring to front, and dock full with the parent control passed as an argument.
scottm
A: 

I've done this before - I just make the window large enough to fit all panels. At runtime, I hide all but the default panel, and set their locations equal. Additionally, I set the size of the parent window (or control) to be the size I want such that one panel fits nicely in the window. Your selection method (clicking images) seems ok, as you'd detect which image is clicked, and show/hide the corresponding panels.

It's a little bit clunky, but for some cases it works just fine. This works great for applications where you want to see all the panels at design time, but only see one panel at runtime. Thus, using Visual Studio's built-in localization tools will continue to work.

Here's some sample code I've copied from a project. This is actually a Settings window, where I select panels to view from a TreeView.

Width = 640;  // set the size of the form, as it's larger in Designer mode
Height = 480;

simulationPanel.Visible = false;   // hide all panels, and set them to be top-left
simulationPanel.Top = 0;           // relative to their parent control
simulationPanel.Left = 0;

delaysPanel.Visible = false;
delaysPanel.Top = 0;
delaysPanel.Left = 0;

occurrencesPanel.Visible = false;
occurrencesPanel.Top = 0;
occurrencesPanel.Left = 0;

languagePanel.Visible = false;
languagePanel.Top = 0;
languagePanel.Left = 0;

Then, to select a panel, you might do something like the following:

private void ShowPanel(string name)
{

     // its easy to just hide all panels again if one is currently visible
     simulationPanel.Visible = false;
     delaysPanel.Visible = false;
     occurrencesPanel.Visible = false;
     languagePanel.Visible = false;

     if (name == "language")
     {
          languagePanel.Visible = true; 
     } else if (name = "delays")
     {
          delaysPanel.Visible = true;
     }
     ... etc
}
Charlie Salts
A: 
Joel Coehoorn
This is a similar approach to my answer, and I like the idea of custom controls.
Charlie Salts
+1  A: 

I assume that you are talking about editing the panels at design time and not run time. Just make all your panels the same size, lay them right on top of one another, and when you name them, make sure they all have the same prefix. Select the panel that shows on the top, and if it is not the one you want, use the dropdown at the top of the Properties window to select the panel that you want, then right-click on the highlighted Panel grip (moving and resizing thingys) and select 'BringToFront'.

Stewbob