ITEC81 VB.NET Events, Methods, and Properties PDF
Document Details
Uploaded by UltraCrispThorium6799
City College of Tagaytay
Rumer M. Bayot
Tags
Summary
This document provides a lecture on VB.NET events, methods, and properties. It describes different types of events like Click, DoubleClick, and MouseHover, common VB.NET methods for string manipulation, mathematical operations, and file I/O. It also explores user-defined methods and console input/output methods. The document is suitable for undergraduate computer science learners.
Full Transcript
## ITEC81: Events Methods and Properties in VB.NET ### Presentation Outline 1. VB.NET Events 2. Some of the Common Events in VB.NET 3. VB.NET Methods 4. Common VB.NET Methods 5. VB.NET Properties 6. Common VB.NET Properties ## VB.NET Events * In Visual Basic .NET (VB.NET), common events refer to...
## ITEC81: Events Methods and Properties in VB.NET ### Presentation Outline 1. VB.NET Events 2. Some of the Common Events in VB.NET 3. VB.NET Methods 4. Common VB.NET Methods 5. VB.NET Properties 6. Common VB.NET Properties ## VB.NET Events * In Visual Basic .NET (VB.NET), common events refer to the events that are frequently used to respond to user interactions and system notifications in Windows Forms applications. * These events are associated with various common controls and are used to trigger specific actions or behaviors. * These events are used and coded as per the requirement of the user's application. ## Some of the Common Events in VB.NET * **Click**: Occurs when the user clicks a control, such as a button or a PictureBox. * **DoubleClick**: Occurs when the user double-clicks a control. * **MouseEnter**: Occurs when the mouse pointer enters the boundaries of a control. * **MouseLeave**: Occurs when the mouse pointer exits the boundaries of a control. * **MouseHover**: Occurs when the mouse pointer hovers over a control for a specified duration without moving. * **Mouse Click**: Occurs when the user clicks a control using the mouse\. * **Mouse DoubleClick**: Occurs when the user double-clicks a control using the mouse. * **KeyPress**: Occurs when a key is pressed while the control has focus. * **KeyUp**: Occurs when a key is released while the control has focus. * **KeyDown**: Occurs when a key is pressed down while the control has focus. * **TextChanged**: Occurs when the text within a TextBox or ComboBox control is changed. * **SelectionChanged**: Occurs when the selected item in a ListBox or ComboBox changes. * **ValueChanged**: Commonly used with controls like NumericUpDown, TrackBar, and DateTimePicker to respond to changes in their values. * **CheckedChanged**: Occurs when the state of a CheckBox or RadioButton control changes. * **ItemClicked (for MenuStrip)**: Occurs when a menu item is clicked in a MenuStrip control. * **LinkClicked (for LinkLabel)**: Occurs when a link is clicked in a LinkLabel control. * **FormClosing**: Occurs when a form is about to close, allowing us to handle closing operations. * **Load**: Occurs when a form or control is loaded and becomes visible. * **Resize**: Occurs when the size of a form or control is changed. * **Activated**: Occurs when a form or control becomes the active window. * **Deactivate**: Occurs when a form or control loses focus. * **TimerTick**: Occurs at regular intervals when a Timer control is enabled. ## VB.NET Methods * Visual Basic.NET (VB.NET) is a versatile programming language that offers a wide range of in-built methods and functions for various tasks. * VB.NET provides a rich set of in-built methods and functions for various tasks, and we can also create our own custom methods to encapsulate reusable functionality in our applications as per requirements. ## Common VB.NET Methods ### String Manipulation Methods * **String.Concat()**: This method concatenates two or more strings into a single string. * **For example**: ```VB.NET Dim result As String = String.Concat("Hello", " ", "India") ``` * **String.Length**: This method returns the length (number of characters) present in a string. * **For example**: ```VB.NET Dim length As Integer = “Hello India".Length ``` * **String.Substring()**: This method extracts a portion of a string. * **For example**: ```VB.NET Dim subString As String = "Hello World".Substring(0, 5) ' [Output = Hello] ``` * **String.ToUpper() and String.ToLower()**: This method converts a string to uppercase or lowercase respectively. * **For example**: ```VB.NET Dim uc As String = “Hello”.ToUpper() ' [Output = HELLO] Dim lc As String = "World".ToLower() ' [Output = world] ``` ### Mathematical Methods * **Math.Abs()**: This method returns the absolute value(+) of a number. * **For example**: ```VB.NET Dim AV As Double = Math.Abs(-5.5) ' [Output = 5.5] ``` * **Math.Round()**: This method rounds a floating-point number to the nearest integer. * **For example**: ```VB.NET Dim roundedValue As Integer = Math.Round(3.7) ' [Output = 4] ``` * **Math.Max() and Math.Min()**: This method returns the maximum or minimum of two numbers. * **For example**: ```VB.NET Dim maxValue As Integer = Math.Max(10, 5) ' [Output = 10] Dim minValue As Integer = Math.Min(10, 5) ' [Output = 5] ``` ### File and I/O Methods * **System.IO.File.ReadAllText()**: This method reads the contents of a text file into a string. * **For example**: ```VB.NET Dim text As String = System.IO.File.ReadAllText("file.txt") ``` * **System.IO.File.WriteAllText(path, text)**: Writes a string or contents to a text file, overwriting its contents. * **For example**: ```VB.NET System.IO.File.WriteAllText("file.txt”, “Hello, World!") ``` * **System.IO.File.Exists()**: This method checks if a file exists or not at the specified path. * **Syntax**: File.Exists(path) * **For example**: ```VB.NET Dim exists As Boolean = System.IO.File.Exists(“file.txt”) ``` * **File.ReadAllLines(path)**: Reads all lines from a text file into an array. * **Directory.CreateDirectory(path)**: Creates a directory at the specified path. ### Date and Time Methods * **DateTime.Now()**: Gets the current date and time. * **DateTime.Today()**: Gets the current date without the time\. * **DateTime.AddDays(days)**: Adds days to a date. * **DateTime.Parse(dateString)**: Parses a string into a DateTime object. ### Conversion Methods * **Convert.ToInt32(value)**: Converts a value to an integer. * **Convert.ToDouble(value)**: Converts a value to a double. * **Convert.ToString(value)** : Converts a value to a string. ### MessageBox Methods * **MessageBox.Show(message)**: Displays a message box with a message. * **MessageBox.Show(message, caption)**: Displays a message box with a message and caption. * **MessageBox.Show(message, caption, buttons)**: Displays a message box with specified buttons. ### User-Defined Methods * We can create our own methods in VB.NET to perform custom operations. * These methods are defined using the Function or Sub keyword. ### Console Input/Output Methods * **Console Input()**: * **Console.ReadLine()**: Used to read user input from the console. * **For Example**: ```VB.NET Dim userInput As String = Console.ReadLine() ``` * **Console Output()**: * **Console.WriteLine()**: Used to display text on the console. * **For Example**: ```VB.NET Console.WriteLine("Hello, World!") ``` ## VB.NET Properties * In Visual Basic .NET (VB.NET), properties are special member variables that provide controlled access to an object's data. * Properties allow us to get and set the values of private fields while encapsulating the internal details of the class. * There are some common types of properties in VB.NET. Properties are essential for encapsulating data and providing controlled access to class members, promoting good object-oriented programming practices and data encapsulation. ### Common VB.NET Properties * **Get Property (Read-Only Property)**: A get-only property allows us to retrieve the value of a private field but doesn't allow us to modify it. * **For example**: ```VB.NET Public ReadOnly Property FirstName As String Get Return first_name End Get End Property ``` * **Set Property (Write-Only Property)**: A set-only property allows us to set the value of a private field but doesn't allow us to retrieve it. * **For example**: ```VB.NET Public WriteOnly Property Age As Integer Set(value As Integer) age = value End Set End Property ``` * **Get-Set Property (Read-Write Property)**: A get-set property allows both getting and setting the value of a private field. * **For example**: ```VB.NET Public Property LastName As String Get Return last_name End Get Set(value As String) Last_Name = value End Set End Property ```