【问题标题】:How can I call this event from other function?如何从其他函数调用此事件?
【发布时间】:2018-03-03 17:10:42
【问题描述】:

我怎样才能通过类似按钮单击功能或其他方式调用此事件private void panel1_Paint(object sender, PaintEventArgs e){.....}

我已经尝试过panel1.Paint += new PaintEventHandler(panel1_Paint); 和其他几个,但它们似乎没有用。

【问题讨论】:

    标签: c# function events call


    【解决方案1】:

    试试这个:

    private void Button1_Click(object sender, EventArgs e){
        panel1.Invalidate();
    }
    

    Invalidate() 方法强制控件重绘。

    【讨论】:

    • 如果我使用 Invalidate() 方法它有点清除我的面板。
    • 我使用了刷新功能,现在它可以工作了 :) 我不知道为什么但它可以工作。
    • 很好,祝你编码愉快:)
    【解决方案2】:

    您需要将其用作简单功能: ...your_code...; panel1_Paint(null, null); ...your_code...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-22
      • 1970-01-01
      • 2020-09-05
      • 1970-01-01
      • 1970-01-01
      • 2019-11-27
      • 1970-01-01
      相关资源
      最近更新 更多