gpt4 book ai didi

winforms - 自定义项目模板向导按钮单击不触发?

转载 作者:行者123 更新时间:2023-12-04 05:59:21 30 4
gpt4 key购买 nike

我完全按照这个:

http://msdn.microsoft.com/en-us/library/ms185301.aspx

但无法让它工作。当我尝试添加新项目时会出现该表单,但是当我输入文本并单击按钮时,没有任何 react 。

为了后代,这里是我的代码:

扩展 IWizard 的 Wizard 类中的非空方法

 public void RunStarted(object automationObject,
Dictionary<string, string> replacementsDictionary,
WizardRunKind runKind, object[] customParams)
{
try
{
// Display a form to the user. The form collects
// input for the custom message.
inputForm = new UserInputForm();
inputForm.ShowDialog();

customMessage = inputForm.get_CustomMessage();

// Add custom parameters.
replacementsDictionary.Add("$custommessage$",
customMessage);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

// This method is only called for item templates,
// not for project templates.
public bool ShouldAddProjectItem(string filePath)
{
return true;
}

用户输入表单代码:
 public partial class UserInputForm : Form
{
private string customMessage;

public UserInputForm()
{
InitializeComponent();
}

public string get_CustomMessage()
{
return customMessage;
}

private void button1_Click(object sender, EventArgs e)
{
customMessage = textBox1.Text;

this.Dispose();
}

}

该按钮确实被命名为按钮 1:
 this.button1.Location = new System.Drawing.Point(200, 180);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(100, 40);
this.button1.TabIndex = 0;
this.button1.Text = "Click Me";
this.button1.UseVisualStyleBackColor = true;

所以我对 Windows 窗体(做 Web 应用程序)没有太多经验,但我正在遵循 MSDN 上的说明,而且非常清楚。有什么建议?其他人可以让这个工作吗?

最佳答案

好吧,我想通了。我必须手动在表单的构造函数中添加事件处理程序:

 public UserInputForm()
{
InitializeComponent();
button1.Click += button1_Click;
}

为什么这不在 MSDN 上的文档中让我难以置信。

关于winforms - 自定义项目模板向导按钮单击不触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9115522/

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