PC Review


Reply
Thread Tools Rate Thread

Drawing over child controls

 
 
=?Utf-8?B?UjJEMg==?=
Guest
Posts: n/a
 
      12th Jun 2006
Hello,

I am trying to get a form to draw arrows linking 2 list boxes to each other.
I can write the code to draw the arrows / make them follow the boxes around
when they are dragged around the form, however, the form always draws the
arrow under the child controls.
I was wondering if anyone could tell me how I would make the arrows draw
over the list boxes, instead of pass under them?

The only idea I had was to call base.onPaint first, then draw the arrows,
but this does not work. [That may sound basic, but I haven't had the need to
do anything like this before, so I don't know much about it].
Any help would be greatly appreciated.

Thanks
 
Reply With Quote
 
 
 
 
Chris Jobson
Guest
Posts: n/a
 
      12th Jun 2006
"R2D2" <(E-Mail Removed)> wrote in message
news:07822C85-4A79-46B6-92FF-(E-Mail Removed)...
> Hello,
>
> I am trying to get a form to draw arrows linking 2 list boxes to each
> other.
> I can write the code to draw the arrows / make them follow the boxes
> around
> when they are dragged around the form, however, the form always draws the
> arrow under the child controls.
> I was wondering if anyone could tell me how I would make the arrows draw
> over the list boxes, instead of pass under them?
>
> The only idea I had was to call base.onPaint first, then draw the arrows,
> but this does not work. [That may sound basic, but I haven't had the need
> to
> do anything like this before, so I don't know much about it].
> Any help would be greatly appreciated.
>
> Thanks


I can think of two ways to do this (but I don't recommend either of them,
and I'm sure someone else can come up with something better).

1. Use a transparent panel as the topmost control on the form and draw the
lines on this panel. There's an article on creating a transparent panel at
http://www.codeproject.com/useritems...TransPanel.asp. The snag with this
is that clicking on a control selects the transparent panel rather than the
control you clicked on. I think I've seen somewhere another version of
atransparent panel that gets round this (rather like the forms designer in
VS), but I'm not sure where.

2. Remove the WS_CLIPCHILDREN style from the form so that the form is
allowed to draw over the controls on it. This can be done as follows:

const int WS_CLIPCHILDREN = 0x02000000;
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Style &= ~WS_CLIPCHILDREN;
return cp;
}
}

Unfortunately there is still a problem because when the form is drawn it
seems to do its own painting first and then paint the controls. The way
round this I've found is to fire a 1ms timer in the paint event, then draw
the lines in the timer event, e.g.

private void Form1_Paint(object sender, PaintEventArgs e)
{
timer1.Enabled = true; // timer1.Interval = 1
}
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
Graphics g = CreateGraphics();
g.DrawLine(Pens.Black, 0, 0, ClientSize.Width, ClientSize.Height);
}

However, I suspect there's a better way round this problem - any ideas
anyone?

Chris Jobson


 
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
Controls.Add() for a Web User Control doesn't instansiate its child controls Ofer Zelig Microsoft ASP .NET 11 28th Mar 2007 02:15 PM
RE: Controls.Add() for a Web User Control doesn't instansiate its child controls Walter Wang [MSFT] Microsoft ASP .NET 0 28th Mar 2007 03:02 AM
Drawing transparent controls over activex controls Michiel Microsoft C# .NET 0 10th Nov 2004 03:06 PM
drawing on the child control Lloyd Dupont Microsoft Dot NET Framework Forms 2 25th Jun 2004 02:24 AM
How to force the child controls OnClick event before the parent controls CreateChildControls method? Arulraja Microsoft ASP .NET 3 17th Oct 2003 05:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:15 PM.