473,765 Members | 2,086 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with OnPaint in custom label control

Hi there

I have a custom label control (GradientLabel) which enherits from Label and
basically just paints the background of a label in a gradient.

In my code I have the following for the overidden OnResize event:

protected override void OnPaint(PaintEv entArgs e)
{
Graphics g = e.Graphics;
using (LinearGradient Brush br = new LinearGradientB rush(e.ClipRect angle,
color1, color2, gradient_mode))
{
g.FillRectangle (br, e.ClipRectangle );
}
base.OnPaint(e) ;
}

(The Color1 and Color2 and gradient_mode are set using properties to get the
designtime representation to work)

Now the odd part is this. I have two different machines, a desktop and a
laptop, both running .NET 2.0. On my desktop there is no problem when I
resize the control and the gradient follows nicely, also when I maximize the
window etc.
On my laptop however, everything works except when I maximize the form in
which the label resides. The gradient simply cuts off and starts over where
the form was maximized from.
I have tried overriding a lot of different events, including the forms own
OnResize event and then through that calling the labels Refresh() method,
but no luck.

What is the problem? I suspect it for being a machine specific problem, but
it would be nice if I somehow could get a reason :)

Another problem is when I drag another window across the label. It then
won't repaint itself. How do I get it to do that?

Sincerely
Kenneth, Denmark
Mar 7 '06 #1
1 8245
Kenneth,

I think that your logic is wrong. Instead of passing the ClipRectangle,
what I would do is pass a rectangle which has the size of your label (from
0, 0 to length, width). The ClipRectangle is just the area of the screen
that needs repainting, not the whole label, so theoretically, your gradient
can shift depending on what needs to be refreshed.

Then, when you call FillRectangle, you can pass the clip rectangle and
the brush should be applied appropriately.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Kenneth Siewers Møller" <ke*****@siewer s.dk> wrote in message
news:44******** *************** @dreader2.cyber city.dk...
Hi there

I have a custom label control (GradientLabel) which enherits from Label
and basically just paints the background of a label in a gradient.

In my code I have the following for the overidden OnResize event:

protected override void OnPaint(PaintEv entArgs e)
{
Graphics g = e.Graphics;
using (LinearGradient Brush br = new
LinearGradientB rush(e.ClipRect angle, color1, color2, gradient_mode))
{
g.FillRectangle (br, e.ClipRectangle );
}
base.OnPaint(e) ;
}

(The Color1 and Color2 and gradient_mode are set using properties to get
the designtime representation to work)

Now the odd part is this. I have two different machines, a desktop and a
laptop, both running .NET 2.0. On my desktop there is no problem when I
resize the control and the gradient follows nicely, also when I maximize
the window etc.
On my laptop however, everything works except when I maximize the form in
which the label resides. The gradient simply cuts off and starts over
where the form was maximized from.
I have tried overriding a lot of different events, including the forms own
OnResize event and then through that calling the labels Refresh() method,
but no luck.

What is the problem? I suspect it for being a machine specific problem,
but it would be nice if I somehow could get a reason :)

Another problem is when I drag another window across the label. It then
won't repaint itself. How do I get it to do that?

Sincerely
Kenneth, Denmark

Mar 7 '06 #2

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

Similar topics

5
2426
by: DraguVaso | last post by:
Hi, I have my custom Inherited DataGrid. I override the OnPaint-event to speed up things and avoid flikkering using Double Buffering. To draw the normal things of the DataGrid I have to call the MyBase.OnPain(pe). But in my opinion it doesn't seem to be painted on the buffer. Everything works fine, but I think it should work better if my MyBase.OnPaint also painted in my buffer. Am I wrong? And how should I do this? I kind of need to...
11
6196
by: Sagaert Johan | last post by:
I have made a custom control that draws a rectangle when the mouse is down, and does nothing when the mouse is up. I set/reset a flag in MouseDown/Mouse up and use this to do the drawing in the OnPaint . The recangle draws correct when i press the mouse, but when i release the mouse the background is not restored What should i do in the Onpaint to make sure the background (the form) is restored correctly ? This problem already keeps...
7
3537
by: Jeroen Ceuppens | last post by:
Hi, When I draw a bitmap on a form, the bitmapdrawing disappears when I move the form, how is it possible to lock the drawing so it stays visible when you move or do somethings else.... Thx Jeroen
5
3085
by: Ron Vecchi | last post by:
I have a custyom control that has a property which wraps a collection. When I add controls to the collection the OnPaint method of these newly added controls never get fired. But if I take the controls in the collection and add them to the custom controls ControlCollection the OnPaint method is called. I would like to use my Collection property but It seems that the controls need to be added to the ControlCollection for them to work....
2
3564
by: CMEDIA_SOUND | last post by:
I have a peculiar problem, I have a tabpage with a label control on it. When i set a background image to the tabpage and drag the label around it has paint issues in that it is slow, granted the image i am using is 5mb!!! HOWEVER... I have inherited the tabpage created an Image reference in it, and overrriden the onPaint method to draw the image now if i press a button that sets the background image of the control
1
264
by: Dave | last post by:
Hi all, I'm creating a control derived from System.Windows.Forms.Control I override the OnPaint() function The control takes place on a form with a background image. Because I've some problems to draw properly my control, I decided to test it with a OnPaint() function which does *absolutely nothing*. And I'm very surprised : I don't understand why the control seems to draw itself !? I get a rectangle filled with the background color of...
20
2574
by: BB | last post by:
Hello all, I am trying to override OnPaint in a custom textbox control (so I can drawstring a caption, etc.). In the code below, I get the "painting the form" message as expected, but not the "painting the control". It also has no effect to explicitly call txtTest.Invalidate or txtTest.Refresh. Am I missing something simple here? Any push in the right direction is appreciated.
1
1480
by: Brian Henry | last post by:
I am trying to make a custom user control that gets a list of users from our database and populates the list, its an owner drawn control also, the problem is, I placed the item onto a form and every time i make a change to the control it reads the database and adds new items to the listing but never gets rid of the old items in the list, the form seems to be makeing a stored copy of the items locally then rebuilding the list ontop of it......
7
2465
by: Dino Buljubasic | last post by:
Hi, I am using C# 2.0 (VS2005) to build my user control that contains a number of dynamically loaded ListViews. ListViewItems have their ForeColor properties set to either black or blue to distinguish between ListViewItems. As long as no other application window (i.e. word or calculator, or ....) goes over my running form, ForeColor properties or each ListViewItem stays black or blue as intended.
0
9566
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
9393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9832
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...
1
7371
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6646
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();...
0
5272
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5413
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3530
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.