473,322 Members | 1,352 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,322 software developers and data experts.

Custom Paint with Gradient Panel

In my WinForms app I'd long ago implemented a drag & drop mechanism just like
is used in PowerPoint when one wants to rearrange the order of the slides.
Specifically, a thin black line is shown between thumbnails to indicate where
an item will be dropped.

As the user moved away I'd erase it by simply drawing another line using the
BackColor of the panel. This worked great! But I've recently switched to
using a Gradient panel and so now the BackColor no longer applies.

Can anyone recommend how I should erase the thin black line?

--
Robert W.
Vancouver, BC
www.mwtech.com
May 2 '06 #1
3 6846
On Mon, 1 May 2006 18:34:02 -0700, Robert W. wrote:
In my WinForms app I'd long ago implemented a drag & drop mechanism just like
is used in PowerPoint when one wants to rearrange the order of the slides.
Specifically, a thin black line is shown between thumbnails to indicate where
an item will be dropped.

As the user moved away I'd erase it by simply drawing another line using the
BackColor of the panel. This worked great! But I've recently switched to
using a Gradient panel and so now the BackColor no longer applies.

Can anyone recommend how I should erase the thin black line?


It's not very clear how you've implemented the black line drawing (which
control is drawing it?). If the panel is drawing it, then calling its
Invalidate() method passing the appropriate rectangle will cause the panel
to redraw itself properly. If the drawing is made by the form, then call
the form's Invalidate() method passing the appropriate rectangle to force
it to redraw properly.
May 2 '06 #2
Mehdi,

Thank you so much! I wasn't very familiar with "Invalidate" but your
response lead me to a successful fix.

In case you're wondering, originally I had just one method to draw and erase
lines:

private void DrawSeparatorLine(Panel panel, int y, Color color)
{
Graphics g = panel.CreateGraphics();
Pen myPen = new Pen(color, 1);
g.DrawLine(myPen, 2, y, panel.ClientSize.Width - 2 , y); // Leave
2-pixel gap
g.Dispose();
}
But it wasn't working once I switched to gradient panels. To resolve the
problem I implemented a second method:

private void EraseSeparatorLine(Panel panel, int y)
{
Graphics g = panel.CreateGraphics();
Rectangle rect = new Rectangle(2, y, panel.ClientSize.Width - 2, 1);
panel.Invalidate(rect, false);
g.Dispose();
}
Though written for the general public, I even gave you credit on my blog:
http://pelalusa.blogspot.com/2006/05...can-be-so.html

Thank you again!

--
Robert W.
Vancouver, BC
www.mwtech.com

"Mehdi" wrote:
On Mon, 1 May 2006 18:34:02 -0700, Robert W. wrote:
In my WinForms app I'd long ago implemented a drag & drop mechanism just like
is used in PowerPoint when one wants to rearrange the order of the slides.
Specifically, a thin black line is shown between thumbnails to indicate where
an item will be dropped.

As the user moved away I'd erase it by simply drawing another line using the
BackColor of the panel. This worked great! But I've recently switched to
using a Gradient panel and so now the BackColor no longer applies.

Can anyone recommend how I should erase the thin black line?


It's not very clear how you've implemented the black line drawing (which
control is drawing it?). If the panel is drawing it, then calling its
Invalidate() method passing the appropriate rectangle will cause the panel
to redraw itself properly. If the drawing is made by the form, then call
the form's Invalidate() method passing the appropriate rectangle to force
it to redraw properly.

May 3 '06 #3
On Tue, 2 May 2006 21:14:01 -0700, Robert W. wrote:

private void EraseSeparatorLine(Panel panel, int y)
{
Graphics g = panel.CreateGraphics();
Rectangle rect = new Rectangle(2, y, panel.ClientSize.Width - 2, 1);
panel.Invalidate(rect, false);
g.Dispose();
}


Note that you do not need to create a Graphics object here (it's not being
used). You can remove the first and the last line of your code to save time
and ressources.
May 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: | last post by:
Please, help. I created my contol, ButtonX, which subclasses System.Forms.Windows.Button class. I am doing my own paiting, by overriding OnPaint and OnPaintBackground (without calling base...
2
by: Daniel | last post by:
Hi, I use paint event to draw gradient on a Panel. But how to get the label to be transaparent on a gradient draw Panel? Thank you. Regards, Daniel
4
by: CroDude | last post by:
I've made a custom groupbox control. Inside, as one of it's members is CSimpleGradient object. CSimpleGradient is a wrapper class for gradient usage. Basically it looks like that: public class...
4
by: Aaron Smith | last post by:
I have a panel that I have in the paint event to draw a Raised 3d border around it.. The problem is, if a msgbox is popped up or a tooltip is displayed, it leaves lines on the panel. I've tried...
1
by: Robert W. | last post by:
In my WinForms app I've long been able to create a linear gradient effect by just intercepting the PaintEventHandler event. But I'd now like to create an inherited user control, specifically of a...
8
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I want to create a custom form border. By thought was to simply override the DisplayRectangle property in order to control the border width and then draw the border during the OnPaint event. The...
5
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
Hi, On a usercontrol I've put a set of radiobuttons within a groupbox. These radiobuttons have visual style enables, i.e. they turn orange when hovering over them and green when pushed. ...
2
tranc3d
by: tranc3d | last post by:
Hello, I have a custom panel in my project (this one: http://www.codeproject.com/KB/graphics/fastimagedrawing.aspx) with a custom paint event ( protected override void OnPaint(PaintEventArgs pe)...
2
by: DaveL | last post by:
when painting the background of a mdi app window how can i resolve the flicker when it paints from darker to lighter colors below is the code i wrote private void...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.