By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,640 Members | 1,581 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,640 IT Pros & Developers. It's quick & easy.

Please Help: MDI Container Form with Label on the background

P: n/a
Hi all

I have a MDI Container Form, with one label control
on the Background of this container form.
When I now open a child form, this form is behind
the label ... and this looks ugly ... :-))

When I set the label with "SendToBack", it completely disapears.
I also tried to set the child form like "BringToFront" but this also does
not help.

Does anybody know how to handle this problem ??

Thanks for any comments and best regards
Frank Uray
Sep 24 '08 #1
Share this Question
Share on Google+
9 Replies


P: n/a
What are you trying to do, Frank?

It sounds like you want a label to appear over the Child Form(s) with a
transparent background.

Your label is on the MDI Form? If this is your goal, try the following:
In the Designer, select your label. In the Appearances category, set the
BackColor to Transparent (on the Web pallet). Tada!

"Frank Uray" wrote:
Hi all

I have a MDI Container Form, with one label control
on the Background of this container form.
When I now open a child form, this form is behind
the label ... and this looks ugly ... :-))

When I set the label with "SendToBack", it completely disapears.
I also tried to set the child form like "BringToFront" but this also does
not help.

Does anybody know how to handle this problem ??

Thanks for any comments and best regards
Frank Uray
Sep 24 '08 #2

P: n/a
Hi

Thanks for your answer.

I am trying to do the following:

I have a form (IsMdiContainer = true).
On this Form I place a label, for example "Version 1.0".
What I now want is: When I open a child form and when
I move this over the Label, the Label should be behind this
Child form (not visible any more).
Now when I move the child form over the label,
the text of this label appears to be on the child form ...

Thanks for your help.

Best regards
Frank


"jp2msft" wrote:
What are you trying to do, Frank?

It sounds like you want a label to appear over the Child Form(s) with a
transparent background.

Your label is on the MDI Form? If this is your goal, try the following:
In the Designer, select your label. In the Appearances category, set the
BackColor to Transparent (on the Web pallet). Tada!

"Frank Uray" wrote:
Hi all

I have a MDI Container Form, with one label control
on the Background of this container form.
When I now open a child form, this form is behind
the label ... and this looks ugly ... :-))

When I set the label with "SendToBack", it completely disapears.
I also tried to set the child form like "BringToFront" but this also does
not help.

Does anybody know how to handle this problem ??

Thanks for any comments and best regards
Frank Uray
Sep 24 '08 #3

P: n/a
On Sep 24, 12:59*pm, Frank Uray <FrankU...@discussions.microsoft.com>
wrote:
Hi

Thanks for your answer.

I am trying to do the following:

I have a form (IsMdiContainer = true).
On this Form I place a label, for example "Version 1.0".
What I now want is: When I open a child form and when
I move this over the Label, the Label should be behind this
Child form (not visible any more).
Now when I move the child form over the label,
the text of this label appears to be on the child form ...

Thanks for your help.

Best regards
Frank

"jp2msft" wrote:
What are you trying to do, Frank?
It sounds like you want a label to appear over the Child Form(s) with a
transparent background.
Your label is on the MDI Form? If this is your goal, try the following:
In the Designer, select your label. In the Appearances category, set the
BackColor to Transparent (on the Web pallet). Tada!
"Frank Uray" wrote:
Hi all
I have a MDI Container Form, with one label control
on the Background of this container form.
When I now open a child form, this form is behind
the label ... and this looks ugly ... :-))
When I set the label with "SendToBack", it completely disapears.
I also tried to set the child form like "BringToFront" but this also does
not help.
Does anybody know how to handle this problem ??
Thanks for any comments and best regards
Frank Uray- Hide quoted text -

- Show quoted text -

Frank,

My first impulse was to suggest that if your goal was to make the mdi
parent's Label contents visible regardless of the location of child
windows, perhaps you can put the Label's contents on a StatusStrip on
the parent form.

I also thought about what you'd have to do to get your idea (as I
understand it) to work. You'd basically have to perform some hit
testing to determine if a child form is over the Label on the mdi
parent. If so, you'd set the Visible property on your parent form
Label to false, and you'd set a similar Label on the child to true.

