MDI Child form overlayed by panel with property dock fill - c#

Description
I have Main form (Home) with IsMDIContainer property set to true.
Then i added a panel on form and set it DOCK property to
FILL
After that i created child form (products) and open on main form
on button click.
Problem i am facing
when i clicked on button to open product i can't see any form. Either it is overlayed by panel or some thing else is going on which i don't know.
What i tried
Changed HOME form IsMDIContainer property back to false
change panel DOCK to bottom (for test)
Again set IsMDIConatiner to true , i got the form.
What i want ?
i want that panel to be DOCK fill and want MDI Parent and child functional should function

Setting TopMost property of child form to true And ShowOnTaskBar to false i got it fixed
Set show on task bar property of form to false
Call a method on form resize checked the FormWindowState
if it is minimized then i set the TopMost property of child form to true
private void Form1_Resize(object sender, EventArgs e)
{
Form minimizedForm = sender as Form;
if (minimizedForm.WindowState == FormWindowState.Minimized)
{
minimizedForm.TopMost = true;
}
}

Related

How to prevent focusing Controls in UserControl

I have a User-Control with 2 Textbox and 1 Button, Something like below:
When I press the button a form show and when the form closed I want to leave focus from User-Control and next control on the Form got focus, I write this code for this issue:
private void Btn_Select_Click(object sender, EventArgs e)
{
if (t.ShowDialog() == DialogResult.OK)
ProcessTabKey(true);
}
I excepted that next control on the Parent Form got focus BUT the textbox on UserControl got focus, I change the TabStop property to false for 2 textbox but still have the problem.
Could anyone know how I solve this problem?
Use:
this.FindForm().SelectNextControl(this, true, true, true, true);
Instead Of:
UserControl.ProcessTabKey();
Will Solve Problem.

How to open a child form from another child form?

I am working on a Windows application. I have a MainForm (Parent) and several childForm. There is a listview in MainForm that contains a childForm name list and by clicking on each name in the list, the relevant childForm shows and the previous ChildForm closes.
I use this codes to show childForm and close the previous childForm in MainForm.cs (ParentForm):
CloseForms();
frm_draft = new frm_ShowDraft();
frm_draft.MdiParent = this;
frm_draft.Show();
CloseForm() is a method that checks, which childForm is runnig and closes it.
So far everything is good.
In one of the childforms there is a Button. When the user clicks on it, it should close this childForm and show another. But when I click on the button, childForm2 shows out of MainForm. How can I show it inside of MainForm?
My code in the button click event:
this.close();
frm_c2 = new frm_child2();
frm_c2.MdiParent = new MainForm().ParentForm; /// Or this.MdiForm
frm_c2.Show();
You should set same MdiForm and call Close at the end:
frm_c2 = new frm_child2();
frm_cLetter.MdiParent = this.MdiParent;
frm_cLetter.Show();
this.Close();
http://www.independent-software.com/weifenluo-dockpanelsuite-tutorial-cookbook/
To show a child form in the main form use the WeiFen Luo library.
This control will make it easier to dock forms into your main form visual studio docking screens
Form with 3 forms inside:
Make sure the IsMdiContainter prop is true.
Example:
public Form1()
{
InitializeComponent();
Form2 f2 = new Form2(); // create new form
// dockPanel is an control from WeiFen Luo more info see the link
// dockPanel control is docked in your mainform.
// this will open Form2 in the dockPanel and align it left
f2.Show(dockPanel, DockState.DockLeft);
}
More docking options:
DockState.Fill docks form in over the hole dockPanel
DockState.Right docks form at the rightside of the dockPanel
DockState.Top docks form at the topside of the dockPanel
for more option check the link
This control will handel responsifnes of the docking forms and will handle allot of positioning calculations for you.

How to remove control box from MDIchild form

When I'm loading a child form in MDIparent the control box also appears. I want to remove the control box and the border of child form.
Also I'm writing code as
private void Form_mainMenu_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
this.ControlBox = false;
this.FormBorderStyle = FormBorderStyle.None;
}
If you really want to customize the appearance of title bar of mdiChild Window, it seems you need handle painting of non-client areas of child window by handling WM_NCPAINT message.
Also you need to handle messages like WM_SETCURSOR, WM_MOUSEMOVE, WM_NCLBUTTONDOWN, ... .
As a workaround you can use a panel instead of mdiParent.
Create parent form and don't set IsMdiContainer.
Add a panel to your parent form and name it "ContainerPanel" and set its Dock property to fill.
Create your child form and add it to panel with none border style, no control box, fill dock style and non top level.
Here is sample code:
var f = new ChildForm();
f.TopLevel = false;
f.ControlBox = false;
f.Dock = DockStyle.Fill;
f.BorderStyle = System.Windows.Forms.BorderStyle.None;
/*I assume this code is in your ParentForm and so 'this' points to ParentForm that contains ContainerPanel*/
this.ContainerPanel.Controls.Add(f);
f.Show();
Using such method you can control every aspect of your hand made mdi window. For example you can use a Menu to show list of open windows and a toolstrip to close windows.

How to focus a control in a form which is added on a panel of its parent form by tabbing index

I'm working on winforms in c#. I have a form which loads other forms in its panel. Now my child forms have many textboxes.
I want to set focus on one of those textboxes by loading my children forms by setting tab index to zero.
But it isn't happening when i load my children forms. I have taken care of the tab stop properties & i also went through the tabbing order of the forms. But the problem is still there.
When i load children forms from startup it focuses zero indexed control. I guess my problem is that i am loading these forms in a panel of a parent form. Any solution to this problem?
The Windows Forms controls in the following list are not selectable. Controls derived from these controls are also not selectable.
Panel
GroupBox
PictureBox
ProgressBar
Splitter
Label
LinkLabel (when there is no link present in the control)
Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.
https://msdn.microsoft.com/en-us/library/system.windows.forms.control.focus.aspx
You can set focus to a control in a form which is added on a panel of its parent form by creating an instance of child form in the parent form and then setting focus to child form controls.
Make an instance of child form:
ChildForm formInstanceName = new ChildForm();
And then you can set the focus property for particular control as:
formInstanceName .controlname.Focus();
And before doing this make sure you add the child form to the respective panel.
Here is the snippet of the code I used:
Form1 childform1 = new Form1();//creating an instance of child form
private void btn_Click(object sender, EventArgs e)
{
Panel2.Controls.Clear();//To clear existing controls on panel
Panel2.Controls.Add(childform1); // To add child form controls on the panel.
childform1 .textbox1.Focus(); //To set focus to control of child form
}
I hope this helps you..

child form minimize goes to task bar

I have an MDI form which displays a treeView control, when the user clicks on the tree node child form, it opens:
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
frmPartMaster frm = new frmPartMaster();
frm.Show();
}
Here frm is displaying the backside of the tree control but I want it to show form in front of parent, not back. So I changed the code to:
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
frmPartMaster frm = new frmPartMaster();
frm.Show(this);
}
Here the child form is displayed in front of the tree, but when I minimize the child form it goes to task bar.How do I get it to go to the left corner of of parent form?
You have to set the parent form's IsMdiContainer property to true. Then while opening the child form add the following code:
frm.MdiParent = this;
Are you using MDI? Then it won't come to Task bar. You can set the ShowInTaskbar option to false, which will not display for in Taskbar.
Real MDI child forms do not minimize to the taskbar. Therefore I can only conclude that you are not using an MDI child form and that your solution is to start doing so.

Categories