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

15 October, 2020

Related Blogs

 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. Formworks like a container, where any number of controls can be placed.
  4. The form is also called as WIN FORM (Windows form)
  5. Every Form is a class that must be inherited from a predefined class called FROM.

  Class Test: Form



  Test arrrowform name

Formarrrowpredefined class  

Example :

Developing a user-defined from at the run time.  

arrrowopen windows form 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 ();

 Interested in mastering .NET? Learn more about ".NET Training" in this blog post.

Every Form will be associated with three files


Working with FORM properties:-  (F4)  

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

Then except form, the 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)  


  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 properties

arrrowScreen saver  

Form Properties continuation:-

 Context menu Strip :


  • 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.  


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


    • 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 Icon control à properties à Icon = select icon file
    • Context menu strip = context menu strip 1 à name of the control.
          Execute the project (F5) Then observe the 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”



àOpen windows form 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”)

text = “”;
  • Choose from properties

Accept Button = Button 1

Cancel Button = Button 2