I tried a quick experiment and it appeared to work. What I did was
create a child form with an event that contains the form's location
and size in its parameters. This event fires on the form's
LocationChanged and ResizeEnd events. The mdi parent subscribes to
these events and each time they are raised, the parent sees if the
moved child form overlaps the parent's label. If so parent's Label's
Visible property is set to false and the child form's Label is set to
true, through a method on the child form.
Here's what I did:
1. Create a new project and create a mdi parent form.
2. Add a Label to this form. I called mine label1.
3. Add a child form to your project and add a label to it. I called
this form Child.cs and the Label label1.
4. On the Child form, I added this code:

internal delegate void MdiChildMovedHandler(object sender, Point
location, Size size);
internal event MdiChildMovedHandler MdiChildMoved;

private void Child_LocationChanged(object sender, EventArgs e) {
if (MdiChildMoved != null) {
MdiChildMoved(this, this.Location, this.Size);
}
}

internal void SetLabelVisible(bool setting) {
label1.Visible = setting;
}

private void Child_ResizeEnd(object sender, EventArgs e) {
if (MdiChildMoved != null) {
MdiChildMoved(this, this.Location, this.Size);
}
}

5. Add the following code to the parent form:

private void MdiChildMoved(object sender, Point location, Size size) {
//Console.WriteLine("ID: {4} -- x:{0}, y:{1}, w:{2}, h:{3}",
location.X, location.Y, size.Width, size.Height,
((Child)sender).Name);
Rectangle formRectangle = new Rectangle(location, size);
Rectangle labelRectangle = new Rectangle(label1.Location,
label1.Size);
label1.Visible = !LabelInsideChild(formRectangle, labelRectangle);
((Child)sender).SetLabelVisible(LabelInsideChild(f ormRectangle,
labelRectangle));
}

// Return true if the label rectangle is completely contained in the
child form's rectangle.
private bool LabelInsideChild(Rectangle labelRectangle, Rectangle
childFormRectangle) {
Point formTopLeftPoint = new Point(childFormRectangle.Left,
childFormRectangle.Top);
Point formTopRightPoint = new Point(childFormRectangle.Left +
childFormRectangle.Width, childFormRectangle.Top);
Point formBottomLeftPoint = new Point(childFormRectangle.Left,
childFormRectangle.Top + childFormRectangle.Height);
Point formBottomRightPoint = new Point(childFormRectangle.Left +
childFormRectangle.Width, childFormRectangle.Top +
childFormRectangle.Height);

// Check Top Left, Top Right, Bottom Left, Bottom Right.
Console.WriteLine(" TL: {0} [x:{1},y:{2}]",
PointInsideRectangle(labelRectangle, formTopLeftPoint),
childFormRectangle.Top, childFormRectangle.Left);
Console.WriteLine(" TR: {0} [x:{1},y:{2}]",
PointInsideRectangle(labelRectangle, formTopRightPoint),
childFormRectangle.Top, childFormRectangle.Left +
childFormRectangle.Width);
Console.WriteLine(" BL: {0} [x:{1},y:{2}]",
PointInsideRectangle(labelRectangle, formBottomLeftPoint),
childFormRectangle.Top + childFormRectangle.Height,
childFormRectangle.Left);
Console.WriteLine(" BR: {0} [x:{1},y:{2}]",
PointInsideRectangle(labelRectangle, formBottomRightPoint),
childFormRectangle.Top + childFormRectangle.Height,
childFormRectangle.Left + childFormRectangle.Width);
Console.WriteLine("======================");
return PointInsideRectangle(labelRectangle, formTopLeftPoint)
&& PointInsideRectangle(labelRectangle, formTopRightPoint)
&& PointInsideRectangle(labelRectangle, formBottomLeftPoint)
&& PointInsideRectangle(labelRectangle,
formBottomRightPoint);
}

// Return true if the Point is inside the Rectangle.
private bool PointInsideRectangle(Rectangle r, Point p) {
return (r.X < p.X) && (p.X < (r.X + r.Width)) && (r.Y < p.Y) && (p.Y
< (r.Y + r.Height));
}

