1

私はかなり奇妙ですが再現性のある問題を抱えています。

MenuStripメソッドを使用して新しいモードレスフォームを開くことができるがありますForm.Show()

子フォームにもメニューストリップがあります。

子フォームのメニューストリップをクリックして開始すると、奇妙なことが起こります。次に、親フォームがフォアグラウンドに戻ってきて、こんにちはと言っています。それは本当に苦痛です。

この問題を防ぐ方法は?

このリンクをたどって私の問題を説明するスコセッシの映画zippyshare.com(3Mo)

ビデオで見ることができるように、親フォームは焦点を合わせていません、それは他の何かによって単に前面に出されます。

を修正して問題を修正することMenuStripに注意してください。ToolStrip

問題を再現するためのいくつかのコード:

public class DemoLostfocus : Form
{
    private void InitializeComponent()
    {
        this.menuStrip1 = new MenuStrip();
        this.fileToolStripMenuItem = new ToolStripMenuItem();
        this.openModelessFormToolStripMenuItem = new ToolStripMenuItem();
        this.menuStrip1.SuspendLayout();
        this.SuspendLayout();

        this.menuStrip1.Items.AddRange(new ToolStripItem[] {
        this.fileToolStripMenuItem});
        this.menuStrip1.Location = new System.Drawing.Point(0, 0);
        this.menuStrip1.Name = "menuStrip1";
        this.menuStrip1.Size = new System.Drawing.Size(284, 24);
        this.menuStrip1.TabIndex = 0;
        this.menuStrip1.Text = "menuStrip1";

        this.fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] {
        this.openModelessFormToolStripMenuItem});
        this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
        this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
        this.fileToolStripMenuItem.Text = "File";

        this.openModelessFormToolStripMenuItem.Name = "openModelessFormToolStripMenuItem";
        this.openModelessFormToolStripMenuItem.Size = new System.Drawing.Size(187, 22);
        this.openModelessFormToolStripMenuItem.Text = "Open Modeless Form";
        this.openModelessFormToolStripMenuItem.Click += new System.EventHandler(this.openModelessFormToolStripMenuItem_Click);

        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(284, 262);
        this.Controls.Add(this.menuStrip1);
        this.MainMenuStrip = this.menuStrip1;
        this.Name = "DemoLostfocus";
        this.Text = "DemoLostfocus";
        this.menuStrip1.ResumeLayout(false);
        this.menuStrip1.PerformLayout();
        this.ResumeLayout(false);
        this.PerformLayout();
    }

    private MenuStrip menuStrip1;
    private ToolStripMenuItem fileToolStripMenuItem;
    private ToolStripMenuItem openModelessFormToolStripMenuItem;

    public DemoLostfocus()
    {
        InitializeComponent();
    }

    private void openModelessFormToolStripMenuItem_Click(object sender, EventArgs e)
    {
        (new DemoLostfocus()).Show();
    }
}
4

1 に答える 1

4

これは、.NET 4.5 で導入された非常に厄介なバグです。KB 記事はこちらから入手できます。修正は現在、ホットフィックスとしてのみ利用可能です。うまくいけば、すぐにサービスの更新になります。説明をコピーして貼り付けます。

.NET Framework 4.5 ベースの Windows フォーム アプリケーションがあるとします。アプリケーションでメニュー項目をクリックして子ウィンドウを開くと、メニューおよび子ウィンドウとの対話が正しく動作しません。

たとえば、次のようなことが発生する可能性があります。

子ウィンドウでコンテキスト メニューを開くと、メイン ウィンドウがフォーカスされます。
ニーモニックを使用してメニュー項目にアクセスすることはできません。

この問題は、IMessageFilter インターフェイスが積極的にアンフックされているために発生します。したがって、.NET Framework 4.5 は、メニュー関連のウィンドウ メッセージをフィルター処理しません。


更新: この問題は、2013 年 1 月 8 日にリリースされた .NET 4.5 更新プログラムで修正されました。 KB 記事はこちらです。

于 2013-01-04T16:08:39.593 に答える