Note that there are some explanatory texts on larger screens.

plurals
  1. POManaging EventHandlers within a large Form
    primarykey
    data
    text
    <p>I'm developing a WinForm application and I've done a pretty bad job thus far of managing the size and contents. I was hoping someone could give me an example of how to break out some of the logic that I have within the main form cs file.</p> <p>Here is an example of an EventHandler function that I have within my MainWindow.cs:</p> <pre><code> 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; } } } } </code></pre> <p>So this is simply one of many EventHandler's that I have within a Form. I created a MainForm which has a Tabbed Pane and has a collection of Tabs which have buttons, textboxes, checkboxes etc in each tab. All of the events that I handle go into the MainForm.cs file and now I've got close to 1,000 lines in this one file.</p> <p>Can someone give me a simple example (or a article/document) detailing good structure? Can I define my EventHandler functions in a separate class (if so, how would this work...) Do I create some sort of static Helper class where I simply pass the instance of the objects i need to manipulate? I.E.</p> <pre><code> private void GroupBoxRequestTypeCheckedChange(object pSender, EventArgs pEventArgs) { HelperClass.HandleGroupBoxRequestTypeCheckedChanged(pSender, pEventArgs, this); } </code></pre> <p>Where 'this' is the Form itself which has all the references to the objects I need to manipulate?</p> <p>It's probably worth noting that I've learned a good bit about the Cross-Thread calls and I've started making Extension methods for many instances that I need which are simplistic.</p> <p>Another question - I notice that the Visual Designer automatically makes all Components created with it private by default, is it in general a bad idea to make these internal and use the form object to reference these components as needed from outside the class? If it is not a good idea, what is better?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload