There is a class Unit: Label, instances of which are displayed on the Panel. It is necessary to make it so that you can add LineShape between elements that act as senders in MouseLeftButtonDown and MouseLeftButtonUp events . The catch is that you can only pass static methods to an EventHandler for an object, and you cannot add LineShape to a form from a static method . What's my mistake?

Z. Y. Do not judge strictly, in the WinForms I got the day before yesterday, and so far I do not focus on them at all.

UPD 1

static void MouseUp(object sender, MouseEventArgs e) { Unit from = start; // sender as Unit в MouseDown Unit to = sender as Unit; // проверки на null пока уберу Panel control = to.Parent as Panel; // как-то получить родителя start = null; LineShape line = new LineShape(from.Location.X, from.Location.Y, to.Location.X, to.Location.Y); control.Controls.Add(line); } 

here in the last line the error Argument "1": type conversion from "Microsoft.VisualBasic.PowerPacks.LineShape" to "System.Windows.Forms.Control" is impossible.

    1 answer 1

    Only static methods can be passed to an EventHandler for an object.

    This is doubtful. Generally speaking, the handler may be a non-static object method.

    type conversion from "Microsoft.VisualBasic.PowerPacks.LineShape" to "System.Windows.Forms.Control" is not possible

    Actually, it speaks for itself. LineShape not a WinForms control.

    • What can replace LineShape? Or how to get around the situation? - Raccoon
    • In WinForms, there is no such control; you will have to draw with the help of the Graphics class. As an option - write or find a ready control for the line. - eigenein
    • Ready control for the line. РЖАЧ ..... Can add the panel with filling ?????? Well, in general, you need 1. CustomControl, 2. Paint () {e.Graphics.DrawLine (); ....} 3. It is desirable to set the attributes SetStyle (). 4. For trimming unwanted parts, look towards UserControl.Region. Good luck - semenvx27