I am using C#. Net Windows application.
I have one MDI parent form and many child forms. I put panel in MDI parent form and drag several button inside panel.
When I click the button they open another child form and set visible false to panel
like this (sample code):
private void Button_Click(object sender, EventArgs e)
{
panel1.Visible = false;
ChildForm Form2 = new ChildForm();
Form2.WindowState = FormWindowState.Maximized;
Form2.Show();
}
Now they perfectly working. What the problem is, when I close the child form the panel could not visible in MDI parent form. Its always panel visible false. I set to true., see my code.
private void ChildForm _FormClosed(object sender, FormClosedEventArgs e)
{
this.Dispose();
MDI md = new MDI();
md.panel1.Visible = true;
}
am also using BringToFront, SendToBack. No use. Please assist.
The problems are:
you create a new instance of MDI form in your child form with MDI md = new MDI();
You should instead retrieve the instance of the opened MDI and set md.panel1.Visible =
true; on this instance. You can use the MdiParent property.
MDI md = (MDI)this.MdiParent;
md.panel1.Visible = true;
and you call This.Dispose before your the code that set panel visible. I am not sure that the code which is after This.Dispose will be executed...
hi friends i Solved this and i got worked now...
here the Solution..
> private void ChildForm_FormClosed(object sender,FormClosedEventArgs e)
> {
> MDI md = (MDI)this.MdiParent;
> md.panel1.Visible = true;
> }
Related
I need help. I have winform, like one which is shown on picture, so I want to improve next things, when I click on first button, on the right side will be showed content from another winform, is this possible? I don't want to use panels.
Why don't you just embed a single UserControl dynamically to represent the current page or if you want to do everything at design-time - a custom TabControl?
showed content from another winform
You generally don't embed a popup window into another, rather controls. Otherwise you have to deal with hiding Minimise, Maximise, Close etc.
MDI Form is the best solution for you.
Use: this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;`
to make your child Forms more beautiful in your project!
If you want the MDI parent to auto-size the child form you can code like this.
Code Example:
private void Form1_Load(object sender, EventArgs e)
{
IsMdiContainer = true;
}
private void btnHotel_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.Show();
frm2.MdiParent = this;
}
private void btnCaffe_Click(object sender, EventArgs e)
{
Form3 frm3 = new Form3();
frm3.Show();
frm3.MdiParent = this;
}
You can use TabControl control -> for each specific content you want to display you just have to add a TabPage to TabControl and when a specific menu option is selected, just switch to required TabControl page.
myTabControl.SelectedIndex = 1; // for selecting and displaying page with index 1
To hide navigation header of myTabControl, set those props (in constructor or in Form_Load event:
myTabControl.ItemSize = new Size(0, 1);
myTabControl.SizeMode = TabSizeMode.Fixed;
Then, you have only content of the TabControl page displayed, without navigation header.
First make it's this.IsMdiContainer = true; either from design time or run time.
then at the button's click event place the following code.
childForm frm = new childForm();
frm.MdiParent = this; //the current mdi parent form
frm.FormBorderStyle = FormBorderStyle.None;
frm.Dock = DockStyle.Fill;
frm.Show();
output
You can use mdi (multiple-document interface):
when you want a form start inside mainform, use this following code:
Dim hotelForm As New HotelForm()
HotelForm.MdiParent = Me // Me is your parent form want to open hotelForm inside
HotelForm.Show()
All forms have a property TopLevel, by setting this property to false, then you can deal with that form as a control, and add it to a panel control.
See below psuedo code:
Form2 newForm = new Form2();
newForm.TopLevel = false;
myPanel.Controls.Add(newForm);
newForm.Show();
After that, your main form design should look like as a navigation control and a panel beside it docked "Fill", then on clicking any navigation button, just create the desired form and set TopLevel to false, then show it on the panel
You have to put a Container control like a panel "pnlHost" in your form and use this for showing any form you want in it
private Form _currentForme;
private void ShowForm(Form frm)
{
_currentForme?.Close();
_currentForme = null;
_currentForme = frm;
_currentForme.TopLevel = false;
_currentForme.TopMost = false;
pnlHost.Controls.Clear();
_currentForme.FormBorderStyle = FormBorderStyle.None;
pnlHost.Controls.Add(_currentForme);
_currentForme.Dock = DockStyle.Fill;
_currentForme.Show();
}
I would use MDI parent and child for this.
But I guess you could also finish the child application, build the exe and initiate it as a new process from your Parent application.
Check the solution given here.
I tried a similar approach long ago and it worked perfectly.
Set current form as a MdiParent then use Datagridview to display data from other forms
I'm going to be short and sweet with only needed information. I'm making an application which has multiple forms displayed in a MDI parent.
I want my users to be able to resize this window and the things i place inside each form resize and move when they resize the window. I do not know how to do this. When i anchor the picture box containing my image to the sides of the form i'm assuming it would work but when you run the application you are not resizing the form, you are resizing the MDIparent form which does not affect the image.
Help.
Edit: removed useless code.
MDIparent code:
private void ribbonButton1_Click(object sender, EventArgs e)
{
foreach (Form f in this.MdiChildren)
{
if (f.GetType() == typeof(Form2))
{
f.Activate();
return;
}
}
Form form2 = new Form2();
form2.MdiParent = this;
form2.Show();
}
Form2 that is the MDICHILD:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.ControlBox = false;
this.WindowState = FormWindowState.Maximized;
this.BringToFront();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
When the MDI parent is resized, the child form sizes of the MDI will not be affected. You will need to do this manually. So, anchoring is the right solution to the child form. Then you will need to set the sizes of the children manually on the resize event of the parent, according to the parent's size. This is all I can say because your post is not clear. Maybe some screenshots could help.
I am adding a child form inside a parent form without setting MDI parent of child form to parent form. Following is the code :
private void Form1_Load(object sender, EventArgs e)
{
ChildForm openForm = new ChildForm();
openForm.Show();
openForm.Visible = true;
openForm.TopLevel = false;
this.Controls.Add(openForm);
}
Clicking text inside any control within child form just selects the text completely and does not allow editing text directly using mouse. Editing text using keyboards is working fine though.
I cannot set ChildForm.MDI= this because of some other issues with a tab control. Is there any way to prevent this and allow user to edit text using mouse.
This works for me in metroframework
private void metroButton1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.TopLevel = true;
frm.Opacity = 10;
frm.Show();
frm.ControlBox = false;
frm.Movable = false;
frm.BorderStyle = MetroFormBorderStyle.None;
frm.DisplayHeader = false;
frm.TopLevel = false;
panel1.Controls.Add(frm);
frm.Dock = DockStyle.Fill;
frm.BringToFront();
this.TopMost = true;
frm.StyleManager = metroStyleManager1;
}
Consider using a UserControl instead. It is designed the same way as a Form but it does not have borders and it is intended to be used inside other forms.
You only have to compile the project that contains it once so that it appears in Visual Studio toolbox (assuming the project is in the same solution and is either the same project as the one containing the Form or has a reference to it.
Or alternatively, you can load it dynamically similar to what you have done in your example. But if you systematically load the same single user control, it is easier to do in the designer...
Sometime, you might also want to make some adjustment to the layout.
I am working on Windows Application.I am having a menustrip in one form and I want to ask that, can I have a panel which will load new form on particular click of menustripitem.
Ex:
File Data
ABC Hello
XYZ Bye
These is my menu bar.On click of ABC I dont want to go on different form can I do something
(whatever I want to)on the same form using panel.
Thanks
I think that I had the same question.
But I found the answer for it
CodeProject Example
First you have to configurate the Form:
myForm.FormBorderStyle = FormBorderStyle.None;
And then, manipulates the action:
Form1 myForm = new Form1();
myForm.TopLevel = false;
myForm.AutoScroll = true;
frmMain.Panel2.Controls.Add(myForm);
myForm.Show();
Hope to help you. Hugs :D
You can use MDI Form.
Try something like this
//Create a new instance of the MDI child template form
Form2 child= new Form2();
//Set parent form for the child window
child.MdiParent=this;
//Display the child window
child.Show()
you can also refer to this site.
If you put the whole content of the target form into a UserControl, you can add a panel to your main form and place the UserControl on that panel.
You still have option to display a separate form by creating an empty form and placing the same UserControl on that form, too.
As Int3 ὰ already points out, you could use MDI forms instead. However, if you want to use dockable panels, the UserControl would be the way to go.
Add two panels on your form, only one will be visible at the same time. Then, add two events on your menus:
private void ABCToolStripMenuItem_Click(object sender, EventArgs e) {
panelABC.Visible = true;
panelXYZ.Visible = false;
}
private void XYZToolStripMenuItem_Click(object sender, EventArgs e) {
panelABC.Visible = false;
panelXYZ.Visible = true;
}
private void pbxpurchase_Click(object sender, EventArgs e)
{
contentpnl.Controls.Clear();//contentpnl is the panelname
purchasebook purchasebk = new purchasebook();//purchasebook is a formname
purchasebk.TopLevel = false;
purchasebk.AutoScroll = true;
contentpnl.Controls.Add(purchasebk);
purchasebk.Dock = DockStyle.Fill;
purchasebk.Show();
}
try this 100% tested
in my project in the container form i use buttons to open the child forms , not Strip Menu but the buttons in the container always appears on the child form
how to privet the buttons or any other controls form being above the child form
i am using Visual Studio 2008 professional edition C# programming language
as in this Image the button suppose to be in form1 and not to be seen in Form2 (Child)
and also the other controls in the Container
sir i have best solution for
create new empty form and than set following property of this form
set in Form_load event
private void bg_Load(object sender, EventArgs e)
{
this.ControlBox = false;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
}
than after
write following code in mdi form load event
private void Main_Load(object sender, EventArgs e)
{
bg bg = new bg(); // create object of empty form my empty form name is "bg"
bg.MdiParent = this;
bg.Show();
}
what ever you want in background add into empty form....]
Enjoy
You should use ToolStrip or MenuStrip to call your child form. In your case, I assume you just drag and drop a Button into your Form1. That's why the button is floating.
But if you are persistent and still don't want to use ToolStrip and MenuStrip, you can hide the button after showing the childform.. Ex:
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.MdiParent = form1;
f2.Show();
button1.Visible = false; // This will cause your button to be hidden.
}