[ Pobierz całość w formacie PDF ]
.EndEnd ClassClassIn previous versions of Visual Basic, you can create enhanced versions of anexisting control by placing an instance of the control on the UserControldesigner.You can then create public properties, methods, and events thatcorrespond to the equivalent items of the constituent control, adding any customitems to create your enhanced behavior.In Visual Basic.NET, you can create a control that inherits from anySystem.Windows.Forms class, such as the TextBox or Label class.Becausethis approach uses inheritance, there is no need to create public properties,methods, and events that map to the constituent control.This greatly reducesthe amount of code required.You only need to create any extra functionality, asdescribed for user controls in the previous topic.The following example shows how to create a control that inherits fromSystemWindows.Forms and adds a public property:Public Class MyTextBoxInherits System.Windows.Forms.TextBoxPrivate strData As StringPublic Property HiddenData( ) As StringGetReturn strDataEnd GetSet(ByVal Value As String)strData = ValueEnd SetEnd Property.End Class Module 9: Developing Components in Visual Basic.NET 45This code creates a new control that inherits all of the TextBox classfunctionality and adds a property called HiddenData.Note For some existing controls, you can create a new graphical front end byoverriding the OnPaint method of the base class.However, some controls, suchas the TextBox control, are painted directly by Windows and cannot beoverridden. 46 Module 9: Developing Components in Visual Basic.NETProviding Control AttributesTopic ObjectiveTo explain how to useSystem.ComponentModel Provides Control Attributescontrol attributes.Class Level  DefaultProperty, DefaultEvent,Lead-inToolboxBitmapControl attributes can beused to supply extraProperty Level  Category, Description, DefaultValueinformation about the controland its properties, methods,ImportsImports System.ComponentModelSystem.ComponentModeland events.PublicPublic Class MyTextBoxClass MyTextBoxInheritsInherits System.Windows.Forms.UserControlSystem.Windows.Forms.UserControl_PublicPublic Property HiddenData( ) As StringProperty HiddenData( ) As String.EndEnd PropertyProperty.EndEnd ClassClassIn previous versions of Visual Basic, you can use the Procedure Attributesdialog box to set control attributes, such as property descriptions and theircategories, which can be viewed in the Object Browser.You can supply similarinformation in Visual Basic.NET by using the attributes provided by theSystem.ComponentModel namespace.Setting Class-level AttributesYou can specify several attributes for the control, including DefaultProperty,DefaultEvent, and ToolboxBitmap.The following example shows how to setthe ToolboxBitmap and DefaultEvent attributes for the MyTextBox class:_Public Class MyTextBoxInherits System.Windows.Forms.UserControl.End Sub Module 9: Developing Components in Visual Basic.NET 47Setting Property-level AttributesYou can specify property-level attributes for any public properties, includingthe Category, Description, and DefaultValue attributes.The followingexample shows how to set these attributes for the HiddenData property:Imports System.ComponentModelPublic Class MyTextBoxInherits System.Windows.Forms.UserControl_Public Property HiddenData( ) As String.End Property.End Class 48 Module 9: Developing Components in Visual Basic.NETDemonstration: Creating an Enhanced TextBoxTopic ObjectiveTo demonstrate how tocreate a control based on anexisting Windows Formscontrol.Lead-inIn this demonstration, youwill learn how to create acontrol based on theWindows Forms TextBoxcontrol.In this demonstration, you will learn how to create a Windows Forms userDelivery Tipcontrol based on the existing TextBox.The step-by-stepinstructions for thisdemonstration are in theinstructor notes for thismodule. Module 9: Developing Components in Visual Basic.NET 49Creating Web Forms User ControlsTopic ObjectiveTo provide an overview ofthe topics covered in thislesson.Extending Existing ControlsLead-inCreating Web User ControlsThis lesson examines howto create Web Forms usercontrols inVisual Basic.NET [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • funlifepok.htw.pl
  •