//Splash form:
//------------
frmMain main = new frmMain();
this.Hide();
main.Show();
//MainForm:
//---------
var formToShow = (frmSplash)System.Windows.Forms.Application.OpenForms.Cast<Form>().FirstOrDefault(c => c is frmSplash);
formToShow.Show();
//formToShow.ShowDialog() execute the load event which I dont want.
formToShow.RunTestMetod()
//How I can get the splash hidden form without loading its Load Event and running its //TestMethod(). I want the mainform under it not accessible same like a message box dialog.
I dont want formtoShow.topmost = true as that keep it on the top but the 2nd form is still clickable. Any help would be greatly appreciated.
You can use myNewForm.Show(this); for the Window you want to be shown as a dialog. This will show myNewForm as a child of the current form, but lets you interact with the current form.
You could just disable MainForm?
// ...
var formToShow = (frmSplash)System.Windows.Forms.Application.OpenForms.Cast<Form>().FirstOrDefault(c => c is frmSplash);
this.Enabled = false;
formToShow.FormClosed += frm_FormClosed;
formToShow.Show(this);
formToShow.RunTestMetod()
void frm_FormClosed(object sender, FormClosedEventArgs e)
{
this.Enabled = 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
private void button1_Click(object sender, EventArgs e)
{
mtp1Start = myTrackPanelss1.Start;
mtp1End = myTrackPanelss1.End;
button1.Enabled = false;
Animation_Radar_Preview ap = new Animation_Radar_Preview();
ap.FormClosing += new FormClosingEventHandler(ap_FormClosing);
ap.Show();
}
I want that the form ap will keep showing display even if i click on other button on the form behind it.
I have one big form and when i click this button a smaller form is open.
I want that the smaller form ap will keep showing stay on place when i click on the big form so the smaller form won't move to the back behind the big form.
Set Form.TopMost property to true:
ap.TopMost = true;
ap.Show();
try to show like this,
Animation_Radar_Preview ap = new Animation_Radar_Preview();
ap.FormClosing += new FormClosingEventHandler(ap_FormClosing);
ap.Show(this);
Assign the parameter this in Show() method. it will set the current form as a owner of child(ap).
I'm new to C# and could use some help.
What I have so far is a set of 8 windows forms I have created in C#, these forms have basic things like text boxes, labels, radio buttons, etc. Now that I have completed making all of these forms I want to have one additional form (called the Selector form) I can use to select one of the other 8 forms. At any given time, I want the Selector form to be on top of other windows and it will have 8 radio buttons (or regular buttons, doesn't matter). When one of the buttons is clicked, the current form (not the Selector form) should disappear and a new form should appear. The name of the button will be the name of the new form that appears.
I have seen a few examples and here is the code I have so far:
void Button1Click(object sender, EventArgs e)
{
//this.Hide();
var form1 = new CASII();
form1.Closed += (sender1, args) => this.Close();
form1.Show();
}
void Button2Click(object sender, EventArgs e)
{
// this.Hide();
var form2 = new CCARAdmin();
form2.Closed += (sender1, args) => this.Close();
form2.Show();
//Application.Run(new CCARAdmin());
}
Problem I am having is I don't want to hide the Selector form, which this does, and I don't know how to identify the other form that is open to close it and then open a different form.
From starting the program the logic would be like this:
Show Selector form
When a button is clicked on the Selector form, keep the Selector form on top and show the other form with the name of the button.
When a different button is clicked on the Selector form, close the previous form that was open (not the Selector form) and open the new form corresponding to the name of the button. Keep the Selector form on top.
When the Selector form is close, application stops.
Problem I am having is I don't want to hide the Selector form, which
this does, and I don't know how to identify the other form that is
open to close it and then open a different form.
Set Selector form TopMost to True to make it always on top. Or
you can use BringToFront after opening a new form
to know other forms that are open check this answer. Or you can define each From as a field in the Selector form, and check that.
selectorForm.TopMost = true ( this will help to keep the selector form always on top).
Create a form variable in your selector form to keep the reference of your currently opened form.
Sample code for 1 button click :
Form frm = null;
void Button1Click(object sender, EventArgs e)
{
//this.Hide();
var form1 = new CASII();
if (frm == null)
{
frm = form1;
}
else
{
frm.Close();
}
form1.Show();
this.TopMost = true;
frm = form1;
}
I resolved this by setting TopMost to true and then using the following code under each one of the buttons:
for (int i = Application.OpenForms.Count - 1; i >= 0; i--)
{
if (Application.OpenForms[i].Name != "FormSelector")
Application.OpenForms[i].Close();
}
var form = new TRAC();
if (radioButton9.Checked == true)
{
form.Show();
}
I have two forms. I have a button in mainForm. When i clicked button1 the main form will show and the button1 will be Enabled false. Now i want to Enable it to True when my ChildForm gets Close. PLease help me .
My code For Enable= False is
CstmersFrm cstFm = new CstmersFrm();
cstFm.MdiParent = this;
cstFm.Show();
cstFm.BringToFront();
btnCstmr.Enabled = false;
Iam trying to Enable= True is In cstmersFrm _Closed Event
mFrm = (mainForm)this.MdiParent;
mFrm.btnCstmr.Enabled = true;
You need to register to the child form Closed event on the main form:
Form child = new Form();
child.MdiParent=this;
child.Show();
child.FormClosed+=child_FormClosed;
and then set the button to Enabled:
void child_FormClosed(object sender, FormClosedEventArgs e)
{
btnCstmr.Enabled = true;
}
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