简体   繁体   English

windowsforms C#控件-在执行时移动控件并调整其大小

[英]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: 我正在尝试创建一个绘制两条线的分组框,并创建了一个方法,并且使用了两个事件Dragenter和Dragover,但生成了一个错误:

CS7036 There is no argument given that corresponds to the required formal parameter 'sender' of 'Form1.DrawLine(object, PaintEventArgs)' CS7036没有给出与“ Form1.DrawLine(object,PaintEventArgs)”的所需形式参数“ sender”相对应的参数

This error appears when i try invoke the method DrawLine() at the final of event DragOver: 当我尝试在事件DragOver的最后调用方法DrawLine()时,会出现此错误:

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)' CS7036没有给出与“ Form1.DrawLine(object,PaintEventArgs)”的所需形式参数“ sender”相对应的参数

it looks like you forgot to pass the arguments to the DrawLine call in your groupBox1_DragOver method. 似乎您忘记了将参数传递给groupBox1_DragOver方法中的DrawLine调用。

You see, the DrawLine method was declared with two parameters: sender of type object and e of type PaintEventArgs . 您会看到,使用两个参数声明了DrawLine方法: object类型的senderPaintEventArgs类型的e

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() ). 将主体提取为无参数方法,或者使用lambda绑定到事件并忽略参数(例如OnSomeEvent += (s, a) => DrawLine() )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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