Click to See Complete Forum and Search --> : Declaring variables in Windows form


raydona
February 25th, 2009, 03:45 PM
Hi,
Can anyone tell me what is the best way to declare and initialize variables to be used in a Windows form at file level (to be used by the form where the variable is declared) and at global level (to be used by several forms). I’ve been declaring variables under ‘Required designer variable’ as shown below and initializing the variables in Page_Load event (I don’t want to mess around with the form’s constructor as it causes the designer window not to function). I would be very grateful.
private:
/// <summary>
/// Required designer variable.
/// </summary>

Alex F
February 26th, 2009, 07:08 AM
Required designer variable is section produced by form designer. Declare your own variables in any other place.
Initialize variable inline, if possible, or in the class constructor. If variable may be initialized only when window is created, Load event handler is the proper place.
I don't know any problem with form designer, when code is added to constructor.