私は WinForm アプリケーションを開発していますが、これまでのところ、サイズとコンテンツの管理がかなりうまくいきませんでした。メイン フォームの cs ファイル内にあるロジックの一部を分解する方法の例を誰かが教えてくれることを期待していました。
MainWindow.cs 内にある EventHandler 関数の例を次に示します。
private void GroupBoxRequestTypeCheckedChanged(object pSender, EventArgs pEventArgs)
{
RadioButton vRadioButton = pSender as RadioButton;
if (vRadioButton != null)
{
this.fSelectedButton = vRadioButton.Checked ? vRadioButton : null;
if (vRadioButton.Equals(this.RadioButton_Copy) || vRadioButton.Equals(this.RadioButton_Delete) || vRadioButton.Equals(this.RadioButton_Download)
|| vRadioButton.Equals(this.RadioButton_Move) || vRadioButton.Equals(this.RadioButton_Upload))
{
this.GroupBox_Files.Enabled = true;
this.GroupBox_Variables.Enabled = false;
}
else
{
this.GroupBox_Files.Enabled = false;
this.GroupBox_Variables.Enabled = true;
}
if (this.fSelectedButton != null)
{
if (this.fSelectedButton.Equals(this.RadioButton_Delete))
{
this.TextBox_DestinationFile.Enabled = false;
this.Button_DestinationBrowse.Enabled = false;
}
else
{
this.TextBox_DestinationFile.Enabled = true;
this.Button_DestinationBrowse.Enabled = true;
}
}
}
}
したがって、これはフォーム内にある多くの EventHandler の 1 つにすぎません。タブ付きペインを持ち、各タブにボタン、テキストボックス、チェックボックスなどを持つタブのコレクションを持つ MainForm を作成しました。私が処理するすべてのイベントは MainForm.cs ファイルに入り、この 1 つのファイルに 1,000 行近くあります。
誰かが良い構造を詳述する簡単な例 (または記事/ドキュメント) を教えてくれますか? 別のクラスで EventHandler 関数を定義できますか (そうであれば、これはどのように機能しますか?) IE
private void GroupBoxRequestTypeCheckedChange(object pSender, EventArgs pEventArgs)
{
HelperClass.HandleGroupBoxRequestTypeCheckedChanged(pSender, pEventArgs, this);
}
「これ」は、操作する必要があるオブジェクトへのすべての参照を含むフォーム自体です。
クロススレッド呼び出しについてかなりのことを学び、必要な多くのインスタンスの単純化された拡張メソッドの作成を開始したことは、おそらく注目に値します。
もう 1 つの質問 - ビジュアル デザイナは、デフォルトで作成されたすべてのコンポーネントを自動的に非公開にすることに気付きました。これらを内部にし、必要に応じてフォーム オブジェクトを使用してこれらのコンポーネントをクラスの外部から参照するのは一般的に悪い考えですか? もしそれが良くないなら、何が良いですか?