473,498 Members | 1,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem on LinearGradientBrush

Hello

I found an abnormal behaviour on LinearGradientBrush (or FillRectangle).
This code

Public Class PanelPanel
Inherits System.Windows.Forms.Panel
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim rect As System.Drawing.Rectangle = New System.Drawing.Rectangle(10, 10, Me.Width - 20, Me.Height - 20)
Dim gradientBrush As System.Drawing.Drawing2D.LinearGradientBrush
gradientBrush = New System.Drawing.Drawing2D.LinearGradientBrush(rect, _
System.Drawing.Color.Gray, _
System.Drawing.Color.FloralWhite, _
System.Drawing.Drawing2D.LinearGradientMode.Vertic al)
e.Graphics.FillRectangle(gradientBrush, rect)
End Sub
End Class

generates a control with an rectangle drawn inside.
The problem is that an unusual line (colored Color.FloralWhite) appears on the top edge of the rectangle. This line
should not be there.
If LinearGradientMode id other than Vertical the problem persists, but it is less visible (only a small colored pixel is
visible).

Please note that the anomaly appears only with some rectangle sizes. Example:
if rect={X=10,Y=10,Width=304,Height=208} 'equivalent to a Me.Size=New Size(324,228) - Anomaly visible
if rect={X=10,Y=10,Width=304,Height=216} 'Correct, anomaly not visible

Could someone PLEASE try to reproduce the problem (just copy code as is) and confirm that is an error and then reason
with me??

Thank you!.

Carlo

(MCP)
Nov 21 '05 #1
4 3123
Carlo,

I am not seeing the problem on my laptop. However I see you did
not set the resizeredraw style to the control. It is possible the problem
is caused by the control not completely redrawing itself.

Public Class PanelPanel
Inherits System.Windows.Forms.Panel
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
Dim rect As System.Drawing.Rectangle = New
System.Drawing.Rectangle(10, 10, Me.Width - 20, Me.Height - 20)
Dim gradientBrush As System.Drawing.Drawing2D.LinearGradientBrush
gradientBrush = New
System.Drawing.Drawing2D.LinearGradientBrush(rect, _
System.Drawing.Color.Gray, _
System.Drawing.Color.FloralWhite,
_
System.Drawing.Drawing2D.LinearGradientMode.Vertic al)
e.Graphics.FillRectangle(gradientBrush, rect)
End Sub

Public Sub New()
Me.SetStyle(ControlStyles.ResizeRedraw, True)
End Sub
End Class

Ken
--------------------------
"Carlo, MCP" <ca******@gmail.com> wrote in message
news:43*********************@news.tiscali.it...
Hello

I found an abnormal behaviour on LinearGradientBrush (or FillRectangle).
This code

Public Class PanelPanel
Inherits System.Windows.Forms.Panel
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
Dim rect As System.Drawing.Rectangle = New
System.Drawing.Rectangle(10, 10, Me.Width - 20, Me.Height - 20)
Dim gradientBrush As System.Drawing.Drawing2D.LinearGradientBrush
gradientBrush = New
System.Drawing.Drawing2D.LinearGradientBrush(rect, _
System.Drawing.Color.Gray, _

System.Drawing.Color.FloralWhite, _

System.Drawing.Drawing2D.LinearGradientMode.Vertic al)
e.Graphics.FillRectangle(gradientBrush, rect)
End Sub
End Class

generates a control with an rectangle drawn inside.
The problem is that an unusual line (colored Color.FloralWhite) appears on
the top edge of the rectangle. This line should not be there.
If LinearGradientMode id other than Vertical the problem persists, but it
is less visible (only a small colored pixel is visible).

Please note that the anomaly appears only with some rectangle sizes.
Example:
if rect={X=10,Y=10,Width=304,Height=208} 'equivalent to a Me.Size=New
Size(324,228) - Anomaly visible
if rect={X=10,Y=10,Width=304,Height=216} 'Correct, anomaly not visible

Could someone PLEASE try to reproduce the problem (just copy code as is)
and confirm that is an error and then reason with me??

Thank you!.

Carlo

(MCP)

Nov 21 '05 #2
Hi Ken

on the original control (where the problem materialized the first time), ResizeRedraw is correctly set to True. I've
post a minimalist version of the original control. However, I also tested this reduced version, and it has the problem
yet.
Please, note that I used a screen magnifier to identify the problem. I believe it's very hard to see on a laptop screen.
Thank you for the help,
Carlo
"Ken Tucker [MVP]" <vb***@bellsouth.net> ha scritto nel messaggio news:ut**************@TK2MSFTNGP12.phx.gbl...
Carlo,

I am not seeing the problem on my laptop. However I see you did not set the resizeredraw style to the
control. It is possible the problem is caused by the control not completely redrawing itself.

Public Class PanelPanel
Inherits System.Windows.Forms.Panel
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim rect As System.Drawing.Rectangle = New System.Drawing.Rectangle(10, 10, Me.Width - 20, Me.Height - 20)
Dim gradientBrush As System.Drawing.Drawing2D.LinearGradientBrush
gradientBrush = New System.Drawing.Drawing2D.LinearGradientBrush(rect, _
System.Drawing.Color.Gray, _
System.Drawing.Color.FloralWhite, _
System.Drawing.Drawing2D.LinearGradientMode.Vertic al)
e.Graphics.FillRectangle(gradientBrush, rect)
End Sub

Public Sub New()
Me.SetStyle(ControlStyles.ResizeRedraw, True)
End Sub
End Class

Ken
--------------------------
"Carlo, MCP" <ca******@gmail.com> wrote in message news:43*********************@news.tiscali.it...
Hello

I found an abnormal behaviour on LinearGradientBrush (or FillRectangle).
This code

Public Class PanelPanel
Inherits System.Windows.Forms.Panel
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim rect As System.Drawing.Rectangle = New System.Drawing.Rectangle(10, 10, Me.Width - 20, Me.Height - 20)
Dim gradientBrush As System.Drawing.Drawing2D.LinearGradientBrush
gradientBrush = New System.Drawing.Drawing2D.LinearGradientBrush(rect, _
System.Drawing.Color.Gray, _

System.Drawing.Color.FloralWhite, _

System.Drawing.Drawing2D.LinearGradientMode.Vertic al)
e.Graphics.FillRectangle(gradientBrush, rect)
End Sub
End Class

generates a control with an rectangle drawn inside.
The problem is that an unusual line (colored Color.FloralWhite) appears on the top edge of the rectangle. This line
should not be there.
If LinearGradientMode id other than Vertical the problem persists, but it is less visible (only a small colored pixel
is visible).

Please note that the anomaly appears only with some rectangle sizes. Example:
if rect={X=10,Y=10,Width=304,Height=208} 'equivalent to a Me.Size=New Size(324,228) - Anomaly visible
if rect={X=10,Y=10,Width=304,Height=216} 'Correct, anomaly not visible

Could someone PLEASE try to reproduce the problem (just copy code as is) and confirm that is an error and then reason
with me??

Thank you!.

Carlo

(MCP)


Nov 21 '05 #3
Hi,

I can see it with the screen magnifier.

Ken
-------------
"Carlo, MCP" <ca************@gmail.com> wrote in message
news:Oj**************@TK2MSFTNGP12.phx.gbl...
Hi Ken

on the original control (where the problem materialized the first time),
ResizeRedraw is correctly set to True. I've post a minimalist version of
the original control. However, I also tested this reduced version, and it
has the problem yet.
Please, note that I used a screen magnifier to identify the problem. I
believe it's very hard to see on a laptop screen.
Thank you for the help,
Carlo
"Ken Tucker [MVP]" <vb***@bellsouth.net> ha scritto nel messaggio
news:ut**************@TK2MSFTNGP12.phx.gbl...
Carlo,

I am not seeing the problem on my laptop. However I see you
did not set the resizeredraw style to the control. It is possible the
problem is caused by the control not completely redrawing itself.

Public Class PanelPanel
Inherits System.Windows.Forms.Panel
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
Dim rect As System.Drawing.Rectangle = New
System.Drawing.Rectangle(10, 10, Me.Width - 20, Me.Height - 20)
Dim gradientBrush As System.Drawing.Drawing2D.LinearGradientBrush
gradientBrush = New
System.Drawing.Drawing2D.LinearGradientBrush(rect, _
System.Drawing.Color.Gray,
_

System.Drawing.Color.FloralWhite, _

System.Drawing.Drawing2D.LinearGradientMode.Vertic al)
e.Graphics.FillRectangle(gradientBrush, rect)
End Sub

Public Sub New()
Me.SetStyle(ControlStyles.ResizeRedraw, True)
End Sub
End Class

Ken
--------------------------
"Carlo, MCP" <ca******@gmail.com> wrote in message
news:43*********************@news.tiscali.it...
Hello

I found an abnormal behaviour on LinearGradientBrush (or FillRectangle).
This code

Public Class PanelPanel
Inherits System.Windows.Forms.Panel
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
Dim rect As System.Drawing.Rectangle = New
System.Drawing.Rectangle(10, 10, Me.Width - 20, Me.Height - 20)
Dim gradientBrush As System.Drawing.Drawing2D.LinearGradientBrush
gradientBrush = New
System.Drawing.Drawing2D.LinearGradientBrush(rect, _
System.Drawing.Color.Gray,
_

System.Drawing.Color.FloralWhite, _

System.Drawing.Drawing2D.LinearGradientMode.Vertic al)
e.Graphics.FillRectangle(gradientBrush, rect)
End Sub
End Class

generates a control with an rectangle drawn inside.
The problem is that an unusual line (colored Color.FloralWhite) appears
on the top edge of the rectangle. This line should not be there.
If LinearGradientMode id other than Vertical the problem persists, but
it is less visible (only a small colored pixel is visible).

Please note that the anomaly appears only with some rectangle sizes.
Example:
if rect={X=10,Y=10,Width=304,Height=208} 'equivalent to a Me.Size=New
Size(324,228) - Anomaly visible
if rect={X=10,Y=10,Width=304,Height=216} 'Correct, anomaly not visible

