1 Attachment(s)
[RESOLVED] Random "notch" in my user-drawn control.
I have my control here, and when the control isn't drawing selected, it has a random notch in the border(as illustrated in the attached photo). It uses a graphics path which is generally used all around so nothing changes there. Other than the fact the control is marked "selected"(which only effects the colors).
Here's the code that generates my graphics path...
vbnet Code:
Private ReadOnly Property gp As GraphicsPath
Get
Dim output As New GraphicsPath
output.AddArc(New Rectangle(New Point(3, 2), New Size(20, 20)), 180, 80)
output.AddArc(New Rectangle(New Point(Me.Width - 23, 2), New Size(20, 20)), 270, 80)
output.AddLine(New Point(Me.Width - 2, Me.Height - 1), New Point(2, Me.Height - 1))
output.AddLine(New Point(2, Me.Height - 1), New Point(3, 10))
Return output
End Get
End Property
I'm hoping someone knows why this may be occurring.. It has happened before to but never was able to solve it.
Maybe if it was less noticeable I wouldn't care, but since the notch occurs in the middle of a dark gray section really makes it stick out like a sore thumb.
Re: Random "notch" in my user-drawn control.
Hi Daves, The first thing to try is to set the Graphics.SmoothingMode to HighQuality when you draw the path. Or are you already doing that? BB
Re: Random "notch" in my user-drawn control.
Quote:
Originally Posted by
boops boops
Hi Daves, The first thing to try is to set the Graphics.SmoothingMode to HighQuality when you draw the path. Or are you already doing that? BB
Yup... this is my code for painting.
vbnet Code:
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
e.Graphics.SmoothingMode = SmoothingMode.HighQuality
Using TabGradientBrush As New LinearGradientBrush(New Point(Me.Width \ 2, 0), New Point(Me.Width \ 2, Me.Height), Me.Skin.BaseColorHigh, Me.Skin.BaseColorLow)
e.Graphics.FillPath(TabGradientBrush, gp)
e.Graphics.DrawPath(New Pen(Color.FromArgb(255, 117, 117, 117), Me.BorderThickness), gp)
Using FontBrush As New SolidBrush(Me.Parent.ForeColor)
Using format As New StringFormat()
format.LineAlignment = StringAlignment.Center
format.Alignment = TextAlignment
format.FormatFlags = StringFormatFlags.NoWrap
e.Graphics.DrawString(Me.Text, Me.Font, FontBrush, New Rectangle(10,0,Me.Width-20,Me.Height), format)
End Using
End Using
End Using
If Image IsNot Nothing Then
e.Graphics.DrawImage(Image, Me.Width\2-ImageSize.Width\2, Me.Height\2-ImageSize.Height\2, ImageSize.Width, ImageSize.Height)
ShowClose = False
End If
If SelfClosing AndAlso Selected AndAlso ShowClose Then
Dim s As Size = My.Resources.close16.Size
Dim p As Point = New Point(Me.Width-(s.Width+((Me.Height-s.Height)\2)),Me.Height\2-s.Height\2)
e.Graphics.DrawImage(My.Resources.close16, p)
CloseBounds = New Rectangle(p,s)
End If
End Sub
Re: Random "notch" in my user-drawn control.
try painting your tabs at an int position... instead a single/double
Kris
Re: Random "notch" in my user-drawn control.
@daves: The lines are clearly being drawn with anti-aliasing, so I guess there was no need to mention the SmoothingMode. GDI+ is sometimes less than perfect at anti-aliasing lines which are almost exactly vertical or horizontal, although I have never noticed gaps like the ones you are getting.
I think you need to look at how you define the path. The length of the base line and the ends of the arcs do not quite match, so that the sides are very slightly inclined. You could adjust your arithmetic to give sides which are exactly vertical. It might help if you draw the straight sides explicitly, so that you can see where the mismatch is. Alternatively, if you actually want sides which are slightly sloping, make the slope a bit more pronounced.
@i00: GDI+ does its antialiasing with single precision so there is normally no visible difference when the SmoothingMode is set appropriately.
BB
EDIT: I had to pick pieces out of the code so that I could try it out. At first I thought I could reproduce the problem but later not. Maybe I made a mistake about which smoothing mode I was using. Now it's clear that the GraphicsPath is as intended and the outline of the tab is always smooth, even when the sides are at a slight angle.
It's a remote possibility, but I wonder whether the problem is caused by drawing the tab image after the outline. In theory, there could be some stray pixels getting in front of the outline. It would be more logical anyway to draw the image before the outline.
Re: Random "notch" in my user-drawn control.
You know what? I just realized this is only occurring when I'm developing on an XP system(computer at work). I just checked now and none of the tabs have that notch.. It must be it, right? Would this explain this notch?
Re: Random "notch" in my user-drawn control.
I'm working on XP. Sorry, no notch. But it I believe GDI+ uses hardware for antialiasing so it might depend on the graphics card. BB
Re: Random "notch" in my user-drawn control.
Yeah this computer really isn't that out of date per-say. We just were forced to use XP because of driver issues with our laser printer. I keep noticing though I get a lot of odd behavior when on this system I am now(The XP one). For example, when drawing arcs. Not sure why but sometimes it will have this straight line that shoots out where the curve begins. Must be something with the system. Maybe the framework is out-of-date. I highly doubt my moms upgraded this computer at all.
Thanks for your help!
Re: [RESOLVED] Random "notch" in my user-drawn control.
I actually found that my transparent key was 161,160,160. My guess isthat one pixel is that color. I use these for the aero glass effect and would explain why it's not drawing that one pixel.
Re: [RESOLVED] Random "notch" in my user-drawn control.
Quote:
Originally Posted by
DavesChillaxin
I actually found that my transparent key was 161,160,160. My guess isthat one pixel is that color. I use these for the aero glass effect and would explain why it's not drawing that one pixel.
Grrr:eek2:.
BB