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

标签 winforms visual-studio-2010 wizard visual-studio-templates

我完全遵循这一点:

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

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

为了子孙后代,这是我的代码:

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

 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 窗体(做网络应用程序)没有太多经验,但我正在遵循 MSDN 上的指示,而且它非常清晰。有什么建议么?其他人可以让它工作吗?

最佳答案

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

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

为什么 MSDN 上的文档中没有这一点,这让我很困惑。

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

相关文章:

java - 适用于 Eclipse 的 Google 插件无法正常工作

c# - 如何使用 objectdatasource 将枚举绑定(bind)到 winform 组合框

java - 如何删除 swt/jface 中的向导容器标题栏

c# - 打印出整个数据 GridView 的简单方法

c# - 如何确定全局键盘钩子(Hook)是否已断开连接?

c# - 如何添加对 DataGridViewAutoFilter 的引用?

visual-studio-2010 - 如何在内置的 Visual Studio 调试器服务器中使用 Web.debug.config?

Jenkins 安装向导未加载

c# - 用于在文本文件中搜索确切字符串并在找到失败时执行操作的代码

c# - 在连接字符串中设置 SQL Server 名称不起作用