答えはおそらくノーだと思います...しかし、いくつかの背景があります。サイズ設定ロジックが表示されている境界線を超えて機能するウィンドウにカスタム境界線を描画するために(Windows 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);
}
}
モーダルウィンドウを偽造して、モーダルではなく呼び出し元を無効にすることができると思います。私はこれを自分のプロジェクトで使用しました。私はそれをこのようにしました:
//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;
}
}
とても簡単です。イベントを使用して、最初のフォームを通知します。Heyiamの2番目のフォームでアクティブです。次に、2番目がアクティブなときに、最初のフォームを無効にすることができます。どのフォームがアクティブかどうかを完全に制御できます。お役に立てれば。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加