Could someone PLEASE try to reproduce the problem (just copy code as is)
and confirm that is an error and then reason with me??

Thank you!.

Carlo

(MCP)



Nov 21 '05 #4
Ok. Reproducing the problem on your IDE means realizing that I not become crazy and this is a good step ahead!

Any ideas?

Carlo

"Ken Tucker [MVP]" <vb***@bellsouth.net> ha scritto nel messaggio news:uR**************@TK2MSFTNGP15.phx.gbl...
Hi,

I can see it with the screen magnifier.

Ken
-------------
"Carlo, MCP" <ca************@gmail.com> wrote in message news:Oj**************@TK2MSFTNGP12.phx.gbl...
Hi Ken

on the original control (where the problem materialized the first time), ResizeRedraw is correctly set to True. I've
post a minimalist version of the original control. However, I also tested this reduced version, and it has the
problem yet.
Please, note that I used a screen magnifier to identify the problem. I believe it's very hard to see on a laptop
screen.
Thank you for the help,
Carlo
"Ken Tucker [MVP]" <vb***@bellsouth.net> ha scritto nel messaggio news:ut**************@TK2MSFTNGP12.phx.gbl...
Carlo,

I am not seeing the problem on my laptop. However I see you did not set the resizeredraw style to the
control. It is possible the problem is caused by the control not completely redrawing itself.

Public Class PanelPanel
Inherits System.Windows.Forms.Panel
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim rect As System.Drawing.Rectangle = New System.Drawing.Rectangle(10, 10, Me.Width - 20, Me.Height - 20)
Dim gradientBrush As System.Drawing.Drawing2D.LinearGradientBrush
gradientBrush = New System.Drawing.Drawing2D.LinearGradientBrush(rect, _
System.Drawing.Color.Gray, _

System.Drawing.Color.FloralWhite, _

System.Drawing.Drawing2D.LinearGradientMode.Vertic al)
e.Graphics.FillRectangle(gradientBrush, rect)
End Sub

Public Sub New()
Me.SetStyle(ControlStyles.ResizeRedraw, True)
End Sub
End Class

Ken
--------------------------
"Carlo, MCP" <ca******@gmail.com> wrote in message news:43*********************@news.tiscali.it...
Hello

I found an abnormal behaviour on LinearGradientBrush (or FillRectangle).
This code

Public Class PanelPanel
Inherits System.Windows.Forms.Panel
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim rect As System.Drawing.Rectangle = New System.Drawing.Rectangle(10, 10, Me.Width - 20, Me.Height - 20)
Dim gradientBrush As System.Drawing.Drawing2D.LinearGradientBrush
gradientBrush = New System.Drawing.Drawing2D.LinearGradientBrush(rect, _
System.Drawing.Color.Gray, _

System.Drawing.Color.FloralWhite, _

System.Drawing.Drawing2D.LinearGradientMode.Vertic al)
e.Graphics.FillRectangle(gradientBrush, rect)
End Sub
End Class

generates a control with an rectangle drawn inside.
The problem is that an unusual line (colored Color.FloralWhite) appears on the top edge of the rectangle. This line
should not be there.
If LinearGradientMode id other than Vertical the problem persists, but it is less visible (only a small colored
pixel is visible).

Please note that the anomaly appears only with some rectangle sizes. Example:
if rect={X=10,Y=10,Width=304,Height=208} 'equivalent to a Me.Size=New Size(324,228) - Anomaly visible
if rect={X=10,Y=10,Width=304,Height=216} 'Correct, anomaly not visible

Could someone PLEASE try to reproduce the problem (just copy code as is) and confirm that is an error and then
reason with me??

Thank you!.

Carlo

(MCP)



Nov 21 '05 #5

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

Similar topics

117
7099
by: Peter Olcott | last post by:
www.halting-problem.com
28
5168
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
4
2128
by: steve bull | last post by:
I have created a UserControl and added it to my toolbox. It appears in the toolbox with the icon I created for it. The problem is that when I drag the control onto a form no code is generated. If I...
1
8208
by: Kenneth Siewers Møller | last post by:
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...
1
2446
by: DigitalMythic | last post by:
Just to set the scene, I have a listbox in an application which im working on. The List box will have owner drawn items in it when it has items. To start with the listbox is empty. What Im...
8
6480
by: _DD | last post by:
It seems that there is some odd interaction with LinearGradientBrush that depends on positioning. A simple test: --------- Rectangle Square = new Rectangle(.....); in Paint: ...
5
5123
by: cblackburn | last post by:
Hi all, I am in the situation where I have a GraphicsPath that I want to draw onto a System.Drawing.Graphics. I want the line to be coloured in a gradient from one end to the other. I have tried...
2
6557
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click...
7
8849
by: prpradip | last post by:
I have used ListView in my Form. I have set OwnerDraw = true. And I have the DrawItem Function as private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e) ...
0
7126
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,...
0
7005
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...
1
6891
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...
0
5465
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,...
0
3096
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...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1424
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 ...
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
293
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...

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.