473,769 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6864
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 DrawSeparatorLi ne(Panel panel, int y, Color color)
{
Graphics g = panel.CreateGra phics();
Pen myPen = new Pen(color, 1);
g.DrawLine(myPe n, 2, y, panel.ClientSiz e.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 EraseSeparatorL ine(Panel panel, int y)
{
Graphics g = panel.CreateGra phics();
Rectangle rect = new Rectangle(2, y, panel.ClientSiz e.Width - 2, 1);
panel.Invalidat e(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 EraseSeparatorL ine(Panel panel, int y)
{
Graphics g = panel.CreateGra phics();
Rectangle rect = new Rectangle(2, y, panel.ClientSiz e.Width - 2, 1);
panel.Invalidat e(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
5676
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 class's OnPaint & OnPaintBackground). My button has a shape of rectangle with rounded corners and is filled with gradient brush, where user specifies the gradient colors. The dilema I have now is how to paint the button when it's disabled (Enabled =...
2
8933
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
2568
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 CSimpleGradient { private float m_GradientAngle; private Color m_ColorA; private Color m_ColorB;
4
11699
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 invalidate after the msgbox to no avail... Here is the event: Private Sub Panel2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel2.Paint ControlPaint.DrawBorder3D(e.Graphics, e.ClipRectangle,...
1
6297
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 panel. I thought I was on the right track and did achieve the effect ... until I started putting some controls on the panel. Then I got an "Invalid parameter" error but don't understand what it's referring to. Based on examples I've found,...
8
14729
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 problem with this technique is that controls that are outside of the ClientRectangle of the form will overlap the form's border. You can see this in the following example: Public Class Form1 Inherits Windows.Forms.Form Private Const...
5
2093
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. Normally I put my updation of data shown in the controls on the usercontrol in the Paint event handler of the usercontrol. When it comes to the radiobuttons, a paint event for the usercontrol is fired whenever hovering over the radiobuttons, making...
2
5667
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) ). You set an image to the Image property of the custom panel, and it scrolls very smoothly through that image according to the value of the scrollbars, in an optimised way in the above OnPaint function. Through the designer, i dropped this custom...
2
2080
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 ShellWindow_Gradient(object sender, PaintEventArgs e) {
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.