473,776 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1945
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*****@oblivi on.com> wrote in message
news:jbd0f.7311 0$tl2.4134@pd7t w3no...
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()

ChangeControlRe gion()

End Sub

Private Sub ChangeControlRe gion()

Dim regionPath As GraphicsPath = GetControlShape Path()
Dim newRegion As System.Drawing. Region = New
System.Drawing. Region(regionPa th)

Me.Region = newRegion

End Sub

Private Function GetControlShape Path() 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(PathPoint Type.Line)
Next i

result = New GraphicsPath(po ints, 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@_spamkille r_bobpowell.net > wrote in message
news:OD******** ******@TK2MSFTN GP15.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 ChangeControlRe gion
from the class constructor:

Protected Overrides Sub OnResize(ByVal eventargs As System.EventArg s)
MyBase.OnResize (eventargs)
ChangeControlRe gion()
End Sub

- Don

"Don" <un*****@oblivi on.com> wrote in message
news:TTe0f.7448 2$tl2.71150@pd7 tw3no...
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()

ChangeControlRe gion()

End Sub

Private Sub ChangeControlRe gion()

Dim regionPath As GraphicsPath = GetControlShape Path()
Dim newRegion As System.Drawing. Region = New
System.Drawing. Region(regionPa th)

Me.Region = newRegion

End Sub

Private Function GetControlShape Path() 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(PathPoint Type.Line)
Next i

result = New GraphicsPath(po ints, 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@_spamkille r_bobpowell.net > wrote in message
news:OD******** ******@TK2MSFTN GP15.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*****@oblivi on.com> wrote in message
news:D1f0f.6423 1$1i.56022@pd7t w2no...
Maybe add this method to the class instead of calling ChangeControlRe gion
from the class constructor:

Protected Overrides Sub OnResize(ByVal eventargs As System.EventArg s)
MyBase.OnResize (eventargs)
ChangeControlRe gion()
End Sub

- Don

"Don" <un*****@oblivi on.com> wrote in message
news:TTe0f.7448 2$tl2.71150@pd7 tw3no...
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()

ChangeControlRe gion()

End Sub

Private Sub ChangeControlRe gion()

Dim regionPath As GraphicsPath = GetControlShape Path()
Dim newRegion As System.Drawing. Region = New
System.Drawing. Region(regionPa th)

Me.Region = newRegion

End Sub

Private Function GetControlShape Path() 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(PathPoint Type.Line)
Next i

result = New GraphicsPath(po ints, 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@_spamkille r_bobpowell.net > wrote in message
news:OD******** ******@TK2MSFTN GP15.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
7652
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
2447
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 enviroment? Am investigating into using it for hit-lines in my game."
15
7230
by: Jigar Patel | last post by:
Hello, I want to create non-rectengular/region form in VB.NET. Please Help Me.............. Jigar Patel
3
2788
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 sparkles comming out of the button. When I click this button I need it to shake and have the face scream (no sound required)... This button will be located over a composite background so I would like to have transparent areas where my button is not...
13
1221
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
1320
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 region. Would seem pretty simple to do this with a region's IsVisible function, but no, IsVisible returns true if any portion of the rectangle is visible. I know I'll eventually get this just by messing around but don't want to unnecesssarily...
2
2518
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 cropped image from the function. I sort of have this working, but not thoroughly. If I take the output image of this function and draw it on my form it shows the clipped image as transparent as I am wanting it. But if I take that image and...
1
8435
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 = new GraphicsPath(); path.AddPolygon(pts); //////// Some points I have passed Region rgn = new Region(path); RegionData rgnDta = rgn.GetRegionData();
0
978
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 outerCircle = new System.Drawing.Drawing2D.GraphicsPath(); Region = new System.Drawing.Region(outerCircle);
0
9628
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
9464
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
10289
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
10120
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
10061
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
8952
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
6722
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
5367
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...
1
4031
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

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.