473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Please Help: MDI Container Form with Label on the background

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
9 7962
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Johnny | last post by:
Hi together, I'm new to XML and have problems with FOP (http://www.apache.org/dyn/closer.cgi/xml/fop) When I try to convert my .fo document to .pdf, I get this message: fo:39:26...
10
by: Joe | last post by:
Hi, Tried using the FindControl() but no luck in finidng this damn textbox having id txtFirstName. Can someone help me with this method? This is what I have been doing but it doesn't work, ...
3
by: ntexchange05 | last post by:
I am trying to learn asp.net and build a site and i am using web matrix and vb.net. I have installed the MSDE on my windows xp pro, i am using the book calledbeginning dynamic websites with...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
2
by: momo | last post by:
Hello Guys, I have a bit of a problem, I created a Dll called SecureQueryStringDll.dll and I had the dll put bin folder of my application first and it did not work so I then put it in the bin...
4
by: _Raven | last post by:
Okay, I am playing with submitting forms with Ajax. I am trying to adapt this script to my forms: http://www.captain.at/howto-ajax-form-post-get.php I have included my code at the bottom of this...
0
by: gauravkg via DotNetMonster.com | last post by:
Problem : I have a nested repeater in which i am showing data through table | title | | description | | title | | description | on load the description is hidden...
6
by: shapper | last post by:
Hello, I am creating a form that includes a few JQuery scripts and TinyMCE Editor: http://www.27lamps.com/Beta/Form/Form.html I am having a few problems with my CSS: 1. Restyling the Select
0
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= | last post by:
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 ... :-))...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.