How to close the current form in a SplitContainer? - c#

I have a user control in my SplitContainer's right panel. A form opens below the user control. Now if i click a button in the user control, that current form should close and a new form should open. How to do this?

You can implement below logic in your app easily:
splitContainer.Panel2.Controls.Remove(myPanel);
splitContainer.Panel2.Controls.Add(myOtherPanel);
which will remove the existing panel from the container and place the other panel. You can extend the same logic to place forms, or separate controls on the container easily.

Related

C# using flowlayoutpanel as simulate MDI container

I'm creating a new winforms application.
I want to simulate MDI functionality with a flowlayoutpanel that will host "many" panels that will have a form embedded into it.
So the workflow would work like this:
User click on navigation menu to open a module (the module is a winform that will be embedded into a panel and this panel will expand to fill its container)
The user will se the module filled in order to work but has option to minimize it so he can work on other module.
When the user click on the minimize icon "custom icon added to the panel", the panel will minimize like a title into the flowcontainerpanel.
The user then can click on other module or double click the existing current opened modules "tiles" to open it again.
Here are some images so I can explain it better.
Once the "tile" is double clicked the panel should expand and fill:
How can I do this?

Devexpress unload usercontrol after save form

i have a main form which is containing a menu.
when i click a menu button there is an usercontrol is loading panel control in main form:
splitContainerControl1.Panel2.Controls.Add(new Moduller.userControlStokListesi() {
Dock = DockStyle.Fill
});
And there is a form on UserControl. when a user fill that form and hit the save button i want to remove that user control form from panel control.
How can i do that?
So if I understand your question correct, you want to remove the instance of Moduller.userControlStokListesi from the Panel2 ?
There are several ways to achieve this. You can remove all controls from a panel this way:
splitContainerControl1.Panel2.Controls.Clear();
You can also remove specific items:
splitContainerControl1.Panel2.Controls.RemoveByKey("the key of your control");
Or if you want the user control removes itself from the panel, you can call this snippet within the user control instance:
SplitContainerControl splitPanel = (SplitContainerControl) this.Parent;
splitPanel.Panel2.Controls.Remove(this);

Menu Items that change the application's view

I've been all up and down this tutorial.
I can't for the life of me figure out how when my app loads to have 1 screen, then when a menu item is clicked to show another screen. I get the idea of having multiple forms, but is that the solution I need here?
From what I've read I understand new forms to be essentially new windows. If that's right, that doesn't sound like what I need.
My users start off with a blank window other than a menu (I'm gonna fill it in later), but I want for File -> Settings to load a settings form. Ideally not in a new window.
Its a MDI window. They are window containers of other windows.
You create a parent form, and then you change which child form is the active form on the menu item click events. This requires you make a parent MDI form, and a child MDI form for each of the different views you want of your document. The menu items then switch which child MDI form is the active one.

C# Control Parent

I have a winform project with a tabcontrol and several tabpages.
Within each tabpage there is some unique panel controls. However, when the user interacts with the form in each tab page, I want a generic picturebox to show. So I don't want to create a new picturebox for each tabpage, rather show the same one. Which control should I therefore have as a parent to the picturebox, and how can I change the parent once I drag the control onto the form?
Thanks.
The form has to be the parent. Which is not so easy to get done in the designer, the tab page will suck it in every opportunity it gets. One thing you can do is put it to the left of the tab control and move it in place by changing its Location property in the form's constructor, after the InitializeComponent() call
public Form1() {
InitializeComponent();
pictureBox1.Left = tabControl1.Left + 15;
}

Display UserControl as popup window

I have a UserControl where I have some buttons and textboxes. I was wondering how I can display that UserControl when a user clicks a button.
A user control cannot be a 'popup window', that requires a toplevel window. A form. You can put the user control in a form and use the form's Show() method to make it visible.
Fwiw, turning a user control into a toplevel window is technically possible with the SetTopLevel() method. It isn't worth the hassle, it won't behave like a proper one.
You should paste the user control on a windows form and then make it a modal window. Make a object of that form and then call object.open();

Categories