c# - How to draw a circle on Canvas? -


i'm newbie in wpf , doing mypaint application. when draw circle or square in canvas, follow mouse when move along oy pivot. have no idea solve problem. here . reading.

point p1, p2;         point currclick;         //int = 0;         //private bool flag = true;         rectangle myline;          solidcolorbrush scb = new solidcolorbrush(colors.black); private void mycanvas_mouseleftbuttondown(object sender, mousebuttoneventargs e)         {             p1 = e.getposition(mycanvas);             myline = new rectangle();              myline.stroke = scb;             myline.strokethickness = 1;             doublecollection mydash = new doublecollection { 5, 3 };             myline.strokedasharray = mydash;             canvas.setleft(myline, p1.x);             canvas.settop(myline, p1.y);             //myline.fill = scb;               mycanvas.children.add(myline);          } private void mycanvas_mousemove_1(object sender, system.windows.input.mouseeventargs e) {             if (e.leftbutton == mousebuttonstate.released)             {                 return;             } else             {                 myline.width = math.max(p2.x, p1.x) - math.min(p2.x, p1.x);                 myline.height = myline.width;                 canvas.setleft(myline, math.min(p1.x, p2.x));                 canvas.settop(myline, math.min(p1.y, p2.y));             }         } 

change mouse move-event this:

 private void mycanvas_mousemove_1(object sender, system.windows.input.mouseeventargs e)     {         p2 = e.getposition(mycanvas);         if (e.leftbutton == mousebuttonstate.pressed)         {             if (p1.x < p2.x)                 canvas.setleft(myline, p1.x);  else canvas.setleft(myline, p2.x);             if (p1.y < p2.y)                 canvas.settop(myline, p1.y);  else canvas.settop(myline, p2.y);              myline.width = math.max(p2.x, p1.x) - math.min(p2.x, p1.x);             myline.height = math.max(p2.y, p1.y) - math.min(p2.y, p1.y);        }     } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -