.net - How to handle click event on shapes of System.Drawing -


i've been trying reach following result in winforms vb.net application

desired result

where each arc or circle in image clickable , clickable arc colored in pink.

i managed write following code

private sub form1_paint(byval sender system.object, byval e system.windows.forms.painteventargs) handles mybase.paint      'create pen objects      dim p new pen(color.green, 30)     dim p1 new pen(color.yellow, 30)     dim p2 new pen(color.red, 30)     dim p3 new pen(color.blue, 30)      'create rectangle objects      dim rt new rectangle(160, 150, 80, 100)     dim rt1 new rectangle(100, 150, 80, 100)     dim rt2 new rectangle(130, 120, 80, 100)     dim rt3 new rectangle(130, 180, 80, 100)      'draw arcs      e.graphics.drawarc(p, rt, 45, -90)     e.graphics.drawarc(p1, rt1, -135, -90)     e.graphics.drawarc(p2, rt2, -45, -90)     e.graphics.drawarc(p3, rt3, 135, -90)  end sub 

that resulted following output .

output

what didn't figure out :

1- how make border each of arcs.

2- how handle clicks on each of arcs.

is there better way way i'am trying pull off.

any appreciated .

special reza aghaei , used in solution following code

edit: improved answer

disposing graphics path , , making code neater

imports system.drawing.drawing2d public class surfaceselection  private sub surfaceselection_click(sender object, e mouseeventargs) handles me.click     dim hitsurface string = string.empty     if getpath(enumsclass.surfacesenum.l).isvisible(e.location)         hitsurface = "l"     elseif getpath(enumsclass.surfacesenum.m).isvisible(e.location)         hitsurface = "m"     elseif getpath(enumsclass.surfacesenum.f).isvisible(e.location)         hitsurface = "f"     elseif getpath(enumsclass.surfacesenum.d).isvisible(e.location)         hitsurface = "d"     else         hitsurface = "missed"     end if      msgbox(hitsurface)  end sub  private sub surfaceselection_paint(byval sender system.object, byval e system.windows.forms.painteventargs) handles mybase.paint      me.drawpath(enumsclass.surfacesenum.l, e)     me.drawpath(enumsclass.surfacesenum.m, e)     me.drawpath(enumsclass.surfacesenum.f, e)     me.drawpath(enumsclass.surfacesenum.d, e)  end sub  private sub drawpath(byval v_bytsurface enumsclass.surfacesenum, byval e system.windows.forms.painteventargs)     using p graphicspath = getpath(v_bytsurface)         e.graphics.fillpath(brushes.green, p)         e.graphics.drawpath(pens.black, p)     end using end sub  private function getpath(byval v_bytsurface enumsclass.surfacesenum) graphicspath     dim path new graphicspath     dim center = new point(100, 100)     dim innerr = 70     dim thickness = 20     dim startangle = getgraphicspathangle(v_bytsurface)     dim arclength = 70     dim outerr = innerr + thickness     dim outerrect = new rectangle(center.x - outerr, center.y - outerr, 2 * outerr, 2 * outerr)     dim innerrect = new rectangle(center.x - innerr, center.y - innerr, 2 * innerr, 2 * innerr)     path.addarc(outerrect, startangle, arclength)     path.addarc(innerrect, startangle + arclength, -arclength)     path.closefigure()     return path end function  private function getgraphicspathangle(byval v_bytsurface enumsclass.surfacesenum) integer     select case v_bytsurface         case enumsclass.surfacesenum.f             return 235         case enumsclass.surfacesenum.o             return 0         case enumsclass.surfacesenum.l             return 55         case enumsclass.surfacesenum.m             return 145         case enumsclass.surfacesenum.d             return 325         case enumsclass.surfacesenum.unspecified             return -1      end select  end function  end class  public class enumsclass     public enum surfacesenum byte         unspecified = 0         f = 1         o = 2         l = 3         m = 4         d = 5     end enum end class 

i used reza's answer in following stackoverflow question :

how draw circular progressbar pie using graphicspath in winform?

how can treat circle control after drawing it? - moving , selecting shapes

how drag , move shapes in c#


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -