473,398 Members | 2,393 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,398 software developers and data experts.

Right and Bottom Cut Off When Creating New Region From GraphicsPath

Don
When creating a new region for a control via a GraphicsPath object, it
appears the entire rightmost column of pixels and bottom most row of pixels
are not included in the region.

I will try to clarify with some ASCII art. Imagine a GraphicsPath
describing a 4x4 pixel square with rounded corners (X = pixel, _ = blank)

_ X X _
X X X X
X X X X
_ X X _

Creating a region from this GraphicsPath object will yield a region shaped
like this:

_ X X
X X X
X X X
Can anyone tell me what's going on with this? How can this be fixed?
- Don
Nov 21 '05 #1
4 1921
Post some code to reproduce this effect please.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Don" <un*****@oblivion.com> wrote in message
news:jbd0f.73110$tl2.4134@pd7tw3no...
When creating a new region for a control via a GraphicsPath object, it
appears the entire rightmost column of pixels and bottom most row of
pixels are not included in the region.

I will try to clarify with some ASCII art. Imagine a GraphicsPath
describing a 4x4 pixel square with rounded corners (X = pixel, _ = blank)

_ X X _
X X X X
X X X X
_ X X _

Creating a region from this GraphicsPath object will yield a region shaped
like this:

_ X X
X X X
X X X
Can anyone tell me what's going on with this? How can this be fixed?
- Don

Nov 21 '05 #2
Don
Try placing the following control class on a form in a new project:
--- CODE START ---
Imports System.Drawing.Drawing2D

Public Class ShapedPanel
Inherits System.Windows.Forms.Panel
Public Sub New()
MyBase.New()

ChangeControlRegion()

End Sub

Private Sub ChangeControlRegion()

Dim regionPath As GraphicsPath = GetControlShapePath()
Dim newRegion As System.Drawing.Region = New
System.Drawing.Region(regionPath)

Me.Region = newRegion

End Sub

Private Function GetControlShapePath() As GraphicsPath

Dim points(7) As Point
Dim types(7) As Byte
Dim result As GraphicsPath
Dim h As Integer = Me.Height
Dim w As Integer = Me.Width
Dim i As Integer

points(0) = New Point(1, 0)
points(1) = New Point(w - 1, 0)
points(2) = New Point(w, 1)
points(3) = New Point(w, h - 1)
points(4) = New Point(w - 1, h)
points(5) = New Point(1, h)
points(6) = New Point(0, h - 1)
points(7) = New Point(0, 1)

For i = 0 To 7
types(i) = CByte(PathPointType.Line)
Next i

result = New GraphicsPath(points, types)

Return result
End Function

End Class
--- CODE END ---
This panel should be drawn with a single pixel out of each of the four
corners. However, only the upper left corner pixel will be missing. Tests
I have done lead me to believe that the rightmost column and bottommost row
of pixels are not included in the region for some reason.

- Don
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:OD**************@TK2MSFTNGP15.phx.gbl...
Post some code to reproduce this effect please.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Nov 21 '05 #3
Don
Maybe add this method to the class instead of calling ChangeControlRegion
from the class constructor:

Protected Overrides Sub OnResize(ByVal eventargs As System.EventArgs)
MyBase.OnResize(eventargs)
ChangeControlRegion()
End Sub

- Don

"Don" <un*****@oblivion.com> wrote in message
news:TTe0f.74482$tl2.71150@pd7tw3no...
Try placing the following control class on a form in a new project:
--- CODE START ---
Imports System.Drawing.Drawing2D

Public Class ShapedPanel
Inherits System.Windows.Forms.Panel
Public Sub New()
MyBase.New()

ChangeControlRegion()

End Sub

Private Sub ChangeControlRegion()

Dim regionPath As GraphicsPath = GetControlShapePath()
Dim newRegion As System.Drawing.Region = New
System.Drawing.Region(regionPath)

Me.Region = newRegion

End Sub

Private Function GetControlShapePath() As GraphicsPath

Dim points(7) As Point
Dim types(7) As Byte
Dim result As GraphicsPath
Dim h As Integer = Me.Height
Dim w As Integer = Me.Width
Dim i As Integer

points(0) = New Point(1, 0)
points(1) = New Point(w - 1, 0)
points(2) = New Point(w, 1)
points(3) = New Point(w, h - 1)
points(4) = New Point(w - 1, h)
points(5) = New Point(1, h)
points(6) = New Point(0, h - 1)
points(7) = New Point(0, 1)

For i = 0 To 7
types(i) = CByte(PathPointType.Line)
Next i

result = New GraphicsPath(points, types)

Return result
End Function

