-
Graphics object again
When using the graphics object i'm using the SetClip command. This works
fine and drawing is clipped at the correct area. But if I use the
ControlPaint object the clipping gets ignored. Does anyone know whats going
on and is there a way to solve this.
Thanks in advance.
--
Michael Culley
www.vbdotcom.com
-
Re: Graphics object again
Michael,
>When using the graphics object i'm using the SetClip command. This works
>fine and drawing is clipped at the correct area. But if I use the
>ControlPaint object the clipping gets ignored.
Can you post very simplified code demonstrating the problem?
--
Turn on, tune in, download.
zane@mvps.org
-
Re: Graphics object again
> Can you post very simplified code demonstrating the problem?
No problem. Just paste this code into a blank form. The FillRectangle and
the DrawEllipse are clipped correctly but the drawborder is not.
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
e.Graphics.SetClip(New Rectangle(50, 50, 100, 100))
e.Graphics.FillRectangle(Brushes.Red, Me.ClientRectangle)
e.Graphics.DrawEllipse(Pens.Black, 100, 100, 170, 170)
ControlPaint.DrawBorder3D(e.Graphics, 120, 50, 50, 20,
Border3DStyle.Raised, Border3DSide.All Or Border3DSide.Middle)
End Sub
--
Michael Culley
www.vbdotcom.com
"Zane Thomas" <zane@mabry.com> wrote in message
news:3cdb57a9.238739671@news.devx.com...
> Michael,
>
> >When using the graphics object i'm using the SetClip command. This works
> >fine and drawing is clipped at the correct area. But if I use the
> >ControlPaint object the clipping gets ignored.
>
> Can you post very simplified code demonstrating the problem?
>
>
> --
> Turn on, tune in, download.
> zane@mvps.org
-
Re: Graphics object again
"Michael Culley" <mike@vbdotcom.com> wrote:
> ControlPaint.DrawBorder3D(e.Graphics, 120, 50, 50, 20,
>Border3DStyle.Raised, Border3DSide.All Or Border3DSide.Middle)
Interesting, this works:
e.Graphics.FillRectangle(Brushes.LightGray, r);
ControlPaint.DrawBorder(e.Graphics, r, Color.LightGray,
ButtonBorderStyle.Outset);
DrawBorder uses Graphics.Line internally while DrawBorder3D uses the GDI
API DrawEdge, I assume the latter does not respect clipping for some
reason.
--
Turn on, tune in, download.
zane@mvps.org
-
Re: Graphics object again
> DrawBorder uses Graphics.Line internally while DrawBorder3D uses the GDI
> API DrawEdge, I assume the latter does not respect clipping for some
> reason.
I thought it might be how the drawedge api works underneath, so I tried it
in vb6 but it does work correctly. Maybe the DrawBorder3D method draws on a
different hDC or something (hence my other question in this group).
I've included the vb6 code just for the heck of it (notice the number of
lines required to do the same thing in vb6)
--
Michael Culley
www.vbdotcom.com
Option Explicit
Private Const BF_TOP = &H2
Private Const BF_RIGHT = &H4
Private Const BF_MIDDLE = &H800 ' Fill in the middle.
Private Const BF_LEFT = &H1
Private Const BF_BOTTOM = &H8
Private Const BDR_RAISEDINNER = &H4
Private Const BDR_RAISEDOUTER = &H1
Private Const EDGE_RAISED = (BDR_RAISEDOUTER Or BDR_RAISEDINNER)
Private Const BF_RECT = (BF_LEFT Or BF_TOP Or BF_RIGHT Or BF_BOTTOM)
Private Type Rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function IntersectClipRect Lib "gdi32" (ByVal hdc As Long,
ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As
Long
Private Declare Function DrawEdge Lib "user32" (ByVal hdc As Long, qrc As
Rect, ByVal edge As Long, ByVal grfFlags As Long) As Long
Private Declare Function SelectClipRgn Lib "gdi32" (ByVal hdc As Long, ByVal
hRgn As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As
Rect, ByVal hBrush As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As
Long) As Long
Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal X1 As
Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Sub Form_Paint()
IntersectClipRect Me.hdc, 50, 50, 150, 150
Dim Rect2 As Rect
Rect2.Right = Me.ScaleWidth / Screen.TwipsPerPixelX
Rect2.Bottom = Me.ScaleHeight / Screen.TwipsPerPixelY
FillRect Me.hdc, Rect2, CreateSolidBrush(255)
Ellipse Me.hdc, 100, 100, 270, 270
Dim Rect As Rect
Rect.Left = 120
Rect.Top = 50
Rect.Right = 170
Rect.Bottom = 70
DrawEdge Me.hdc, Rect, EDGE_RAISED, BF_RECT Or BF_MIDDLE
SelectClipRgn Me.hdc, 0
End Sub
-
Re: Graphics object again
Something else I noticed is that DrawBorder3D will honor a clipping region
that dot net itself sets up but not one I do. In the paint event the
clipping region has already been set but do net and DrawBorder3D will work
correctly with this clipping region, but if I make the region smaller then
it ignores it.
--
Michael Culley
www.vbdotcom.com
"Zane Thomas" <zane@mabry.com> wrote in message
news:3ce0cb8c.268405843@news.devx.com...
> "Michael Culley" <mike@vbdotcom.com> wrote:
>
> > ControlPaint.DrawBorder3D(e.Graphics, 120, 50, 50, 20,
> >Border3DStyle.Raised, Border3DSide.All Or Border3DSide.Middle)
>
> Interesting, this works:
>
> e.Graphics.FillRectangle(Brushes.LightGray, r);
> ControlPaint.DrawBorder(e.Graphics, r, Color.LightGray,
> ButtonBorderStyle.Outset);
>
>
> DrawBorder uses Graphics.Line internally while DrawBorder3D uses the GDI
> API DrawEdge, I assume the latter does not respect clipping for some
> reason.
>
>
> --
> Turn on, tune in, download.
> zane@mvps.org
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks