vb.net - Smooth Curves when drawing ellipse -
i trying paint picture box circle , code:
private withevents pparent thumbcontrol sub new(byval pnparent thumbcontrol, byval path string, optional byval datastring string = "") pparent = pnparent strpath = path strdata = datastring me.sizemode = windows.forms.pictureboxsizemode.stretchimage me.size = new size(100, 100) dim gp new system.drawing.drawing2d.graphicspath() gp.addellipse(0, 0, me.width - 3, me.height - 3) dim rg new region(gp) me.region = rg end sub
paint method:
protected overrides sub onpaint(byval pe system.windows.forms.painteventargs) mybase.onpaint(pe) if not bselected if pparent.highlightmode = ihighlitemode.glassandforeground if bover dim rc new rectangle(0, 0, 100, 100) dim rc1 new rectangle(0, 0, 100, 50) pe.graphics.fillellipse(new solidbrush(color.fromargb(100, pparent.highlight.r, pparent.highlight.g, pparent.highlight.b)), rc) dim br new system.drawing.drawing2d.lineargradientbrush(rc1, color.fromargb(180, 255, 255, 255), color.fromargb(80, 255, 255, 255), drawing2d.smoothingmode.antialias) pe.graphics.fillellipse(br, rc1) end if elseif pparent.highlightmode = ihighlitemode.backgroundonly if bover dim rc1 new rectangle(-2, -2, 100, 100) dim br new system.drawing.drawing2d.lineargradientbrush(rc1, color.fromargb(180, 255, 255, 255), color.fromargb(80, 255, 255, 255), drawing2d.smoothingmode.antialias) pe.graphics.fillellipse(br, rc1) end if elseif pparent.highlightmode = ihighlitemode.glassonly if bover dim rc1 new rectangle(0, 0, 100, 100) dim br new system.drawing.drawing2d.lineargradientbrush(rc1, color.fromargb(180, 255, 255, 255), color.fromargb(80, 255, 255, 255), drawing2d.smoothingmode.antialias) pe.graphics.fillellipse(br, rc1) end if elseif pparent.highlightmode = ihighlitemode.glassandbackground if bover dim rc1 new rectangle(0, 0, 100, 100) dim br new system.drawing.drawing2d.lineargradientbrush(rc1, color.fromargb(180, 255, 255, 255), color.fromargb(80, 255, 255, 255), drawing2d.smoothingmode.antialias) pe.graphics.fillellipse(br, rc1) end if end if 'dim irc1 new rectangle(0, 0, 90, 100) 'pe.graphics.drawellipse(new pen(pparent.selectedcolor, 1), irc1) end if 'if bselected ' dim irc new rectangle(0, 0, 90, 90) ' pe.graphics.drawellipse(new pen(pparent.selectedcolor, 2), irc) 'end if end sub protected overrides sub onpaintbackground(byval pevent system.windows.forms.painteventargs) mybase.onpaintbackground(pevent) if not bselected if pparent.highlightmode = ihighlitemode.glassandbackground if bover 'dim rc new rectangle(0, 0, 180, 150) 'dim rc1 new rectangle(0, 0, 100, 80) 'pevent.graphics.fillellipse(new solidbrush(color.fromargb(100, pparent.highlight.r, pparent.highlight.g, pparent.highlight.b)), rc) 'dim br new system.drawing.drawing2d.lineargradientbrush(rc1, color.fromargb(180, 255, 255, 255), color.fromargb(80, 255, 255, 255), drawing2d.lineargradientmode.vertical) 'pevent.graphics.fillrectangle(br, rc1) end if elseif pparent.highlightmode = ihighlitemode.backgroundonly if bover dim rc new rectangle(0, 0, 90, 100) dim rc1 new rectangle(0, 0, 100, 80) pevent.graphics.fillellipse(new solidbrush(color.fromargb(100, pparent.highlight.r, pparent.highlight.g, pparent.highlight.b)), rc) dim br new system.drawing.drawing2d.lineargradientbrush(rc1, color.fromargb(180, 255, 255, 255), color.fromargb(80, 255, 255, 255), drawing2d.smoothingmode.antialias) end if end if end if end sub
i'm getting non-smoothed curve shown below:
how smooth rounded curve
before draw ellipse, set smoothingmode
, e.g.
dim grp graphics = picturebox1.creategraphics grp.smoothingmode = drawing2d.smoothingmode.antialias grp.fillellipse(brushes.blue, new rectangle(0, 0, 100, 100))
Comments
Post a Comment