How can I create a text box in a non-visible form before I click calculate in C #?

advertisements

So in the beginning, the user has to input data but in the form. It has textboxes and labels where the answers to the calculations go. I have it so that when it clicks, it computes certain labels and textboxes show up and when the user clicks reset they disappear using:

txtTaxesPaid.Visible = true;

txtTaxesPaid.Visible = false;

My problem is that in the beginning the ones that are not visible. When I click reset they show up. How do I make them not visible in the very beginning?


Option 1: (shortest and most straight forward) In VS designer of your form - locate those controls and set the visible property to false.

Option 2: In your form_load event you can set the initial state of your controls.

Option 3: You can force to invoke the method of the button which already contain the reset commands from your form_load event.

Option 4: (I think is the preferable choice) - Create a method for reset.. - call the method from form_load or from your "reset" button or anywhere else you want.

private void ResetControls()
{
   txtMyControl.Visible=false;
   //here comes more logic for what to do upon reset.
}

private void form_load(...
{
  ResetControls();
}

private void btnReset_Click(...
{
  ResetControls();
}