Shahid Ashraf Enrolment # 100210 Department of IT
Shahid Ashraf Enrolment # 100210 Department of IT
Shahid Ashraf Enrolment # 100210 Department of IT
VB.NET INTRO
Visual Basic .NET (VB.NET), is an object-oriented computer programming language that can be viewed as an evolution of the classic Visual Basic (VB), which is implemented on the .NET Framework. There are four versions and five releases of Visual Basic .NET implemented by the Visual Basic Team. Visual Basic .NET 2003 (VB 7.1) Visual Basic 2005 (VB 8.0) Visual Basic 2008 (VB 9.0) Visual Basic 2010 (VB 10.0)
Controls
A control is an object that can be drawn on to the Form to enable or enhance user interaction with the application. Examples of these controls, TextBoxes, Buttons, Labels etc. All these Windows Controls are based on the Control class, the base class for all controls. Visual Basic allows us to work with controls in two ways: at design time and at runtime.
Abstraction
Like forms, controls are based on classes in the FCL:
System.Windows.Forms.Label System.Windows.Forms.TextBox
System.Windows.Forms.Button
object object
etc.
object
object
object
Notable properties of most of these Windows Controls which are based on the Control class itself are summarized in the table below.
Continued
Button Control
One of the most popular control in Visual Basic is the Button Control (previously Command Control). They are the controls which we click and release to perform some action. Buttons are used mostly for handling events in code, say, for sending data entered in the form to the database and so on. The default event of the Button is the Click event and the Button class is based on the ButtonBase class which is based on the Control class.
Appearance Appearance section of the properties window allows us to make changes to the appearance of the Button. BackColor, Background Image, ForeColor.etc Behavior Notable Behavior properties of the Button are the Enabled and Visible properties. The Enabled property is set to True by default which makes the button enabled and setting it's property to False makes the button Disabled. Layout Layout properties are about the look of the Button. With the Location property you can change the location of the button. With the Size property you can set the size of the button. Apart from the Dock property you can set it's size and location by moving and stretching the Button on the form itself.
MaskedTextBox
A MaskedTextBox control provides validation mechanism for user input on a Form. For example, if we want a TextBox to accept date in mm/dd/yyyy format, we can set masking in the MaskedTextBox. We can create a MaskedTextBox control using a Forms designer at design-time or using the MaskedTextBox class in code at run-time (also known as dynamically) the MaskedTextBox class is derived from TextBoxBase that provides its fundamental properties*.
Properties
Probably the most important property of a masked text box, which sets it apart from the (traditional) text box control, is its ability to control what the user can and cannot enter in the text side. To visually configure this text, the MaskedTextBox class is equipped with a property named Mask. Mask the default property and represents the format of the input can be accepted by a control There are two main ways you can configure it:
The following code snippet sets the Mask property at run-time. dynamicMaskedTextBox.Mask = "00/00/0000"
Picture Box
PictureBoxes are used to display images on them. The images displayed can be anything varying from Bitmap, JPEG, GIF, PNG or any other image format files. The PictureBox control is based on the Control class. Notable property of the PictureBox Control in the Appearance section of the properties window is the Image property which allows to add the image to be displayed on the PictureBox.
Another important property is SizeMode Controls how the PictureBox will handle image placement and control sizing. ContextMenuStrip property This property allow to display shortcut menu when a user clicks on the picture box. The PictureBox control can also be use to display the video files. The PictureBox is not a selectable control, which means that it cannot receive input focus.
ToolTip
Represents a small rectangular pop-up window that displays a brief description of a control's purpose when the user rests the pointer on the control. provides useful contextual hints to the client ToolTip is not a control but a component which means that when we drag a ToolTip from the toolbox onto a form it will be displayed on the component tray. Tooltip is an Extender provider component which means that when you place an instance of a ToolTipProvider on a form, every control on that form receives a new property. This property can be viewed and set in the properties window where it appears as Tooltip on n, where n is the name of the ToolTipProvider.
Important methods. The most important methods on ToolTip controls you can use in C# or VB.NET are the Show method, the Hide method, the SetToolTip method, and the GetToolTip method. First, the Show method forces the tip to be displayed.
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles MyBase.Load Create the ToolTip and associate with the Form container. Dim toolTip1 As New ToolTip() ' Set up the delays for the ToolTip. toolTip1.AutoPopDelay = 5000 toolTip1.InitialDelay = 1000 toolTip1.ReshowDelay = 500 ' Force the ToolTip text to be displayed whether or not the form is active. toolTip1.ShowAlways = True ' Set up the ToolTip text for the Button and Checkbox. toolTip1.SetToolTip(Me.button1, "My button1") toolTip1.SetToolTip(Me.checkBox1, "My checkBox1") End Sub
TextBox
Represents a Windows text box control. The TextBox is based on the TextBoxBase class which is based on the Control class. TextBoxes are used to accept input from the user or used to display text. The amount of text that can be stored in the Text property is 64K character capacity limit of the TextBox control
TextBox Event
The default event of the TextBox is the TextChanged Event which looks like this in code:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles TextBox1.TextChanged MsgBox(Textchanged") End Sub
RichTextBox
RichTextBoxes are similar to TextBoxes but they provide some advanced features over the standard TextBox. RichTextBox allows formatting the text, say adding colors, displaying particular font types and so on. The RichTextBox, like the TextBox is based on the TextBoxBase class which is based on the Control class. These RichTextBoxes came into existence because many word processors these days allow us to save text in a rich text format. With RichTextBoxes we can also create our own word processors. We have two options when accessing text in a RichTextBox, text and rtf (rich text format). Text holds text in normal text and rtf holds text in rich text format.
The text within the control can be assigned character and paragraph formatting. The SelectionFont property enables you to make text bold or italic. You can also use this property to change the size and typeface of the text. The SelectionColor property enables you to change the color of the text. To create bulleted lists you can use the SelectionBullet property. You can also adjust paragraph formatting by setting the SelectionIndent, SelectionRightIndent, and SelectionHangingIndent properties. The RichTextBox control provides methods that provide functionality for opening and saving files. The LoadFile method enables you to load an existing RTF or ASCII text file into the control.
RichTextBox1.SelectionStart = RichTextBox1.Find("are") 'using the Find method to find the text "are" and setting it's return 'property to SelectionStart which selects the text RichTextBox1.SelectionColor = Color.Blue 'setting the color for the selected text with SelectionColor property RichTextBox1.SelectionStart =RichTextBox1.Find("working") RichTextBox1.SelectionColor = Color.Yellow
End Sub
References
http://www.dotnetperls.com/tooltip http://www.devasp.net/net/articles/display/367 .html