Monday 18 June 2018

Windows Forms Controls Visibility in c#

Sometimes we need to change the visibility of the WinForm controls. There could be the cases where we want to show/hide the controls for appropriate actions, people based on the requirements of the applications or the functionality. You can do it very easily just by creating a property of that particular controls and change its visibility like mentioned below


public bool IsControlVisible
{
  get { return control.Visible; }
  set { control.Visible = value; }
}

Usage: You can use the above code to determine/set the current visibility status of the control by using the below code

if(!MyForm.IsControlVisible)
{
  MyForm.IsControlVisible = true;
}

Explanation: MyForm is the instance of the winform and control is any control on that form, the if condition checks if the control is not visible then setting its visibility to true which will make the controls visible on the form. You can use the above property with any type of controls within the WinForm.


1 comment: