Working with windows programming [GUI programming] in C# .Net

 Working with windows  programming [GUI programming] :-

 

  1. working with from and controls is called as GUI programming.
  2. Windows programming supports to develop disk top applications , games, animations, Rich interactive, applications etc,…………
  3. Form works like a container, where any number of controls can be placed.
  4. Form is also called as WIN FORM (Windows form)
  5. Every Form is a class which must be inherited from a predefined class called as FROM.

 

Class Test : Form

{

 

}

 

Test arrrowform name

Formarrrowpredefined class

 

Example :

Developing a user defined from at run time.

 

arrrowopen windows forms application project

arrrowplace a button

arrrowcode in GD

 

Class Test : Form

Code for Button 1_ click

Test t = new Test ();

  1. Back color = color. Green;
  2. show ();

 

Every Form will be associated with three files

 

Screenshot_61

 

Working with FORM properties :-  (F4)

 

  1. Name: - this property changes object names with controls and class name with Forms
  2. Back color : Back ground color changes
  3. Fore color :-
  4. Font:-
  5. Back ground Image
  6. Back ground Image Layout
  7. Opacity (transparent) : when this value is decreasing then transparency ratio will be increasing  (2……………..100)
  8. Transparency key :- this value must be same as form back color.

Then except form border and controls body remaining port will be displayed fully transparent.

  1. Form border style : none
  2. Window state : normal / Minimize / Maximize

 

 

Developing a Screen Saver :-

 

Generally Screen saves are  .SCR files ,  which will be under  c:/windows/system 32 folder

Open windows forms application project with project name Abcd  (output file will be abcd. exe)

 

Form arrrowproperties  (F4) and set

Back color = black

Form border style  = none.

Window state = maximize

 

  • Place a picture Box control arrrow propertiesarrrowimage = select an Image
  • Place a timer control àproperties arrrow enabled = true
  • Code in GD. Int x = 0;
  • Code for Timer 1_Tick

{

X = x +5;

If (x > 400)

X = 0;

Picture box 1. Location = new point (x, x);

}

 

  • Code for Form 1 key press event ( Form 1 àproperties àclick on yellow colored Icon (events)àdouble click on key press )

{

Application .Exit ();

}

Execute the Project (F5)

 

OBS:-

 

Abcd .exe file will be created under

 

D:/c 194/abcd/bin/debug Folder

 

Rename Abcd .exe with Abcs.Scr

 

arrrowcopy Abcd .Scr in to C :/windows / system 32 folder;

Then check box desktop propertiesarrrowScreen saver

 

Form Properties continuation:-

 

Context menu Strip :

Screenshot_62

 

 

  • The Associated context menu strip control will be displayed when right clicked on an object.

 

Example on context menu strip :-

 

Display an Icon in Systems  along with context menu strip.

 

Screenshot_63

 

  • Open windows forms application project
  • Place a color – dialog control
  • Place a context menu strip control on the form
  • Design context menu strip with following options

 

Screenshot_64

 

 

    • Code for colors menu Item ( double click on colors)

    {

    Color Dialog 1. Show Dialog ();

    this. Back color = color Diaglog1. Color;

    }

     

    • Code for Exit menu Item

    {

    Application .Exit ();

    }

     

    • Place a notify I con control à properties à I con = select icon file
    • Context menu strip = context menu strip 1 à name of the control.

     

     

     

    Execute the project (F5)

    Then observe system’s tray for a new icon

 

 

Form properties Continuation

 

  1. Accept button : the Associated button will be executed when pressed “Enter key”
  2. Cancel Button : the associated button will be executed when pressed “Escape key”

Screenshot_65

 

 

 

Example:-

 

àOpen windows forms Application project

àPlace five text boxes and two buttons

 

  • Code for button 1 _ click

{

This. Back color = color .Green ;

}

 

à  code for button2_ click (clearing the text boxes)

{

For each (control c in this. controls)

{

If (c. Get type (). Name == “Text box”)

  1. text = “”;

}

 

  • Choose from properties

Accept Button = Button 1

Cancel Button = Button 2