Professional Documents
Culture Documents
Components in Visual
Basic .NET
Overview
Components Overview
Creating Serviced Components
Creating Component Classes
Creating Windows Forms Controls
Creating Web Forms User Controls
Threading
Components Overview
Types of Components
Using Modules As Components
Using Classes As Components
Using Components in Unmanaged Client Applications
.NET Remoting Overview
Types of Components
Structures
Modules
Classes
Component classes
Serviced components
User controls
Windows Forms user controls
Web Forms user controls
Using Modules As Components
'Client
'Client code
code
Imports MyAssembly
Imports MyAssembly
...
...
Dim
Dim xx As
As Long
Long == Square(20)
Square(20)
Using Classes As Components
'Client
'Client code
code
Imports
Imports MyAssembly
MyAssembly
Dim
Dim xx As
As New
New Account(
Account( ))
x.Debit(1021,
x.Debit(1021, 1000)
1000)
Using Components in Unmanaged Client Applications
Client Code
Formatter
Formatter
Server
Proxy Channel
Server
Object
Marshal By Value
Client Code
Formatter Channel
Server Channel
Object
Copy
Remoting Boundary
Creating Serviced Components
<ObjectPooling(Enabled:=True,
<ObjectPooling(Enabled:=True, MinPoolSize:=5,
MinPoolSize:=5, __
MaxPoolSize:=50)>
MaxPoolSize:=50)> __
Public
Public Class
Class Account
Account
Inherits
Inherits ServicedComponent
ServicedComponent
...
...
Protected
Protected Overrides
Overrides Function
Function CanBePooled(
CanBePooled( )) As
As Boolean
Boolean
Return
Return True
True
End
End Function
Function
End
End Class
Class
Using Constructor Strings
<ConstructionEnabled(True)>Public
<ConstructionEnabled(True)>Public Class
Class Account
Account
Inherits
Inherits ServicedComponent
ServicedComponent
Protected
Protected Overrides
Overrides Sub
Sub Construct(ByVal
Construct(ByVal ss As
As String)
String)
''Called
Called after
after class
class constructor
constructor
''Use
Use passed
passed in
in string
string
End
End Sub
Sub
End
End Class
Class
Using Security
s s
C la
a s e System.ComponentModel.Component
B
IComponent
Interface
ed
r i v s Component Classes
D e l as s e Predefined Classes
C Custom Classes
Creating a Component Class
Imports
Imports System.ComponentModel
System.ComponentModel
<ToolboxBitmap("C:\txticon.ico"),
<ToolboxBitmap("C:\txticon.ico"), DefaultEvent("Click")>
DefaultEvent("Click")> __
Public
Public Class
Class MyTextBox
MyTextBox
Inherits System.Windows.Forms.UserControl
Inherits System.Windows.Forms.UserControl
<Category("Appearance"),
<Category("Appearance"), __
Description("Stores
Description("Stores extra
extra data"),
data"), __
DefaultValue("Empty")>
DefaultValue("Empty")> __
Public
Public Property
Property HiddenData(
HiddenData( )) As
As String
String
...
...
End Property
End Property
...
...
End Class
End Class
Demonstration: Creating an Enhanced TextBox
Creating Web Forms User Controls
<%@
<%@ Control
Control Language="vb"
Language="vb" AutoEventWireup="false"
AutoEventWireup="false"
Codebehind="SimpleControl.ascx.vb"
Codebehind="SimpleControl.ascx.vb"
Inherits="MyApp.SimpleControl"%>
Inherits="MyApp.SimpleControl"%>
<asp:TextBox
<asp:TextBox id="TextBox1"
id="TextBox1" runat="server"></asp:TextBox>
runat="server"></asp:TextBox>
Public
Public MustInherit
MustInherit Class
Class SimpleControl
SimpleControl
Inherits System.Web.UI.UserControl
Inherits System.Web.UI.UserControl
Protected
Protected WithEvents
WithEvents TextBox1
TextBox1 AsAs System.Web.UI.WebControls.TextBox
System.Web.UI.WebControls.TextBox
Public
Public Property
Property TextValue(
TextValue( )) As
As String
String
Get
Get
Return
Return TextBox1.Text
TextBox1.Text
End Get
End Get
Set(ByVal
Set(ByVal Value
Value As
As String)
String)
TextBox1.Text
TextBox1.Text = Value
= Value
End
End Set
Set
End Property
End Property
End
End Class
Class
Demonstration: Creating a Simple Web Forms User
Control
Lab 9.2: Creating a Web Forms User Control
Threading
What Is a Thread?
Advantages of Multithreading
Creating Threads
Using Threading
When to Use Threading
What Is a Thread?
Sub
Sub Test(
Test( ))
Dim
Dim calc
calc AsAs New
New Calculate(
Calculate( ))
Dim
Dim th
th As
As New
New Threading.Thread(AddressOf
Threading.Thread(AddressOf calc.LongCalculation)
calc.LongCalculation)
calc.iValue
calc.iValue == 10
10
AddHandler
AddHandler calc.Complete, AddressOf
calc.Complete, AddressOf CalcResult
CalcResult
th.Start(
th.Start( ))
End
End Sub
Sub
Sub
Sub CalcResult(ByVal
CalcResult(ByVal Result
Result As
As Integer)
Integer)
...
...
End
End Sub
Sub
When to Use Threading
Components Overview
Creating Serviced Components
Creating Component Classes
Creating Windows Forms Controls
Creating Web Forms User Controls
Threading
Course Evaluation