PC Review


Reply
Thread Tools Rate Thread

2 Controls overlap

 
 
Martijn Mulder
Guest
Posts: n/a
 
      6th Jan 2009
I want 2 UserControls with Dock=DockStyle.Fill share the same space in a
Form, ie Paint them on top of each other.

I made the UserControls keep the Background intact, but only one shows up.
See the code below:


//using...
using System.Drawing;
using System.Windows.Forms;


//class Circle
class Circle: UserControl
{

//constructor
public Circle()
{
Dock= DockStyle.Fill;
}

//method OnPaint
override protected void OnPaint( PaintEventArgs e)
{
e.Graphics.FillEllipse( Brushes.Yellow, new Rectangle(5, 5, 50, 50));
}

//method OnPaintBackground
override protected void OnPaintBackground( PaintEventArgs e)
{
//Do nothing. Leave Background intact
}
}


//class Square
class Square: UserControl
{

//constructor
public Square()
{
Dock= DockStyle.Fill;
}

//method OnPaint
override protected void OnPaint( PaintEventArgs e)
{
e.Graphics.FillRectangle( Brushes.Red, new Rectangle( 25, 25, 50, 50));
}

//method OnPaintBackground
override protected void OnPaintBackground( PaintEventArgs e)
{
//Do nothing. Leave Background intact
}
}


//class MainForm
class MainForm: Form
{

//constructor
MainForm()
{
Text="Controls Share Space (NOT!)"; // Only the Circle shows!
Controls.Add( new Circle());
Controls.Add( new Square());
}

//method Main
static void Main()
{
Application.Run(new MainForm());
}
}



 
Reply With Quote
 
 
 
 
Jeff Gaines
Guest
Posts: n/a
 
      7th Jan 2009
On 06/01/2009 in message <4963dcad$0$82467$(E-Mail Removed)>
Martijn Mulder wrote:

>I want 2 UserControls with Dock=DockStyle.Fill share the same space in a
>Form, ie Paint them on top of each other.
>
>I made the UserControls keep the Background intact, but only one shows up.
>See the code below:


[code snipped]

That is the behaviour I would expect. If I put a plate on a table then put
another plate on top of the first plate I would only be able to see the
top plate when looking down at them.

--
Jeff Gaines Damerham Hampshire UK
There are 10 types of people in the world, those who do binary and those
who don't.
 
Reply With Quote
 
Martijn Mulder
Guest
Posts: n/a
 
      7th Jan 2009
> That is the behaviour I would expect. If I put a plate on a table then put
> another plate on top of the first plate I would only be able to see the
> top plate when looking down at them.


So it is by design? It is not like stacking glass plates, one with green
eggs, the other with ham. So that when I look from above, I see green eggs
and ham?


 
Reply With Quote
 
Jeff Gaines
Guest
Posts: n/a
 
      7th Jan 2009
On 07/01/2009 in message <49648a7a$0$83234$(E-Mail Removed)>
Martijn Mulder wrote:

>>That is the behaviour I would expect. If I put a plate on a table then put
>> another plate on top of the first plate I would only be able to see the top plate when looking down at them.

>
>So it is by design? It is not like stacking glass plates, one with green
>eggs, the other with ham. So that when I look from above, I see green eggs
>and ham?


The plate analogy is making me feel sick now :-)

I would say it is by design, the top most item covers what is underneath.
Can you set the transparency on the controls? I've never done it but it
may give you the 'glass plate' effect.

--
Jeff Gaines Damerham Hampshire UK
I can please only one person per day. Today is not your day.
Tomorrow, isn't looking good either.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Overlap User Controls in Windows Application? samueltilden@gmail.com Microsoft C# .NET 1 30th Apr 2008 07:42 PM
Controls overlap Dan Aldean Microsoft C# .NET 2 3rd May 2006 01:13 PM
Group Box Controls Overlap Richard Myers Microsoft VB .NET 2 5th Dec 2004 02:04 AM
Re: why controls overlap in IE S. Justin Gengo Microsoft ASP .NET 0 30th Jul 2004 02:56 PM
Controls don't overlap on design form, but do at runtime Randy Hersom Microsoft Dot NET Framework Forms 3 10th Sep 2003 10:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:30 PM.