2016-11-09 5 views
1

私は恐らく答えはノーですが、いくつかの背景です。表示枠線を越えてサイジングロジックが動作するウィンドウにカスタムボーダーを描画するには(ウィンドウ10と同じように)、ウィンドウの周りにレイヤーウィンドウを追加してメッセージをキャプチャし、それらを中央ウィンドウに転送します。これは、フォームが修正されて表示されるまでうまくいきました。その時点で、すべてのエッジウィンドウが自動的に無効になりました。明らかにこれは設計によるものですが、周りに何らかの方法があるかどうかはわかりません。私は中央のウィンドウでエッジウィンドウを所有しようとしましたが、うまくいかなかった。モーダルウィンドウを表示するときに追加のウィンドウをアクティブにする方法はありますか?

また、完全に良いアプローチがあります。それはしかし、モーダル発信者を無効にされないように私は、することができます偽のモーダルウィンドウと思う

public partial class Form1 : Form 
    { 
     public Form1() 
     { 
     } 

     protected override void OnClick(EventArgs e) 
     { 
     base.OnClick(e); 

     Form f2 = new Form(); 

     f2.Text = "Non Modal"; 

     f2.Show(); 

     Form f3 = new Form(); 

     f3.Text = "Modal"; 

     f3.ShowDialog(this); 
     } 
    } 
+1

モーダルダイアログでは、所有者のみが無効になります。どのような設定を実装したのかははっきりしていないので、モーダルダイアログではこれらの追加ウィンドウも無効になります。 – IInspectable

+0

あなたの言ったことが当てはまらないことを実証するための例を追加しました。 – user109078

答えて

0

は、ここで問題のサンプルです。私はこれを自分のプロジェクトで使っていました。私はこのようにしました:

//Setup small Interface 
public interface IDialog 
{ 
    //Our own Event which tell the caller if the Dialog is active/inactive 
    public event DialogChangedEventArgs DialogChanged; 
} 

//Setup EventArgs for our own Event 
public class DialogChangedEventArgs : EventArgs 
{ 
    public bool DialogActive{get;} 

    public DialogChangedEventArgs(bool dialogActive) 
    { 
     DialogActive = dialogActive; 
    } 
} 

//Setup the Form which act as Dialog in any other form 
public class Form2 : Form, IDialog 
{ 
    public event EventHandler<DialogChangedEventArgs> DialogChanged; 

    //If this Form is shown we fire the Event and tell subscriber we are active 
    private void Form2_Shown(object sender, EventArgs e) 
    { 
     DialogChanged?.Invoke(this, true); 
    } 

    //If the user close the Form we telling subscriber we go inactive 
    private void Form2_Closing(object sender, CancelEventArgs e) 
    { 
     DialogChanged?.Invoke(this, false); 
    } 
} 

public class Form1 : Form 
{ 
    //Setup our Form2 and show it (not modal here!!!) 
    private void Initialize() 
    { 
    Form2 newForm = new Form2(); 
    newForm.DialogChanged += DialogChanged; 
    newForm.Show(); 
    } 

    private void Form2_DialogChanged(object sender, DialogChangedEventArgs e) 
    { 
     //Now check if Form2 is active or inactive and enable/disable Form1 
     //So just Form1 will be disabled. 
     Enable = !e.DialogActive; 
    } 
} 

これは本当に簡単です。イベントを使用して、最初のフォームに:Hey iam second formとアクティブを伝えてください。その後、2番目がアクティブな状態で最初のフォームを無効にすることができます。フォームがアクティブであるかどうかを完全に制御できます。お役に立てれば。

+0

EnableWindowを使うと、メインフォームのすべてのコントロールが無効な外観に変わらないようになるかもしれませんが、このテクニックはうまくいくと思います! – user109078

関連する問題