gpt4 book ai didi

c# - 我对 button.Click 事件有一些问题

转载 作者:太空宇宙 更新时间:2023-11-03 19:20:53 30 4
gpt4 key购买 nike

我有一个函数private void change (),我想在按下按钮时运行它。我有 Button schimbare = new Button();,如果我按下,运行函数。

我尝试了 schimbare.Click += change(); 但没有用。什么是好的命令?

这是代码:

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace Programarii
{
class InputBoxOptiuni
{
static TextBox textBox1 = new TextBox();

/// <summary>
/// Displays a dialog with a prompt and textbox where the user can enter information
/// </summary>
/// <param name="title">Dialog title</param>
/// <param name="promptText">Dialog prompt</param>
/// <param name="value">Sets the initial value and returns the result</param>
/// <returns>Dialog result</returns>
public static DialogResult Show(string title, string promptText, string informati, string mesaj, ref int ora, ref int minut30, ref int minut15, ref int douaore, ref int minut10, ref int minut5, ref int pornire2, ref int anuntare2, ref int cuparola, ref string parola, ref string email, ref int expirare, ref int cateminute, ref int vl, ref int culimba, string scurtaturi, string scurtaturi2, string format, ref int tipformat)
{

Button schimbare = new Button();

schimbare.Click += change;

}

private void change(object sender, EventArgs e)
{

}
}
}

对于所有回答我的问题,tnx。

我尝试:

private void change(object sender, EventArgs e) and schimbare.Click += change; 

但是不工作。我尝试使用 schimbare.Click += (s,e)=> {//your code }; 并且有效!

最佳答案

你的方法签名应该是这样的:

void change(object sender, EventArgs e)

并写成 schimbare.Click += change;

你也可以使用这种语法

schimbare.Click += (s,e)=>
{
//your code
};

关于c# - 我对 button.Click 事件有一些问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12318911/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com