Your child forms would subscribe to the MdiChildMoved event


Give this a try. It worked for me but you'll want to test and refine
things a bit. I tried to format my code so it wouldn't be too
difficult for you to copy and paste it. If you want I can email you
the project file (VS 2005).

-Jay
Sep 25 '08 #4

P: n/a
Hi Jay

Thanks a lot for your answer !!

I am not sure if you mean the same as I ...

Try to do the following:
- Create a new C# Application Solution.
- Set the Form1 as MdiContainer = true
- Place a Label in the middle of Form1
- In the Load Event of Form1 place the following code:
this.IsMdiContainer = true;
System.Windows.Forms.Form local_Form = new System.Windows.Forms.Form();
local_Form.MdiParent = this;
local_Form.Show();

When you now move the child form over the Label,
the Label appears on the child form ...
This is what I dont want. The Label should be always
behind every child form.

Thanks for your help on this !

Best regards
Frank

Sep 25 '08 #5

P: n/a
Jay's response would probably handle what you need, but the way I see it -
I'm sure it would be choppy (I did not actually build the project, though).

If I follow Jay's logic correctly, if the child form's edges creap into the
space of the MDI form's label, the label is hidden.

I'm not sure, though, if Jay's version would handle the case of a form being
created or being maximized to cover the label.

I'm still following this post, but it is likely that this is not something
that can be naturally done.

Here's an interesting theory: Since an MDI form is essentially a container
for other forms, it may be forms created in the MDI parent are being treated
as if they are being displayed behind a glass wall (uh... Windows) so when
labels are dropped on the MDI form, they are being placed on top of the plate
glass. I don't know if that is the case, though. I don't know *how* software
development tools go about creating an MDI application.

"Frank Uray" wrote:
Hi Jay

Thanks a lot for your answer !!

I am not sure if you mean the same as I ...

Try to do the following:
- Create a new C# Application Solution.
- Set the Form1 as MdiContainer = true
- Place a Label in the middle of Form1
- In the Load Event of Form1 place the following code:
this.IsMdiContainer = true;
System.Windows.Forms.Form local_Form = new System.Windows.Forms.Form();
local_Form.MdiParent = this;
local_Form.Show();

When you now move the child form over the Label,
the Label appears on the child form ...
This is what I dont want. The Label should be always
behind every child form.

Thanks for your help on this !

Best regards
Frank
Sep 25 '08 #6

P: n/a
On Sep 25, 1:50*am, Frank Uray <FrankU...@discussions.microsoft.com>
wrote:
Hi Jay

Thanks a lot for your answer !!

I am not sure if you mean the same as I ...

Try to do the following:
- Create a new C# Application Solution.
- Set the Form1 as MdiContainer = true
- Place a Label in the middle of Form1
- In the Load Event of Form1 place the following code:
* *this.IsMdiContainer = true;
* *System.Windows.Forms.Form local_Form = new System.Windows.Forms.Form();
* *local_Form.MdiParent = this;
* *local_Form.Show();

When you now move the child form over the Label,
the Label appears on the child form ...
This is what I dont want. The Label should be always
behind every child form.

Thanks for your help on this !

Best regards
Frank


Hi Frank,

Sorry, I misunderstood some of what you want. As jp2msft said, what I
wrote would probably handle what you needed but it could be improved
upon.

To just display a string on a mdi background you can override the mdi
parent's OnPaint event and 'manually' draw a string (what you want in
the Label) on the background using the DrawString method. I did this
on a .net 1.1 application and it worked great. Unfortunately I don't
have the source here at work and I couldn't find any decent links in a
quick Google search I did.

I can post some details later at about 9 pm PST.

-Jay

Sep 25 '08 #7

P: n/a
Have you considered creating an image with the text you want, and
regenerating the image if the label text needs altering? You then would use
this image as the MDI container background. I've put images back there but
never a control.

"Frank Uray" <Fr*******@discussions.microsoft.comwrote in message
news:C1**********************************@microsof t.com...
Hi all

