I would like to create TabPages (fill docked with frmCalculationReport) as child forms of a MDI, so that I can switch active TabPage from ToolStripMenu such as "Window" pull down menu.
I have one tabControl1 fill docked in MDI MainWindow with ToolStripMenu of that "Window".
When I click one ToolStripMenu item such as performCodeCalculationsToolStripMenuItem from MDI MainWindow, I would like one TabPage (with a docked frmCalculationReport) added on tabControl1 as a child form of MDI MainWindow. Following are the codes. But, I do not know how to add the TabPages as child of MDI MainWindows. Any suggestion and comments will be greatly appreciated.
private void performCodeCalculationsToolStripMenuItem_Click(object sender, EventArgs e)
{
string title = "CalReport";
TabPage myTabPage = new TabPage(title);
tabControl1.TabPages.Add(myTabPage);
CalculationReport frmCalculationReport = new CalculationReport();
frmCalculationReport.TopLevel = false;
frmCalculationReport.Visible = true;
frmCalculationReport.FormBorderStyle = FormBorderStyle.None;
frmCalculationReport.Dock = DockStyle.Fill;
tabControl1.TabPages[tabControl1.TabCount - 1].Controls.Add(frmCalculationReport);
tabControl1.SelectedIndex = tabControl1.TabCount - 1;
}
Related
i am new in c# windows application learning
i have 3 form.
main form, form menu, child form
in main form when i click on button1, form menu is show in 1st panel.
this code in main form.....this work properly for me... if anyone have better then this then suggest me.
private void button1_Click(object sender, EventArgs e)
{
bool IsOpen = false;
foreach (Form frmchild in Application.OpenForms)
{
if (frmchild.Text == "Child Form")
{
IsOpen = true;
frmchild.Close();
break;
}
}
if (IsOpen == false)
{
child form cf = new child form();
cf.Owner = this; //main form is owenr
cf.Show();
cf.Location
= new Point(button1.Left + 37, button1.Height + button1.Top + 4);
}
}
main form have 2 panel, 1st is small and dock in top. 2nd is main panel (dock = fill) where i want to dock all child form.
in form menu i have button and when i click on i want to open child form in main form 2nd panel.
please help me to open child form in main form's panel when i click button in another child form in c# language.
please help me.
i think you have to use USER CONTROL instead of a form. Add a usercontrol at your prject and here is the code :
for (int i = panel2.Controls.Count; i > 0; i--)
{
panel2.Controls[i-1].Dispose();
}
//add user control you want
UserControl1 uc = new UserControl1();
panel2.Controls.Add(uc);
I have created ribbon form (XtraMain)and I set IsMdiContainer Property to true,i also add documentManager controle i set MdiParent to XtraMain I have add this code to open child forms
public void ViewChildForm(XtraForm _form)
{
if (!IsFormActived(_form))
{
_form.MdiParent = this;
_form.Show();
}
}
private bool IsFormActived(XtraForm form)
{
bool IsOpenend = false;
if (MdiChildren.Count() > 0)
{
foreach (var item in MdiChildren)
{
if (form.Name == item.Name)
{
tabbedView1.ActivateDocument(item);
IsOpenend = true;
}
}
}
return IsOpenend;
}
and i use this code in click of button to open the child form
private void bbtnEmployee_ItemClick(object sender, ItemClickEventArgs e)
{
FrmEmployee frme = new FrmEmployee();
frme.Name = "FrmEmployee";
ViewChildForm(frme);
}
my problem start when the form contain a LayoutControl for example i have this code that open on click of button
private void btnBonLivraison_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
LayoutControl lc = new LayoutControl();
lc.Dock = DockStyle.Top;
LookUpEdit OrderNumber = new LookUpEdit();
OrderNumber.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
OrderNumber.Properties.DataSource = shippProdu.GetOrderNumber();
OrderNumber.Properties.DisplayMember = "N° Bon de livraison";
OrderNumber.Properties.ValueMember = "N° Bon de livraison";
lc.AddItem(Resources.selectOrderNumber, OrderNumber).TextVisible = true;
lc.Height = 70;
this.Controls.Add(lc);
this.Dock = DockStyle.Top;
lc.BestFit();
the second I click on a button the tabHeader disappears,what cause this problem?and how can I solve it.before I use documentManager I used XtraTabControl and if i click a button to open LayoutControl and after that try to open another form the focus remaining in the first form even when the form two is already opened and if I want to go to form two I must first click on a tab of the first form and then click on tab of the second form , thanks in advance .
this is my main form
and this is when the eader disappears
If DocumentManager resides within the same form to which you add LayoutControl, it is the expected behavior. DocumentManager places a special documents' host onto the main form and set its Dock property to Fill. That is why it is incorrect to place LayoutControl onto the same form and dock it to form edges.
If you need to show tabbed documents and LayoutControl on the same form simultaneously, do not use the MDI mode. Consider the use of a separate UserControl. Place your DocumentManager there. Then, put this UserControl onto your form. Note that in this case UserControl's Dock property should be set to Top or Bottom since LayoutControl should fill all available area or vice versa.
I want to replace ContextMenuStrip of NotifyIcon with some more complex Form. I can display form when user click on NotifyIcon in SystemTray but I can't hide/close form like ContextMenuStrip close when user click somewhere else.
Is that possible?
Here is example code, I Show that form this way:
private void Mouse_Up_Event(object sender, MouseEventArgs e)
{
FormMenu f = new FormMenu();
f.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
f.SetDesktopLocation(Cursor.Position.X - f.Width / 2,
Cursor.Position.Y - f.Height - 20);
f.Show();
f.Focus();
}
And FormMenu is a complex form with panels and multiple buttons.
You can host your complex control or form in ContextMenuStrip using ToolStripControlHost.
Code:
var c= new MyUserControl();
//Set up properties and events then add it to context menu
this.contextMenuStrip1.Items.Add(new ToolStripControlHost(c));
You can also add your form to context menu strip this way:
var f = new YourForm() {
TopLevel = false,
FormBorderStyle = System.Windows.Forms.FormBorderStyle.None,
MinimumSize= new Size(200, 200), /*Your preferred size*/
Visible=true
};
//Set up properties and events then add it to context menu
this.contextMenuStrip1.Items.Add(new ToolStripControlHost(f) );
Screenshot:
In above screenshot I added a form to a context menu strip that has not other items and set ShowImageMargin property of context menu to false.
You can also have other Items and sub menus.
I have a main application form, I've set the IsMdiContainer property to TRUE
I have a panel in the main application form on the top but when I open the ChildForm it opens behind the panel. How do I set location relative to the bottom of the panel + maximize the window?
As Hans said in comments, Set the Dock property of Panel to Top for example. And add your Mdi Childs this way:
Example:
private void MdiTest_Load(object sender, EventArgs e)
{
//Codes for test only
var f = new Form();
f.Controls.Add(new TextBox());
f.MdiParent = this;
f.Show();
}
Note:
You can access to MdiClient control this way:
var mdiClient = this.Controls.OfType<System.Windows.Forms.MdiClient>().First();
Then you can do anything with it if you need. It is a Control like other controls.
Normal State:
Maximized State:
I have a mainform that contains a panel in which different MDI child forms are displayed. The controls in the MDI child got Anchor = Left, Right, Top, Bottom to resize.
The problem is the resizing of the controls in the MDI child when the main form is resized. I got it working with the following code:
private void MainForm_Resize(object sender, EventArgs e)
{
foreach (Form f in panel.Controls.OfType<Form>())
{
f.WindowState = FormWindowState.Minimized;
f.WindowState = FormWindowState.Maximized;
}
}
The problem is that the controls in the MDI child permanantly change their location when you are resizing. Is there some way to call a Resize method?
For those who got the same issue:
You need to set the Dock property to DockStyle.Fill for the MDI child. Else it just doesn't resize the controls.