2011-10-12 16 views
2

私のアプリケーションでは、特定のダイアログがMac OS X Document modal Sheetの機能と同様に動作するようになってきています。アプリケーション全体ではなく、親コントロール/ダイアログだけがダイアログになります(http://en.wikipedia.org/wiki/Window_dialog参照)。.NETにはMac OS Xドキュメントモーダルシートと同等のものがありますか?

現在のウィンドウShowDialog()はアプリケーションのニーズには不十分です。アプリケーションの別のダイアログにモーダルダイアログを表示する必要がありますが、アプリケーションの他の領域にユーザーがアクセスできるようにする必要があります。

C#.NETにドキュメントモーダルシートと同等の機能がありますか?あるいは、誰かがやったことが近い実装であっても、私自身はこの機能を試して実装するのですか?私はGoogleとSOを無駄に検索してみました。

おかげで、

カイル

答えて

2

この問題を再確認した後、私は掘り下げて、自分のニーズに適したハイブリッドソリューションを見つけました。

Iはp-daddyによって提案を取った:https://stackoverflow.com/a/428782/654244

そしてIは、32ビットと64ビットhans-passantによって提案を使用してコンパイルするために動作するようにコードを変更し:https://stackoverflow.com/a/3344276/654244

結果を以下の通りである:

const int GWL_STYLE = -16; 
const int WS_DISABLED = 0x08000000; 

public static int GetWindowLong(IntPtr hWnd, int nIndex) 
{ 
    if (IntPtr.Size == 4) 
    { 
     return GetWindowLong32(hWnd, nIndex); 
    } 
    return GetWindowLongPtr64(hWnd, nIndex); 
} 

public static int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong) 
{ 
    if (IntPtr.Size == 4) 
    { 
     return SetWindowLong32(hWnd, nIndex, dwNewLong); 
    } 
    return SetWindowLongPtr64(hWnd, nIndex, dwNewLong); 
} 

[DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)] 
private static extern int GetWindowLong32(IntPtr hWnd, int nIndex); 

[DllImport("user32.dll", EntryPoint = "GetWindowLongPtr", CharSet = CharSet.Auto)] 
private static extern int GetWindowLongPtr64(IntPtr hWnd, int nIndex); 

[DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)] 
private static extern int SetWindowLong32(IntPtr hWnd, int nIndex, int dwNewLong); 

[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", CharSet = CharSet.Auto)] 
private static extern int SetWindowLongPtr64(IntPtr hWnd, int nIndex, int dwNewLong); 


public static void SetNativeEnabled(IWin32Window control, bool enabled) 
{ 
    if (control == null || control.Handle == IntPtr.Zero) return; 

     NativeMethods.SetWindowLong(control.Handle, NativeMethods.GWL_STYLE, NativeMethods.GetWindowLong(control.Handle, NativeMethods.GWL_STYLE) & 
      ~NativeMethods.WS_DISABLED | (enabled ? 0 : NativeMethods.WS_DISABLED)); 
} 

public static void ShowChildModalToParent(IWin32Window parent, Form child) 
{ 
    if (parent == null || child == null) return; 

    //Disable the parent. 
    SetNativeEnabled(parent, false); 

    child.Closed += (s, e) => 
    { 
     //Enable the parent. 
     SetNativeEnabled(parent, true); 
    }; 

    child.Show(parent); 
} 
1

Form.ShowDialog方法は、あなたがそれを呼び出すときに、所有者を指定することができます。この場合、フォームは指定された所有者に対してのみモーダルです。

編集:私はこの結果を混ぜて試しました。私はメインフォームと他の2つのWindowsフォームアプリケーションを作成しました。ボタンをクリックしてメインフォームをクリックし、Showメソッドを使用してForm2を開いた。 Form2にもボタンがあり、クリックすると、ShowDialogメソッドを使用してForm3を開き、Form2を所有者として渡しました。 Form3はForm2をモーダルに見せていましたが、Form3を閉じるまでForm1に戻ることはできませんでした。

+0

まだアプリケーションをブロックしますが、それはまだブロックします。ポスターは、アプリケーションの1つのウィンドウをブロックし、同じアプリケーションの他のウィンドウが正常に処理を継続できるようにする方法を求めています。 – tcarvin

+0

tcarvinは正しいです。私は詳細を私の質問に更新します。 – KyleK

+0

メインフォームから2番目のフォーム(Form2a)を開き、 'Show'を使って試してみてください。 Form2aに切り替えることができるかどうかを確認してください。 –

関連する問題