单击“自定义项模板向导”按钮未触发?

发布于 2025-01-01 09:23:33 字数 2007 浏览 2 评论 0原文

我完全遵循这一点:

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

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

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

扩展 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 Forms(做网络应用程序),但我遵循MSDN上的指示,它非常清晰。有什么建议吗?其他人可以让它发挥作用吗?

I am following this exactly:

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

but can't get it to work. The form appears when I try and add my new item, but when I input text and click the button, nothing happens.

For posterity's sake here is my code:

The non-empty methods in the Wizard class which extends 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;
    }

The user input form code:

 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();
    }

}

And the button is indeed named button 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;

So I don't have much experience with Windows Forms (do web apps), but I am following the directions on MSDN and it's pretty clear cut. Any suggestions? Can anyone else get this to work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扮仙女 2025-01-08 09:23:33

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

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

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

Okay I figured it out. I had to add the event handler in the form's constructor manually:

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

Why this isn't in the documentation on MSDN boggles my mind.

伴我心暖 2025-01-08 09:23:33

如果您使用 WinForms 设计器模式从工具箱中拖动按钮,然后在设计器视图中双击该按钮,它将添加事件处理程序并为您存根该 Click 方法。仅供参考。

If you use the WinForms designer mode to drag your button from the Toolbox, and then double-clicked the button in the designer view, it would have added the event handler and stubbed that Click method for you. Just FYI.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文