SlideShare ist ein Scribd-Unternehmen logo
1 von 29
GUI Applications Development Using .NET Framework
Objectives


                In this session, you will learn to:
                   Work with Windows Forms
                   Work with the Windows forms controls
                   Perform drag-and-drop operations using clipboard




     Ver. 1.0                        Session 2                        Slide 1 of 29
GUI Applications Development Using .NET Framework
Introducing Windows Forms


               • Windows Forms is a representation of any window
                 displayed in an application.
               • A form is used to accept input from a user and display the
                 information entered.
               • When you create a new project for a Windows application, a
                 form is automatically added to the project. This form has the
                 default name Form1.cs.
               • Every form in Windows is a class derived from the Form
                 class of the System.Windows.Forms namespace.




    Ver. 1.0                         Session 2                         Slide 2 of 29
GUI Applications Development Using .NET Framework
Windows Forms Properties


               Windows Forms properties are used to determine its
               appearance at run time.
                                                            Font property specifies
                                                            the style, size, and type
                 Backcolor property specifies               of font for the text to be
                 the background color of the                displayed on various
                 form.                                      controls in a form.



                                                              Size property is
                                                              used to specify the
                                                              height and width of
                                                              a form.


                                                            StartPosition property is
                                                            used to specify the position
                                                            of the form on the screen.
                                                             Text property is used to
                                                             specify the caption to be
                                                             displayed in the title bar
                                                             of a form.




    Ver. 1.0                                    Session 2                   Slide 3 of 29
GUI Applications Development Using .NET Framework
Windows Forms Methods


               Windows Forms methods enable you to perform various
               tasks, such as opening, activating, and closing the form.
               Some of the methods are:
               Form1 frmObj = new Form1(); // Is used to display a
               frmObj.show();                          form.
               frmObj.hide();
               frmObj.Activate();
               frmObj.Close();




    Ver. 1.0                     Session 2                      Slide 4 of 29
GUI Applications Development Using .NET Framework
Windows Forms Methods (Contd.)


               Windows Forms methods enable you to perform various
               tasks, such as opening, activating, and closing the form.
               Some of the methods are:
               Form1 frmObj = new Form1();
               frmObj.show();
               frmObj.hide();            // Is used to hide a form.
               frmObj.Activate();
               frmObj.Close();




    Ver. 1.0                       Session 2                        Slide 5 of 29
GUI Applications Development Using .NET Framework
Windows Forms Methods (Contd.)


               Windows Forms methods enable you to perform various
               tasks, such as opening, activating, and closing the form.
               Some of the methods are:
               Form1 frmObj = new Form1();
               frmObj.show();
               frmObj.hide();
               frmObj.Activate();           // Is used to activate a form and
               frmObj.Close();              set the focus on it.




    Ver. 1.0                       Session 2                         Slide 6 of 29
GUI Applications Development Using .NET Framework
Windows Forms Methods (Contd.)


               Windows Forms methods enable you to perform various
               tasks, such as opening, activating, and closing the form.
               Some of the methods are:
               Form1 frmObj = new Form1();
               frmObj.show();
               frmObj.hide();
               frmObj.Activate();
               frmObj.Close();           // Is used to close a form.




    Ver. 1.0                       Session 2                        Slide 7 of 29
GUI Applications Development Using .NET Framework
Windows Forms Events


               An event is generated when a user performs an action,
               such as clicking the mouse or pressing a key.
               You can specify the action to be performed on the
               occurrence of an event within a special method called,
               event handler.
               While the user needs to call the methods explicitly, the code
               within the event handler method gets executed as soon as
               the event gets generated.
               The common events used in a form are:
                  Click
                  FormClosed
                  Deactivate
                  Load
                  MouseMove

    Ver. 1.0                       Session 2                         Slide 8 of 29
GUI Applications Development Using .NET Framework
Working with Windows Forms Controls


               A control is a component used to accept input from a user
               or display some information on a form.
               Each control has its own set of properties, methods, and
               events that make it suitable for a particular task.
               You can set the properties of a control during design time
               by using the Properties window.
               You can also set the properties of a control at run time by
               writing code.




    Ver. 1.0                       Session 2                         Slide 9 of 29
GUI Applications Development Using .NET Framework
Working with Windows Forms Controls (Contd.)


                  Let us identify the various controls on a form.



                Label
                Controls                                            TextBox
                                                                    Controls




                                                                    ComboBox
                                                                    Control
                RadioButton                                         GroupBox
                Control                                             Control


                                                                    CheckBox
                                                                    Controls

                Button
                Control

     Ver. 1.0                         Session 2                        Slide 10 of 29
GUI Applications Development Using .NET Framework
Just a minute


                Which of the following control serves as a repository for
                images?
                 1.   PictureBox
                 2.   ListView
                 3.   ImageList
                 4.   ListBox




                Answer:
                 3. ImageList


     Ver. 1.0                       Session 2                         Slide 11 of 29
GUI Applications Development Using .NET Framework
Control Events


                The events associated with various controls are as follows:
                    Keyboard events             For example, KeyDown, KeyUp,
                    Mouse events                KeyPress
                                                For example MouseUP,
                    Control-specific events     MouseDown,Resized,
                                                For example MouseMove
                                                VisibleChanged




     Ver. 1.0                       Session 2                             Slide 12 of 29
GUI Applications Development Using .NET Framework
Dynamically Loading Controls in Windows Forms


                •   The loading of controls at run time is called dynamic loading
                    of controls.
                •   Every control is a class derived from the
                    System.Windows.Forms.Control class.
                •   To add a control at run time:
                     1. Create an instance of the control to be added.
                     2. Set the properties of the control.
                     3. Add the new control to the Controls collection of the parent
                        control.
                    Let us see how a control is added at run time.




     Ver. 1.0                            Session 2                            Slide 13 of 29
GUI Applications Development Using .NET Framework
Dynamically Loading Controls in Windows Forms (Contd.)


                For example, following code should be written to
                dynamically load a textbox control at the click of a button:
                  private void button1_Click(object sender,
                  EventArgs e)
                    {
                      TextBox t1 = new TextBox();
                      this.Controls.Add(t1);
                    }




     Ver. 1.0                       Session 2                         Slide 14 of 29
GUI Applications Development Using .NET Framework
Just a minute


                Write the steps, which need to be taken, while adding a
                control dynamically to a form.




                Answer:
                 1. Create an instance of the control to be added
                 2. Set the properties of the control
                 3. Add the control to the Controls collection of the parent control

     Ver. 1.0                         Session 2                             Slide 15 of 29
GUI Applications Development Using .NET Framework
Creating Event Handlers at Run Time


                Creation of event handlers at run time is required if a control
                is added to a form at run time.
                When you create an event handler at run time, you must
                first create a method that has the same parameters as the
                event that you want to handle.
                You must then connect the event with code that specifies
                the handler for the event involved.




     Ver. 1.0                       Session 2                          Slide 16 of 29
GUI Applications Development Using .NET Framework
Demo: Working with Windows Forms Controls


               Problem Statement:
                  Create an application to accept a user name and a password
                  through a startup screen. The application should check
                  whether the login name is “sa” and the password is
                  “callcenter”. The user should be provided with three login
                  attempts. After three unsuccessful login attempts, the
                  application should display an error message and close the
                  screen.




    Ver. 1.0                       Session 2                          Slide 17 of 29
GUI Applications Development Using .NET Framework
Demo: Working with Windows Forms Controls (Contd.)


                Solution:
                   To create a Login Form, you need to perform the following
                   tasks:
                     1.   Create a new VC# application.
                     2.   Design the application form.
                     3.   Add code to validate the user input.
                     4.   Execute the application and verify the output.




     Ver. 1.0                            Session 2                         Slide 18 of 29
GUI Applications Development Using .NET Framework
Performing Drag-and-Drop Operation Using Clipboard


                The drag-and-drop function enables you to drag an item
                from one location to another in an application.




     Ver. 1.0                      Session 2                      Slide 19 of 29
GUI Applications Development Using .NET Framework
The Drag-and-Drop Operation Events


                The events that need to be handled by the Windows Forms
                application to perform drag-and-drop operation are as
                follows:
                   ItemDrag
                   DragEnter
                   DragOver
                   DragDrop
                   DragLeave
                   GiveFeedback




     Ver. 1.0                     Session 2                     Slide 20 of 29
GUI Applications Development Using .NET Framework
The Drag-and-Drop Operation Phases


                To perform the drag-and-drop operation, the user has to
                perform a series of steps. These steps are:
                1. Initiate the drag-and-drop operation for a control by calling the
                   DoDragDrop() method from the MouseDown or the
                   ItemDrag event of the control.
                2. Handle the events to provide information about the
                   drag-and-drop operation to the user. These events include
                   DragEnter, DragLeave, and GiveFeedback.
                3. To enable the destination control to accept the dropped data,
                   set its AllowDrop property to true.
                4. Write code in the DragDrop event of the destination control
                   specifying how the dropped data should be handled.




     Ver. 1.0                        Session 2                              Slide 21 of 29
GUI Applications Development Using .NET Framework
Providing Clipboard Support in a Windows Form Application


                • Clipboard acts as a temporary storage area for any
                  application running on Windows operating system.
                • The Clipboard function can be incorporated in a VC#
                  application by using the methods provided by the
                  System.Windows.Forms.Clipboard class.
                • The three different operations associated with the clipboard
                  are:
                      Storing data on clipboard
                                                            To do so, use methods such as
                      Identifying the type of data on clipboardSetAudio(), SetData(),
                      Retrieving data from clipboard                 SetImage()
                                                                 To do so, use methods like
                                                                     ContainsAudio(),
                                                               To do so, use methods like
                                                                      ContainsData(),
                                                              GetAudioStream(), GetData(),
                                                                      ContainsImage()
                                                                      GetImage()




     Ver. 1.0                              Session 2                                    Slide 22 of 29
GUI Applications Development Using .NET Framework
Just a minute


                Which event occurs when a user drags an item in a
                TreeView or ListView control?
                1.   DragEnter event
                2.   DragOver event
                3.   GiveFeedback event
                4.   ItemDrag event




                Answer:
                4. ItemDrag event

     Ver. 1.0                       Session 2                       Slide 23 of 29
GUI Applications Development Using .NET Framework
Performing Drag-and-Drop Operation Between Applications


                The following code will help the user to enter text in a
                WordPad file and drag the text in the TextBox control on his
                form:
                  private void textBox1_DragEnter(object
                  sender,DragEventArgs e)
                   {

                if(e.Data.GetDataPresent(DataFormats.Text))
                       e.Effect = DragDropEffects.Copy;
                 else
                       e.Effect = DragDropEffects.None;
                 }



     Ver. 1.0                      Session 2                         Slide 24 of 29
GUI Applications Development Using .NET Framework
Performing Drag-and-Drop Operation Between Applications (Contd.)


                private void textBox1_DragDrop(object sender,
                DragEventArgs e)
                 {
                 textBox1.Text =
                e.Data.GetData(DataFormats.Text).ToString();
                 }



                                          Drag to the Form




     Ver. 1.0                 Session 2                      Slide 25 of 29
GUI Applications Development Using .NET Framework
Demo: Performing the Drag-and-Drop Operation


                Problem Statement:
                   Create an application to use the drag-and-drop feature of VC#.
                   Use the TextBox and TreeView controls as the source of data
                   and the ListBox control as the destination.
                   How will you create the application?




     Ver. 1.0                       Session 2                            Slide 26 of 29
GUI Applications Development Using .NET Framework
Demo: Performing the Drag-and-Drop Operation (Contd.)


                Solution:
                   To create an application to demonstrate the drag-and-drop
                   operation, you need to perform the following tasks:
                     1.   Create a new VC# application.
                     2.   Design the application form.
                     3.   Add code to perform the drag-and-drop operation.
                     4.   Execute the application and verify the output.




     Ver. 1.0                           Session 2                            Slide 27 of 29
GUI Applications Development Using .NET Framework
Summary


               In this session, you learned that:
                  A form is used to accept input from a user and present
                  information to the user.
                  A form has many properties, methods, and events.
                  An event gets generated on performing an action such as
                  clicking the mouse or pressing a key from the keyboard.
                  When an event is raised, code within the event handler is
                  executed.
                  Controls can be added to a form to accept input from the user
                  or display some information on the form.
                  Some commonly used controls are the TextBox, Label,
                  CheckBox, RadioButton, and Button controls.
                  Controls can be added either at design time or at runtime.
                  The drag-and-drop function enables the user to move an item
                  on a form from one location to another.

    Ver. 1.0                       Session 2                            Slide 28 of 29
GUI Applications Development Using .NET Framework
Summary (Contd.)


                 There are various events that need to be handled to support
                 the drag-and-drop operation in an application. These events
                 are:
                   •   ItemDrag event
                   •   DragEnter event
                   •   DragOver event
                   •   DragDrop event
                   •   DragLeave event
                   •   GiveFeedback event
               – Clipboard is the temporary repository of data.
               – The Clipboard function can be incorporated in the application
                 by using the methods provided by the
                 System.Windows.Forms.Clipboard class.




    Ver. 1.0                        Session 2                          Slide 29 of 29

Weitere ähnliche Inhalte

Andere mochten auch

Gui application development guidelines
Gui application development guidelinesGui application development guidelines
Gui application development guidelinesLOUIS WAYNE
 
Operating Systems Basics
Operating Systems BasicsOperating Systems Basics
Operating Systems Basicsnishantsri
 
Graphical User Interface
Graphical User Interface Graphical User Interface
Graphical User Interface Bivek Pakuwal
 
Graphical User Interface (Gui)
Graphical User Interface (Gui)Graphical User Interface (Gui)
Graphical User Interface (Gui)Bilal Amjad
 

Andere mochten auch (7)

Gui application development guidelines
Gui application development guidelinesGui application development guidelines
Gui application development guidelines
 
Chapter 7
Chapter 7Chapter 7
Chapter 7
 
Basic os-concepts
Basic os-conceptsBasic os-concepts
Basic os-concepts
 
Operating Systems Basics
Operating Systems BasicsOperating Systems Basics
Operating Systems Basics
 
Graphical User Interface
Graphical User Interface Graphical User Interface
Graphical User Interface
 
Graphical User Interface (Gui)
Graphical User Interface (Gui)Graphical User Interface (Gui)
Graphical User Interface (Gui)
 
Macintosh vs. windows
Macintosh vs. windowsMacintosh vs. windows
Macintosh vs. windows
 

Ähnlich wie 02 gui 02

visual basic v6 introduction
visual basic v6 introductionvisual basic v6 introduction
visual basic v6 introductionbloodyedge03
 
Vb.net session 02
Vb.net session 02Vb.net session 02
Vb.net session 02Niit Care
 
Programming Without Coding Technology (PWCT) - Label Control
Programming Without Coding Technology (PWCT) - Label ControlProgramming Without Coding Technology (PWCT) - Label Control
Programming Without Coding Technology (PWCT) - Label ControlMahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 54 of 88
The Ring programming language version 1.3 book - Part 54 of 88The Ring programming language version 1.3 book - Part 54 of 88
The Ring programming language version 1.3 book - Part 54 of 88Mahmoud Samir Fayed
 
Programming Without Coding Technology (PWCT) - Checkbutton control
Programming Without Coding Technology (PWCT) - Checkbutton controlProgramming Without Coding Technology (PWCT) - Checkbutton control
Programming Without Coding Technology (PWCT) - Checkbutton controlMahmoud Samir Fayed
 
Programming Without Coding Technology (PWCT) - Editbox control
Programming Without Coding Technology (PWCT) - Editbox controlProgramming Without Coding Technology (PWCT) - Editbox control
Programming Without Coding Technology (PWCT) - Editbox controlMahmoud Samir Fayed
 
Vb net xp_02
Vb net xp_02Vb net xp_02
Vb net xp_02Niit Care
 
Programming Without Coding Technology (PWCT) - Checkbox control
Programming Without Coding Technology (PWCT) - Checkbox controlProgramming Without Coding Technology (PWCT) - Checkbox control
Programming Without Coding Technology (PWCT) - Checkbox controlMahmoud Samir Fayed
 
Programming Without Coding Technology (PWCT) - Combobox control
Programming Without Coding Technology (PWCT) - Combobox controlProgramming Without Coding Technology (PWCT) - Combobox control
Programming Without Coding Technology (PWCT) - Combobox controlMahmoud Samir Fayed
 
Programming Without Coding Technology (PWCT) - Button Control
Programming Without Coding Technology (PWCT) - Button ControlProgramming Without Coding Technology (PWCT) - Button Control
Programming Without Coding Technology (PWCT) - Button ControlMahmoud Samir Fayed
 
Programming Without Coding Technology (PWCT) - Textbox Control
Programming Without Coding Technology (PWCT) - Textbox ControlProgramming Without Coding Technology (PWCT) - Textbox Control
Programming Without Coding Technology (PWCT) - Textbox ControlMahmoud Samir Fayed
 
Programming Without Coding Technology (PWCT) - Frame control
Programming Without Coding Technology (PWCT) - Frame controlProgramming Without Coding Technology (PWCT) - Frame control
Programming Without Coding Technology (PWCT) - Frame controlMahmoud Samir Fayed
 
Programming Without Coding Technology (PWCT) - Progressbar control
Programming Without Coding Technology (PWCT) - Progressbar controlProgramming Without Coding Technology (PWCT) - Progressbar control
Programming Without Coding Technology (PWCT) - Progressbar controlMahmoud Samir Fayed
 
Event driven theory
Event driven theoryEvent driven theory
Event driven theorynickywalters
 
Programming Without Coding Technology (PWCT) - Richeditbox control
Programming Without Coding Technology (PWCT) - Richeditbox controlProgramming Without Coding Technology (PWCT) - Richeditbox control
Programming Without Coding Technology (PWCT) - Richeditbox controlMahmoud Samir Fayed
 

Ähnlich wie 02 gui 02 (20)

visual basic v6 introduction
visual basic v6 introductionvisual basic v6 introduction
visual basic v6 introduction
 
Vb.net session 02
Vb.net session 02Vb.net session 02
Vb.net session 02
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
Programming Without Coding Technology (PWCT) - Label Control
Programming Without Coding Technology (PWCT) - Label ControlProgramming Without Coding Technology (PWCT) - Label Control
Programming Without Coding Technology (PWCT) - Label Control
 
The Ring programming language version 1.3 book - Part 54 of 88
The Ring programming language version 1.3 book - Part 54 of 88The Ring programming language version 1.3 book - Part 54 of 88
The Ring programming language version 1.3 book - Part 54 of 88
 
Programming Without Coding Technology (PWCT) - Checkbutton control
Programming Without Coding Technology (PWCT) - Checkbutton controlProgramming Without Coding Technology (PWCT) - Checkbutton control
Programming Without Coding Technology (PWCT) - Checkbutton control
 
Programming Without Coding Technology (PWCT) - Editbox control
Programming Without Coding Technology (PWCT) - Editbox controlProgramming Without Coding Technology (PWCT) - Editbox control
Programming Without Coding Technology (PWCT) - Editbox control
 
Vb net xp_02
Vb net xp_02Vb net xp_02
Vb net xp_02
 
Programming Without Coding Technology (PWCT) - Checkbox control
Programming Without Coding Technology (PWCT) - Checkbox controlProgramming Without Coding Technology (PWCT) - Checkbox control
Programming Without Coding Technology (PWCT) - Checkbox control
 
Programming Without Coding Technology (PWCT) - Combobox control
Programming Without Coding Technology (PWCT) - Combobox controlProgramming Without Coding Technology (PWCT) - Combobox control
Programming Without Coding Technology (PWCT) - Combobox control
 
Programming Without Coding Technology (PWCT) - Button Control
Programming Without Coding Technology (PWCT) - Button ControlProgramming Without Coding Technology (PWCT) - Button Control
Programming Without Coding Technology (PWCT) - Button Control
 
Programming Without Coding Technology (PWCT) - Textbox Control
Programming Without Coding Technology (PWCT) - Textbox ControlProgramming Without Coding Technology (PWCT) - Textbox Control
Programming Without Coding Technology (PWCT) - Textbox Control
 
03 gui 04
03 gui 0403 gui 04
03 gui 04
 
Programming Without Coding Technology (PWCT) - Frame control
Programming Without Coding Technology (PWCT) - Frame controlProgramming Without Coding Technology (PWCT) - Frame control
Programming Without Coding Technology (PWCT) - Frame control
 
Programming Without Coding Technology (PWCT) - Progressbar control
Programming Without Coding Technology (PWCT) - Progressbar controlProgramming Without Coding Technology (PWCT) - Progressbar control
Programming Without Coding Technology (PWCT) - Progressbar control
 
04 gui 05
04 gui 0504 gui 05
04 gui 05
 
Event driven theory
Event driven theoryEvent driven theory
Event driven theory
 
Programming Without Coding Technology (PWCT) - Richeditbox control
Programming Without Coding Technology (PWCT) - Richeditbox controlProgramming Without Coding Technology (PWCT) - Richeditbox control
Programming Without Coding Technology (PWCT) - Richeditbox control
 
Vb.net and .Net Framework
Vb.net and .Net FrameworkVb.net and .Net Framework
Vb.net and .Net Framework
 
Intake 37 9
Intake 37 9Intake 37 9
Intake 37 9
 

Mehr von Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 

Kürzlich hochgeladen

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 

Kürzlich hochgeladen (20)

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 

02 gui 02

  • 1. GUI Applications Development Using .NET Framework Objectives In this session, you will learn to: Work with Windows Forms Work with the Windows forms controls Perform drag-and-drop operations using clipboard Ver. 1.0 Session 2 Slide 1 of 29
  • 2. GUI Applications Development Using .NET Framework Introducing Windows Forms • Windows Forms is a representation of any window displayed in an application. • A form is used to accept input from a user and display the information entered. • When you create a new project for a Windows application, a form is automatically added to the project. This form has the default name Form1.cs. • Every form in Windows is a class derived from the Form class of the System.Windows.Forms namespace. Ver. 1.0 Session 2 Slide 2 of 29
  • 3. GUI Applications Development Using .NET Framework Windows Forms Properties Windows Forms properties are used to determine its appearance at run time. Font property specifies the style, size, and type Backcolor property specifies of font for the text to be the background color of the displayed on various form. controls in a form. Size property is used to specify the height and width of a form. StartPosition property is used to specify the position of the form on the screen. Text property is used to specify the caption to be displayed in the title bar of a form. Ver. 1.0 Session 2 Slide 3 of 29
  • 4. GUI Applications Development Using .NET Framework Windows Forms Methods Windows Forms methods enable you to perform various tasks, such as opening, activating, and closing the form. Some of the methods are: Form1 frmObj = new Form1(); // Is used to display a frmObj.show(); form. frmObj.hide(); frmObj.Activate(); frmObj.Close(); Ver. 1.0 Session 2 Slide 4 of 29
  • 5. GUI Applications Development Using .NET Framework Windows Forms Methods (Contd.) Windows Forms methods enable you to perform various tasks, such as opening, activating, and closing the form. Some of the methods are: Form1 frmObj = new Form1(); frmObj.show(); frmObj.hide(); // Is used to hide a form. frmObj.Activate(); frmObj.Close(); Ver. 1.0 Session 2 Slide 5 of 29
  • 6. GUI Applications Development Using .NET Framework Windows Forms Methods (Contd.) Windows Forms methods enable you to perform various tasks, such as opening, activating, and closing the form. Some of the methods are: Form1 frmObj = new Form1(); frmObj.show(); frmObj.hide(); frmObj.Activate(); // Is used to activate a form and frmObj.Close(); set the focus on it. Ver. 1.0 Session 2 Slide 6 of 29
  • 7. GUI Applications Development Using .NET Framework Windows Forms Methods (Contd.) Windows Forms methods enable you to perform various tasks, such as opening, activating, and closing the form. Some of the methods are: Form1 frmObj = new Form1(); frmObj.show(); frmObj.hide(); frmObj.Activate(); frmObj.Close(); // Is used to close a form. Ver. 1.0 Session 2 Slide 7 of 29
  • 8. GUI Applications Development Using .NET Framework Windows Forms Events An event is generated when a user performs an action, such as clicking the mouse or pressing a key. You can specify the action to be performed on the occurrence of an event within a special method called, event handler. While the user needs to call the methods explicitly, the code within the event handler method gets executed as soon as the event gets generated. The common events used in a form are: Click FormClosed Deactivate Load MouseMove Ver. 1.0 Session 2 Slide 8 of 29
  • 9. GUI Applications Development Using .NET Framework Working with Windows Forms Controls A control is a component used to accept input from a user or display some information on a form. Each control has its own set of properties, methods, and events that make it suitable for a particular task. You can set the properties of a control during design time by using the Properties window. You can also set the properties of a control at run time by writing code. Ver. 1.0 Session 2 Slide 9 of 29
  • 10. GUI Applications Development Using .NET Framework Working with Windows Forms Controls (Contd.) Let us identify the various controls on a form. Label Controls TextBox Controls ComboBox Control RadioButton GroupBox Control Control CheckBox Controls Button Control Ver. 1.0 Session 2 Slide 10 of 29
  • 11. GUI Applications Development Using .NET Framework Just a minute Which of the following control serves as a repository for images? 1. PictureBox 2. ListView 3. ImageList 4. ListBox Answer: 3. ImageList Ver. 1.0 Session 2 Slide 11 of 29
  • 12. GUI Applications Development Using .NET Framework Control Events The events associated with various controls are as follows: Keyboard events For example, KeyDown, KeyUp, Mouse events KeyPress For example MouseUP, Control-specific events MouseDown,Resized, For example MouseMove VisibleChanged Ver. 1.0 Session 2 Slide 12 of 29
  • 13. GUI Applications Development Using .NET Framework Dynamically Loading Controls in Windows Forms • The loading of controls at run time is called dynamic loading of controls. • Every control is a class derived from the System.Windows.Forms.Control class. • To add a control at run time: 1. Create an instance of the control to be added. 2. Set the properties of the control. 3. Add the new control to the Controls collection of the parent control. Let us see how a control is added at run time. Ver. 1.0 Session 2 Slide 13 of 29
  • 14. GUI Applications Development Using .NET Framework Dynamically Loading Controls in Windows Forms (Contd.) For example, following code should be written to dynamically load a textbox control at the click of a button: private void button1_Click(object sender, EventArgs e) { TextBox t1 = new TextBox(); this.Controls.Add(t1); } Ver. 1.0 Session 2 Slide 14 of 29
  • 15. GUI Applications Development Using .NET Framework Just a minute Write the steps, which need to be taken, while adding a control dynamically to a form. Answer: 1. Create an instance of the control to be added 2. Set the properties of the control 3. Add the control to the Controls collection of the parent control Ver. 1.0 Session 2 Slide 15 of 29
  • 16. GUI Applications Development Using .NET Framework Creating Event Handlers at Run Time Creation of event handlers at run time is required if a control is added to a form at run time. When you create an event handler at run time, you must first create a method that has the same parameters as the event that you want to handle. You must then connect the event with code that specifies the handler for the event involved. Ver. 1.0 Session 2 Slide 16 of 29
  • 17. GUI Applications Development Using .NET Framework Demo: Working with Windows Forms Controls Problem Statement: Create an application to accept a user name and a password through a startup screen. The application should check whether the login name is “sa” and the password is “callcenter”. The user should be provided with three login attempts. After three unsuccessful login attempts, the application should display an error message and close the screen. Ver. 1.0 Session 2 Slide 17 of 29
  • 18. GUI Applications Development Using .NET Framework Demo: Working with Windows Forms Controls (Contd.) Solution: To create a Login Form, you need to perform the following tasks: 1. Create a new VC# application. 2. Design the application form. 3. Add code to validate the user input. 4. Execute the application and verify the output. Ver. 1.0 Session 2 Slide 18 of 29
  • 19. GUI Applications Development Using .NET Framework Performing Drag-and-Drop Operation Using Clipboard The drag-and-drop function enables you to drag an item from one location to another in an application. Ver. 1.0 Session 2 Slide 19 of 29
  • 20. GUI Applications Development Using .NET Framework The Drag-and-Drop Operation Events The events that need to be handled by the Windows Forms application to perform drag-and-drop operation are as follows: ItemDrag DragEnter DragOver DragDrop DragLeave GiveFeedback Ver. 1.0 Session 2 Slide 20 of 29
  • 21. GUI Applications Development Using .NET Framework The Drag-and-Drop Operation Phases To perform the drag-and-drop operation, the user has to perform a series of steps. These steps are: 1. Initiate the drag-and-drop operation for a control by calling the DoDragDrop() method from the MouseDown or the ItemDrag event of the control. 2. Handle the events to provide information about the drag-and-drop operation to the user. These events include DragEnter, DragLeave, and GiveFeedback. 3. To enable the destination control to accept the dropped data, set its AllowDrop property to true. 4. Write code in the DragDrop event of the destination control specifying how the dropped data should be handled. Ver. 1.0 Session 2 Slide 21 of 29
  • 22. GUI Applications Development Using .NET Framework Providing Clipboard Support in a Windows Form Application • Clipboard acts as a temporary storage area for any application running on Windows operating system. • The Clipboard function can be incorporated in a VC# application by using the methods provided by the System.Windows.Forms.Clipboard class. • The three different operations associated with the clipboard are: Storing data on clipboard To do so, use methods such as Identifying the type of data on clipboardSetAudio(), SetData(), Retrieving data from clipboard SetImage() To do so, use methods like ContainsAudio(), To do so, use methods like ContainsData(), GetAudioStream(), GetData(), ContainsImage() GetImage() Ver. 1.0 Session 2 Slide 22 of 29
  • 23. GUI Applications Development Using .NET Framework Just a minute Which event occurs when a user drags an item in a TreeView or ListView control? 1. DragEnter event 2. DragOver event 3. GiveFeedback event 4. ItemDrag event Answer: 4. ItemDrag event Ver. 1.0 Session 2 Slide 23 of 29
  • 24. GUI Applications Development Using .NET Framework Performing Drag-and-Drop Operation Between Applications The following code will help the user to enter text in a WordPad file and drag the text in the TextBox control on his form: private void textBox1_DragEnter(object sender,DragEventArgs e) { if(e.Data.GetDataPresent(DataFormats.Text)) e.Effect = DragDropEffects.Copy; else e.Effect = DragDropEffects.None; } Ver. 1.0 Session 2 Slide 24 of 29
  • 25. GUI Applications Development Using .NET Framework Performing Drag-and-Drop Operation Between Applications (Contd.) private void textBox1_DragDrop(object sender, DragEventArgs e) { textBox1.Text = e.Data.GetData(DataFormats.Text).ToString(); } Drag to the Form Ver. 1.0 Session 2 Slide 25 of 29
  • 26. GUI Applications Development Using .NET Framework Demo: Performing the Drag-and-Drop Operation Problem Statement: Create an application to use the drag-and-drop feature of VC#. Use the TextBox and TreeView controls as the source of data and the ListBox control as the destination. How will you create the application? Ver. 1.0 Session 2 Slide 26 of 29
  • 27. GUI Applications Development Using .NET Framework Demo: Performing the Drag-and-Drop Operation (Contd.) Solution: To create an application to demonstrate the drag-and-drop operation, you need to perform the following tasks: 1. Create a new VC# application. 2. Design the application form. 3. Add code to perform the drag-and-drop operation. 4. Execute the application and verify the output. Ver. 1.0 Session 2 Slide 27 of 29
  • 28. GUI Applications Development Using .NET Framework Summary In this session, you learned that: A form is used to accept input from a user and present information to the user. A form has many properties, methods, and events. An event gets generated on performing an action such as clicking the mouse or pressing a key from the keyboard. When an event is raised, code within the event handler is executed. Controls can be added to a form to accept input from the user or display some information on the form. Some commonly used controls are the TextBox, Label, CheckBox, RadioButton, and Button controls. Controls can be added either at design time or at runtime. The drag-and-drop function enables the user to move an item on a form from one location to another. Ver. 1.0 Session 2 Slide 28 of 29
  • 29. GUI Applications Development Using .NET Framework Summary (Contd.) There are various events that need to be handled to support the drag-and-drop operation in an application. These events are: • ItemDrag event • DragEnter event • DragOver event • DragDrop event • DragLeave event • GiveFeedback event – Clipboard is the temporary repository of data. – The Clipboard function can be incorporated in the application by using the methods provided by the System.Windows.Forms.Clipboard class. Ver. 1.0 Session 2 Slide 29 of 29

Hinweis der Redaktion

  1. Students have already learnt the basic syntax and program structure in C#. They have already designed console based application. Now the students will be familiarized with windows based applications. Start the session by sharing the session objectives with the students.
  2. The students have already understood the difference in CUI and GUI applications. Also, they are aware of the advantages of the GUI applications as being more user friendly. Therefore, the faculty should start the session with the same concept of designing GUI applications. In order to design these applications the students require Windows Form. This is a container that can contain other controls such as a label, textbox, button, list box etc. Explain the concept of form by taking a real life example. Compare this with the Admissions form to be filled by students to take admission in a university. Discuss with the students, that each students is handed over a similar form to be filled. This reduces the ambiguity, as otherwise each student will write details at their own will. This will make it difficult for the Admissions department to extract the required information. Explain to the students that a form is added by default when a new windows application project is opened. The students can customize this form according to their requirements.
  3. To customize the form, the students can use several properties of the forms. Some of these properties have been displayed here.
  4. Besides properties, a Form control also has various methods that can be used to customize an application according to customer’s requirements. Here the faculty must display a demo form that helps the students to understand the way properties, methods, and events can be attached to a form. The faculty can also display the purpose of the methods such as show(), hide(), close(), activate().
  5. In GUI programming, the most important thing is an event. Events can be used to perform an action. The faculties must explain to the students that all the controls have various events attached to them. For example, display a simple form to the students that is being to add two numbers. While creating this form do not insert any buttons. Insert only 3 labels and 3 textboxes ( to accept 1 st number, 2 nd number, display result). Now insert numbers in the 1 st and 2 nd textbox. After this ask the students, how will they be able to see the result. Collate the answers from the students. Now add a button to the form and create code in the click event of the button. With this example, you can discuss the importance of the events in a GUI application.
  6. The faculty must demonstrate all the commonly used controls with the help of a form. These have been shown in the given figure.
  7. Explain to the students that there are three basic categories of events. These are keyboard, mouse, and control-specific events. The keyboard events are generated when the keyboard keys are pressed or released. The mouse events are generated when the mouse keys are pressed or released. Mouse events are also generated when the mouse is rolled over a control. The control-specific events are associated to a particular control. You can write the following code to demonstrate one of the keyboard events: Create a text box on the form n then write the following code in the KeyPress event of the form: private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { MessageBox.Show("keypressed"); } You can write the following code to demonstrate one of the mouse events. This code needs to be written in the MouseUp event of the form. private void Form1_MouseUp(object sender, MouseEventArgs e) { MessageBox.Show("MouseUp"); }
  8. Explain the concept of loading controls dynamically with the help of the following example: The controls need to be dynamically loaded in an Order Detail Entry form. This is because one of the customer may have purchased five items while the other may have purchased 15 items. Now if the form contains only 10 text box controls to accept input, the user will not be able to enter details for all the items for the second customer in a single bill. He might have to create two bills. Therefore, to overcome such a problem, the user must have the flexibility to add as many text boxes as the number of items purchased by the customers at the run time. In addition, the faculty must demonstrate an application that loads controls dynamically to the form.
  9. Use this and the next slide to create an application containing Windows Forms Controls. Discuss with the students the various controls, methods, and events that are added within the form application.
  10. Before discussing this topic with the students, the faculty must demonstrate the drag-and-drop operation using any of the Windows based application such as wordpad or notepad. Although the students would have already worked with the clipboard while working with MS-Word or MS-Exccel, the faculty should also discuss the features of clipboard with the students. Using this and the next two slides, explain to the students that they can use a clipboard in their VC# applications with the help of Clipboard functions.
  11. The faculty must also discuss these Drag-and-Drop operation events with the students.
  12. Before discussing this topic with the students, the faculty must demonstrate the drag-and-drop operation using any of the Windows based application such as wordpad or notepad. Although the students would have already worked with the clipboard while working with MS-Word or MS-Exccel, the faculty should also discuss the features of clipboard with the students. Using this and the next two slides, explain to the students that they can use a clipboard in their VC# applications with the help of Clipboard functions.
  13. For the following example to be functional, you need to add a text box control named textBox1 to the form and write the given code in the corresponding textbox events
  14. Use this and the next slide to discuss the concept of drag-and-drop operations. Ask students to provide examples of different applications where these drag-and-drop operations can be used.
  15. You can summarize the session by using the summary given in the slides. In addition, you can also ask students to summarize what they have learnt in this session.