Hi there,

1) So i have a Menu Strip, and a couple of user controls, and in these user controls, i have group boxes. So when I click on the item that I want in my menu strip, it displays as normal. That's working fine.

What I am trying to do is, when I click on a different item in the menu strip, i want that item (user control) to be displayed on my form, disposing the previous user control.

How do i go about displaying the other control and disposing the previous?

2) I have a picture box, the size of this picture box is "376, 197". does this mean that it is 376x197 pixels?

Thanks in advance.

so this is what i use to call a user control, but I can only call 1 user control, it does not switch over to other user controls when i want it to. I cannot make use of the dispose method because then i wouldn't get access to the control again, unless I run the program again.

private void scheduleTerminalsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SchedTerminals SchedTerm = new SchedTerminals();
            Logo.Dispose();
            this.Controls.Add(SchedTerm);
        }

        private void descheduleDevicesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DeSched Deschedule = new DeSched();
            Logo.Dispose();
            this.Controls.Add(Deschedule);
        }

        private void configurationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Config Configuration = new Config();
            Logo.Dispose();
            this.Controls.Add(Configuration);
        }

You need the user control to save its data, not sure what you need so can't give you any tips there yet. I don't know how they work, but you might be able to make them member variables on the form and never dispose of them.

My advice would be to set your area you want to display the user control in as a panel.
Upon clicking each menu item, you would have something like:

//Create control
//This might be a member variable instead
DeSched Deschedule = new DeSched();
//Clear controls
this.panel.Controls.Clear();
//Add control
this.panel.Controls.Add(Deschedule);

Have you considered simply calling Show() and Hide()? This way you don't have to reinitialize all the data between controls that are switched between often.

I hope I am understanding how your current project is set up correctly - if not, please correct me.

You have one box with a space for one user control to be shown at a time (or that is the size you want the window to be), with the user choosing which one is visible.

Personally, I would do the following (especially since I am still learning and this would be the easiest way for me):

1. Create a vertical stackpanel that contains all of the controls.
2. Decide which control you want to be the default view - have the visibility of that control set to visible (Visibility = Visible; ) and the others set to collapsed (Visibility = Collapsed; ).
3. When the user chooses one of the options, the selected item is now visible and the others are all collapsed.

This keeps the size of the window the same (since the collapsed controls are not taken into consideration when the program is creating the window) and should help with switching the currently viewed panel.

I would be looking at this path, since I would have to look up/figure out the code still and it would be easier for me to work with this logic.

My application has different user controls, and in my main form(Form1), i am trying to use this method of calling the different user controls.

private void scheduleTerminalsToolStripMenuItem_Click(object sender, EventArgs e)
    {
        SchedTerminals SchedTerm = new SchedTerminals();
        Logo.Dispose();
        this.Controls.Add(SchedTerm);
    }

    private void descheduleDevicesToolStripMenuItem_Click(object sender, EventArgs e)
    {
        DeSched Deschedule = new DeSched();
        Logo.Dispose();
        this.Controls.Add(Deschedule);
    }

    private void configurationToolStripMenuItem_Click(object sender, EventArgs e)
    {
        Config Configuration = new Config();
        Logo.Dispose();
        this.Controls.Add(Configuration);

I have added a panel to one of the user controls. I made use of this code to try and call the user control through the panel:
panel1.Controls.Add(AddTerm);

but, it doesn't seem to call it, im very new to the user control and panel thing though...

this.panel.Controls.Clear(); does not work, it does not find it in intellisense either.

Is it right that i try to call for these different panels and controls in my main form though?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.