End Class
--- CODE END ---
This panel should be drawn with a single pixel out of each of the four
corners. However, only the upper left corner pixel will be missing.
Tests I have done lead me to believe that the rightmost column and
bottommost row of pixels are not included in the region for some reason.

- Don
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:OD**************@TK2MSFTNGP15.phx.gbl...
Post some code to reproduce this effect please.

--
Bob Powell [MVP]
Visual C#, System.Drawing


Nov 21 '05 #4
I'm definitely seeing a result that I didn't expect. Even though I've made a
few changes from your original code.

I'll investigate this further and If I can pin down an real bug I'll
escalate it to the GDI+ team at MS. As to a workaround I would suggest in
the short-term adding a fudge-factor to make it look the way you want it to.

Thanks.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Don" <un*****@oblivion.com> wrote in message
news:D1f0f.64231$1i.56022@pd7tw2no...
Maybe add this method to the class instead of calling ChangeControlRegion
from the class constructor:

Protected Overrides Sub OnResize(ByVal eventargs As System.EventArgs)
MyBase.OnResize(eventargs)
ChangeControlRegion()
End Sub

- Don

"Don" <un*****@oblivion.com> wrote in message
news:TTe0f.74482$tl2.71150@pd7tw3no...
Try placing the following control class on a form in a new project:
--- CODE START ---
Imports System.Drawing.Drawing2D

Public Class ShapedPanel
Inherits System.Windows.Forms.Panel
Public Sub New()
MyBase.New()

ChangeControlRegion()

End Sub

Private Sub ChangeControlRegion()

Dim regionPath As GraphicsPath = GetControlShapePath()
Dim newRegion As System.Drawing.Region = New
System.Drawing.Region(regionPath)

Me.Region = newRegion

End Sub

Private Function GetControlShapePath() As GraphicsPath

Dim points(7) As Point
Dim types(7) As Byte
Dim result As GraphicsPath
Dim h As Integer = Me.Height
Dim w As Integer = Me.Width
Dim i As Integer

points(0) = New Point(1, 0)
points(1) = New Point(w - 1, 0)
points(2) = New Point(w, 1)
points(3) = New Point(w, h - 1)
points(4) = New Point(w - 1, h)
points(5) = New Point(1, h)
points(6) = New Point(0, h - 1)
points(7) = New Point(0, 1)

For i = 0 To 7
types(i) = CByte(PathPointType.Line)
Next i

result = New GraphicsPath(points, types)

Return result
End Function

End Class
--- CODE END ---
This panel should be drawn with a single pixel out of each of the four
corners. However, only the upper left corner pixel will be missing.
Tests I have done lead me to believe that the rightmost column and
bottommost row of pixels are not included in the region for some reason.

- Don
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:OD**************@TK2MSFTNGP15.phx.gbl...
Post some code to reproduce this effect please.

--
Bob Powell [MVP]
Visual C#, System.Drawing



Nov 21 '05 #5

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

Similar topics

11
by: Altramagnus | last post by:
I have a complicated Region object, which I need to draw the outline, but not fill How can I convert the Region object to GraphicsPath object? or How can I draw the outline of the Region object?
1
by: Brian | last post by:
Greetings all, I wrote a message regarding hit-lines here a couple of days back saying: "Anyone got links to some examples of using Region and/or Region.Intersect in a graphical / gaming...
15
by: Jigar Patel | last post by:
Hello, I want to create non-rectengular/region form in VB.NET. Please Help Me.............. Jigar Patel
3
by: Arturo Toledo | last post by:
Ok.. I need to create a button. Not a normal one. I need one that has a STAR shape. I need it to be yellow and with a face. When I rollover this button I need the face to smile and to have...
13
by: iwdu15 | last post by:
hi, i was wondering how i could create my own buttons, like with unique shapes and such. i kno theres a way but i dont kno how...
1
by: PJ6 | last post by:
I've Googled this but come up short... I have a non-rectangular region that contains a moveable rectangle. I want to restrict the rectangle's movement to have it always fully contained in this...
2
by: Mark Denardo | last post by:
Hi, I need some expert GDI+ person to help me with my RoundOffImage Function: What I'm trying to do is take in an image, crop off the edges around an ellipse region I set up, and then return the...
1
by: renu | last post by:
Hello, I have drawn polygon on window. And I want to check wheather given point is in that polygon region or not? How shold I find that? I have created object of class region GraphicsPath path...
0
by: slg | last post by:
I have a round region how can i draw a border for it. Is there a function to get the border points in a region.? i have code something like below. System.Drawing.Drawing2D.GraphicsPath...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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,...
0
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...
0
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,...

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.