Skip to content

How to show the button on Customer Form only in view mode?

Posted in Education, and WhoCodeFirst

To show a button on a customer form only in view mode, you can use the following approach:

  • Create a boolean variable that will determine whether the form is in view mode or not.
  • Bind the Visibility property of the button to the boolean variable.
  • In the form’s Load event, set the boolean variable to true if the form is in view mode and false if it’s in edit mode.
  • In the form’s Closing event, set the boolean variable to false.

Here is an example of how you can implement this in C# code.

bool viewMode = false;
 private void CustomerForm_Load(object sender, EventArgs e)
 {
     if (this.FormMode == FormMode.View)
     {
         viewMode = true;
         button1.Visible = true;
     }
     else
     {
         viewMode = false;
         button1.Visible = false;
     }
 }
 private void CustomerForm_Closing(object sender, FormClosingEventArgs e)
 {
     viewMode = false;
     button1.Visible = false;
 }

You can also use this same logic for any other controls you want to show only in view mode.

Please Note: “FormMode” is a property that you have to check if it’s in View mode or not. Also in the above example, I have used C# Windows Form Application, you can use this logic in any platform you are using.

Happy Learning!

If you enjoyed this article, Get email updates (It’s Free)
Translate »