2

私はこれを正確にフォローしています:

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 フォーム (Web アプリケーション) の経験はあまりありませんが、MSDN の指示に従っており、かなり明確です。助言がありますか?他の誰かがこれを機能させることができますか?

4

2 に答える 2

3

わかりました。フォームのコンストラクターに手動でイベント ハンドラーを追加する必要がありました。

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

これが MSDN のドキュメントにない理由は、私の頭を悩ませます。

于 2012-02-02T19:54:38.937 に答える
0

WinForms デザイナー モードを使用してツールボックスからボタンをドラッグし、デザイナー ビューでボタンをダブルクリックすると、イベント ハンドラーが追加され、その Click メソッドがスタブ化されます。参考までに。

于 2014-03-12T17:15:06.547 に答える