I have a MDI Container Form, with one label control
on the Background of this container form.
When I now open a child form, this form is behind
the label ... and this looks ugly ... :-))

When I set the label with "SendToBack", it completely disapears.
I also tried to set the child form like "BringToFront" but this also does
not help.

Does anybody know how to handle this problem ??

Thanks for any comments and best regards
Frank Uray
Sep 25 '08 #8

P: n/a
On Sep 25, 1:50*am, Frank Uray <FrankU...@discussions.microsoft.com>
wrote:
Hi Jay

Thanks a lot for your answer !!

I am not sure if you mean the same as I ...

Try to do the following:
- Create a new C# Application Solution.
- Set the Form1 as MdiContainer = true
- Place a Label in the middle of Form1
- In the Load Event of Form1 place the following code:
* *this.IsMdiContainer = true;
* *System.Windows.Forms.Form local_Form = new System.Windows.Forms.Form();
* *local_Form.MdiParent = this;
* *local_Form.Show();

When you now move the child form over the Label,
the Label appears on the child form ...
This is what I dont want. The Label should be always
behind every child form.

Thanks for your help on this !

Best regards
Frank

Frank,

OK, I looked over my project where I succesfully write text to a mdi
parent's background and the way I 'drew' this text is to create an in-
memory bitmap that includes the text and then use this bitmap as the
parent's background image. Any mdi client forms will hide the text on
the mdi parent's background.

I created a minimal functioning solution in C# 2.0 that demonstrates
this but I noticed that when I resize the mdi parent, the background
flickers a bit. It doesn't do this on my 1.1 project. I'm not sure
why this is but I think you'll find the project useful.

Here's how I did it.

1. Create a new project. On Form1 set the IsMdiContainer property to
true.
2. Add the following field to the form's code:

private MdiClient _mdiClient;
3. Create a Load event for the form, and add this code:

private void Form1_Load(object sender, EventArgs e) {
foreach (Control c in this.Controls) {
_mdiClient = c as MdiClient;
if (_mdiClient != null) {
break;
}
}
_mdiClient.Resize += new EventHandler(mdiClient_Resize);
}
4. Add the following event to the form:

private void mdiClient_Resize(object sender, System.EventArgs e) {
Bitmap bufferImage;
Rectangle r = new Rectangle(Point.Empty, _mdiClient.Size);

if (r.Height <= 0 || r.Width <= 0) {
return;
}

bufferImage = new Bitmap(r.Width, r.Height);
Graphics g = Graphics.FromImage(bufferImage);

StringFormat sf = new StringFormat(StringFormatFlags.NoWrap);

string text = "Press F12 to log in";
sf.LineAlignment = StringAlignment.Center;
SolidBrush brush = new SolidBrush(SystemColors.ControlDarkDark);
g.FillRectangle(brush, r);
brush.Dispose();

Font font = new Font("Arial Rounded MT Bold", 36,
FontStyle.Regular, GraphicsUnit.Pixel);
sf.Alignment = StringAlignment.Center;
sf.Trimming = StringTrimming.EllipsisWord;
g.DrawString(text, font, Brushes.Yellow, (RectangleF)r, sf);

font.Dispose();
sf.Dispose();
g.Dispose();

_mdiClient.BackgroundImage = bufferImage;
}

That should do it!

The way it works is pretty simple: When the form loads it finds a
reference to the MdiClient control and it adds a Resize event. The
Resize event creates the background image I talked about, adds,
formats and positions text on this image and then sets this image to
the MdiClient control's BackgroundImage property.

Let me know if this works for you. If you can correct the flickering,
let me know.

-Jay
Sep 26 '08 #9

P: n/a
Any Controls placed on the MDIClient will always show on top of any MDI
Child Forms.
Draw to the MDIClient rather than placing a Control onto it.

You'll find an example on my Form Tips page:
http://dotnetrix.co.uk/form.htm

--
Mick Doherty
http://dotnetrix.co.uk/nothing.htm
Sep 26 '08 #10

This discussion thread is closed

Replies have been disabled for this discussion.