I'm creating a Graphical Editor. I'm able to draw lines and rectangles but now I want to move them, so I am trying to add the MouseMove event now. I tried the following things:
rectangle.MouseMove += shape_MouseMove;
Error:
'System.Drawing.Rectangle' does not contain a definition for 'MouseDown' and no extension method 'MouseDown' accepting a first argument of type 'System.Drawing.Rectangle' could be found (are you missing a using directive or an assembly reference?)
rectangle += shape_MouseMove;
Errors:
Error 2 Cannot convert method group 'shape_MouseMove' to non-delegate type 'System.Drawing.Rectangle'. Did you intend to invoke the method
Error 1 Operator '+=' cannot be applied to operands of type 'System.Drawing.Rectangle' and 'method group'
Code:
private void shape_MouseMove(object sender, MouseEventArgs e)
{
}
private void panel_MouseUp(object sender, MouseEventArgs e)
{
draw = false;
xe = e.X;
ye = e.Y;
Item item;
Enum.TryParse<Item>(menuComboBoxShape.ComboBox.SelectedValue.ToString(), out item);
switch (item)
{
case Item.Pencil:
using (Graphics g = panel.CreateGraphics())
using (var pen = new Pen(System.Drawing.Color.Black)) //Create the pen used to draw the line (using statement makes sure the pen is disposed)
{
g.DrawLine(pen, new Point(x, y), new Point(xe, ye));
}
break;
case Item.Rectangle:
Rectangle rectangle = new Rectangle(x, y,xe-x, ye-y);
rectangle += shape_MouseMove; //Error here
using (Graphics g = panel.CreateGraphics())
using (var pen = new Pen(System.Drawing.Color.Black)) //Create the pen used to draw the rectangle (using statement makes sure the pen is disposed)
{
g.DrawRectangle(pen,rectangle);
}
break;
default:
break;
}
}
How can I add the MouseMove
event to the Rectangle
?