I made my first Child (I mean Form. Actually I am a grandfather...)
I have two problems:
1. The Child form is dipslayed on top of the Main Form, but under the main form's controls (TextBox, Buttons, etc).
(I naturally set the Child to TopMost=True, the main form to TopMost=false).
Changing the controls order to back did not help.
2. As soon as I defined the Main Form as a MDI container, its background color changed from the standard Control grey into dark grey. I can not change it back.
Both issues seem to be matter of settings, but which?
Thaks
Sam
Loading
Tanmay SarkarPosted Oct 30, 2010, 2:58 AM
Second, in your MDI form load section put this code
private void Form1_Load(object sender, EventArgs e)
{
MdiClient Form1;
foreach (Control my_control in this.Controls)
{
try
{
Form1 = (MdiClient)my_control;
Form1.BackColor = this.BackColor;
}
catch
{
}
}
}
the default color you see when you set a form as mdi it's nothing but a system provided color or theme color.
Hope sample will help you.
Thank you!
If it help you then mark it is an answer.
SamPosted Oct 31, 2010, 10:49 AM
Thank you very much.
As I wrote, I followed MS instruction in building the child form.
All commands were entered automatically, and are in line with your manual suggestions.
The forms builds OK, and looks OK until there is a control on the main form.
In such case, regardless of what I do (I did it several times, and followed the instructions step-by-step), the child form still apears under the control.
I have over 100! controls on the main form (It is a single form working instrument).
When I start the child, I can hardly see it under the controls.
All your suggestions were tested, but there still is a major problem.
Thanks.
Tanmay SarkarPosted Oct 31, 2010, 2:41 AM
Basically when you use MDI it require that you put all the control in menubar not container. Although you can add them in container but it not looks well (i think).
Iput here your code also with sample.
private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.MdiParent = this;
frm2.Show();
}
By the way, you convert VS2010 to VS2008 and i think that works well. can you give the link for me? or you put that link on my blog http://www.c-sharpcorner.com/UploadFile/Blogs/3580/
where few links I already uploaded for people and me also.
Thank you!
SamPosted Oct 30, 2010, 6:28 PM
Thanks again.
The Child form was created by me following Microsofts step-by-step instructions, and the relevant method, similar to what you suggested, was automatically built as follows (Even the comments were made by the system):
protected void fileToolStripMenuItem_Click(object sender, EventArgs e)
{
FormPortSetup newMDIChild = new FormPortSetup();
// Set the Parent Form of the Child window.
newMDIChild.MdiParent = this;
// Display the new form.
newMDIChild.Show();
}
I then converted your MDI example to VS2008 and opened it as is, which works well until I added a control (a button) to the container. (See attached project).
At that point, I got the same problem as with my form, namely the child form is shown UNDER the main form controls which is unacceptable.
I send you back the project with the hope you can find the problem. I also suggest that you will try to add a control to your original MDI demo and see if there is a differenece between the versions.
Regards,
Sam
Tanmay SarkarPosted Oct 30, 2010, 10:20 AM
http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe
if you need any other link then you can find here also
http://www.c-sharpcorner.com/UploadFile/Blogs/3580/
Probably you can't open project file with 2008 but you may open *.cs file with note pad or any text editor to see the code.
Thank you!
Tanmay SarkarPosted Oct 30, 2010, 10:13 AM
Form2 frm2 = new Form2();
frm2.MdiParent = this;
frm2.Show();
and never forget to set form1, this.IsMdiContainer = true;
you may check it in properties window (which you already done).
reset(or disable) the topmost value. it's not required for mdi child-parent form.
Thank you!
SamPosted Oct 30, 2010, 8:03 AM
Thanks for your reply.
I added the snippet you suggested, and indeed it solved the main form background color issue.
I still need to dig into it to better understand why it is like this.
(I could not use your code example as it seem to have been compiled under VS201 that can not run on my 2008).
Regarding the Child form being under the Main form's controls, i still can not resolve this one, which inhibits the use of the child form.
Sam