简体   繁体   中英

windowsforms C# Control - Move and resize a control in execution time

I'm trying creat a groupbox that draw a line whith two point and i created a method and i use two events Dragenter and Dragover, but is generated an error:

CS7036 There is no argument given that corresponds to the required formal parameter 'sender' of 'Form1.DrawLine(object, PaintEventArgs)'

This error appears when i try invoke the method DrawLine() at the final of event DragOver:

Anybody help me? The code is here:

   private void DrawLine(object sender, PaintEventArgs e)
    {
        Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255), 8);
        pen.StartCap = LineCap.ArrowAnchor;
        pen.EndCap = LineCap.RoundAnchor;
        e.Graphics.DrawLine(pen, StPoint, EnPoint);
        //groupBox1.Refresh();
    }

    private void groupBox1_DragEnter(object sender, DragEventArgs e)
    {
        StPoint = new Point(e.X, e.Y);

    }

    private void groupBox1_DragOver(object sender, DragEventArgs e)
    {
        EnPoint = new Point(e.X, e.Y);

        this.DrawLine();
    }

Well given your error,

CS7036 There is no argument given that corresponds to the required formal parameter 'sender' of 'Form1.DrawLine(object, PaintEventArgs)'

it looks like you forgot to pass the arguments to the DrawLine call in your groupBox1_DragOver method.

You see, the DrawLine method was declared with two parameters: sender of type object and e of type PaintEventArgs .

private void DrawLine(object sender, PaintEventArgs e)

You need to fill those in in places where you call the method.

It is questionable, however, if this method should even have those parameters since it doesn't use them anyway and it is a burden to reuse it. Either extract the body to a parameterless method or use lambda to bind to the event and ignore the arguments (eg OnSomeEvent += (s, a) => DrawLine() ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM