Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

Common Controls and Handling Control Events

By Exforsys | on June 20, 2005 |
VB.NET 2005

Common Controls and Handling Control Events

In this tutorial we will be learning how to use common control like Control Hierarchy, Label and LinkLabel, TextBox and RichTextBox, PictureBox, GroupBox and Panel, Button, CheckBox and RadioButton, ListBox, CheckedListBox and ComboBox, DomainUpDown and NumericUpDown, MonthCalendar and DateTimePicker, TreeView and ListView, Timer, TrackBar and ProgressBar, HScrollBar, VScrollBar, TabControl and Handling Control Events.

All controls are governed by the Control Class “System.Windows.Forms” Namespace. This class handles the entire basic window handle (HWND) functionality such as the creation and destruction of windows handles. When Control and Rich Control are integrated VB.NET provides for greater functionality.

A number of properties are shared by all controls in a class. Any change in such shared properties impacts on all controls in the class. Some of the shared properties are listed below.

DefaultBackColor: Read-only. Returns what the background color of the control would be if the background color were set explicityly

DefaultFont: Read-only. Returns what the font of the control would be if the font were set explicitly

DefaultForeColor: Read-only. Returns what the foreground color of the control would be if the fore ground color is changed.

Public Shared Properties

Public shared properties are distinct from properties that are shared by controls of a class in that the value of the property is not shared across the controls in a class. Any change in the property of a control does not result in a change in the properties of the controls in the class. Even when two instances of an object are created, each can have a distinct value assigned to a property. Examples of public instance properties are listed below for your understanding.

AccessibilityObject
Specified the AccessibleObject assigned to the control.
BackColor
Specifies the background color
Cursor
Specifies the cursor that is displayed when the mouse pointer moves over the control
Focused
Read-only. Returns whether the control currently as the input focus.
Size
Specifies the size of the control
Anchor
Specifies which edges of the control are bound to the edges of its container
Dock
Specifies to which edge of the container the control is docked. When specified, the resizing of the control is handled automatically. Controls that are “dockable” require code analyzing window movements coupled with the setting of this property
Font
Specifies the current font of the control
Location
Specifies the coordinates of the upper-left corner of the control relative to the upper-left corner of the controls container
Name
Specifies the name of the control. This value is typically used to refer to the control in code
Size
Specifies the height and width of the full control
TabIndex
Specifies this control’s place in the tab order for all controls within the same container
TabStop
Specifies whether the control can receive focus via the tab key
Visible
Specifies whether the control is visible
Enabled
Specifies whether the control is enabled. This also covers items such as receiving focus

Configuring the order of tabs

A user is required to move across a form in a prescribed order. The tab order of the control determines the way in which the cursor moves in the form and takes the user through the various options created for his use. This is a very important property for the application designer as it determines the sequence of user input if any.

Click on the control in the form and edit the TabIndex property and change its value. The value for this property is given in integers. This will be enabled only if the TabStop Property is set to true. Let us see an example for this feature.

  1. Create a new project in the visual Studio IDE and add a form.
  2. Drag and add 18 Command Buttons to this form and arrange them in a matrix.
  3. Pick any 6 of them and select them.
  4. Set the property enabled to false.
  5. This can also be done at runtime as shown in the example.
  6. Position two buttons separately as shown in the from.
  7. You can also add two labels one at the top and the other at the bottom.
  8. For each of the remaining Buttons do the following changes:
    1. From the first button on the top left change their name in order and give them a new name (First, Second … Tenth)
    2. You will find that the TabIndex value would have already been set as per the order of their placement in the form.
    3. Change their values so that the label named first will have the value 1 and the label that has the name Tenth will have a value 10.

At the bottom of the form you will have one label control and two command buttons. Set the name value for the label as null and that of the first command button to “Reverse Order!”. Let the name of the second command button be “Exit”. Now your form will look like the screenshot given below.



You have to add the following lines of code to the project:

Click here for Sample Source Code

Execute the project by pressing F5. This example illustrates the purpose of the properties and also the method used to assign the properties at run time. Please note that the property TabStop is not available to all properties. For example the controls like Label and LinkLabel do not expose this property.

Handling Control Events

Controls are used as a primary medium of handling events. Rich set of events are specified for controls and their nature can be easily understood by reading their names. For example OnClick, MouseEnter, MouseLeave etc. describe the nature of the event they handle. Some of the events and their descriptions are given below:

Event Name
Description
BackColorChanged
Occurs when the BackClolor property of the control is changed
BindingContextChanged
Occurs when the BindingContext property of the control changes
ChangeUICues
Occurs when focus or keyboard cues changes
ContextMenuChanged
Occurs when the Contextmenu Property of the control is changed
KeyUp
Occurs when a key is released while the control has focus
Move
Occurs when the control is moved
Resize
Occurs when the control is resized
Paint
Occurs when the control is drawn or redrawn
LocationChanged
Occurs when the location property of the control changes
Validating
Occurs when the visible property of the control changes

All controls have been declared with the functionalities built into them and therefore are capable of executing the function when the user calls the event. This process is enabled by using the term “Handles”. The program that is executed will look like the one below.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

————

————

End Sub

The event handler takes two parameters in the above instance. The first is the sender as System.Object and the other is the valued ‘e’ as System.EventArgs. The Sender defines the object that has raised the event and the EventArg contains all the event specific data that the event sender passes.

There are other types of arguments that are accepted, such as FileSystemEventAtrgs, ImageClickEventArgs, KeyEventArgs and CommandEventArgs. Using the SenderObject could be particularly useful if a any action from out of a set of grouped actions is to be performed. Let us look at an example of this.

Start a new Visual Basic Windows Application Project in the Visual Studio IDE.

Add seven buttons and four labels and rename the buttons as shown as shown in the following screenshot.

Two labels label3 and label4 are not visible as the text is set to null. Now add the code as given below:

Click here for Sample Source Code

Here, we have used a CommonHandler that does some action based on the output of the various events. This is a simple code that changes the text of the labels. You can also write complex codes using loops that perform some action based on the event of the object that has sent the event. This facility is very useful in solving complex problems with simple solutions quickly.

In the next chapter we will learn about Common Dialog Boxes and Creating a Custom Dialog Box in Visual Studio .NET 2005 using Visual Basic.NET 2005.

« « Visual Studio Adding Controls to Windows Form
Dialog Boxes in Visual Basic .NET » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 0 Followers
  • Popular
  • Recent
  • Windows Application Testing

    July 30, 2005 - 0 Comment
  • Implementing Inheritance

    June 5, 2005 - 0 Comment
  • VB.NET Creating and Managing Components Part 2

    July 6, 2005 - 0 Comment
  • DomainUpDown and NumericUpDown Controls

    June 27, 2005 - 0 Comment
  • Data Manipulation with ADO.NET

    July 15, 2005 - 0 Comment
  • Debugging Windows Applications In Visual Studio.NET 2005

    August 3, 2005 - 0 Comment
  • Visual Studio.NET Namespaces

    June 7, 2005 - 0 Comment
  • .NET Assemblies

    July 7, 2005 - 0 Comment
  • .NET Common Windows Forms Controls Part 2

    July 2, 2005 - 0 Comment
  • Using XML Data

    July 14, 2005 - 0 Comment
  • Microsoft .NET Creating Installation Components

    August 10, 2005 - 0 Comment
  • Shared Assembly

    August 9, 2005 - 0 Comment
  • The File Types Editor

    August 9, 2005 - 0 Comment
  • Tracing VB.NET Windows Application

    August 9, 2005 - 0 Comment
  • VB.NET Windows Application Testing

    August 9, 2005 - 0 Comment
  • The Registry Editor in Visual Studio.NET 2005

    August 4, 2005 - 0 Comment
  • Customizing Setup Project in Visual Studio.NET 2005

    August 4, 2005 - 0 Comment
  • Deploying Windows Applications In Visual Studio.NET 2005

    August 3, 2005 - 0 Comment
  • Debugging Windows Applications In Visual Studio.NET 2005

    August 3, 2005 - 0 Comment
  • Working with Legacy Code and COM Components

    July 30, 2005 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • Microsoft .NET Creating Installation Components
  • Shared Assembly
  • The File Types Editor
  • Tracing VB.NET Windows Application
  • VB.NET Windows Application Testing

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT