Posted by: Sourav | September 2, 2016

Using Reflection in GUI using VB,VB Teacher Sourav,Kolkata 09748184075


I have 3 listbox,1 textbox and 1 button in a form

the button click event is like this

 

Private Sub Click_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClickMe.Click
ListBox1.Items.Clear()
ListBox2.Items.Clear()
ListBox3.Items.Clear()
Dim typename As String = TextBox1.Text

Dim t As Type = Type.GetType(typename)

‘Console.WriteLine(“The full name of the class by reflection ” + t.FullName)
‘Console.WriteLine(“Just the name of the class by reflection ” + t.Name)
‘Console.WriteLine(“The namespace of the class by reflection ” + t.Namespace)
‘Console.WriteLine(“The properties of the class by reflection “)
Dim properties() As PropertyInfo = t.GetProperties()
For Each propertyelem As PropertyInfo In properties

ListBox1.Items.Add(propertyelem.PropertyType.Name & ” ” & propertyelem.Name)

Next
‘Console.WriteLine(“The methods of the class by reflection “)
Dim methods() As MethodInfo = t.GetMethods()
For Each method As MethodInfo In methods

ListBox2.Items.Add(method.ReturnType.Name & ” ” & method.Name)

Next

Console.WriteLine(“The constructors of the class by reflection “)
Dim constructors() As ConstructorInfo = t.GetConstructors()
For Each constructor As ConstructorInfo In constructors

ListBox3.Items.Add(constructor.ToString)

Next

End Sub

 

I also added a class named customer

 

Public Class customer
Private id As Integer
Private name As String
Public Property manipulateid(ByVal id As Integer) As Integer
Get
Return Me.id

End Get
Set(ByVal value As Integer)
Me.id = value

End Set
End Property
Public Property manipulatename(ByVal name As String) As String
Get
Return Me.name

End Get
Set(ByVal value As String)
Me.name = value

End Set
End Property
Sub New()
Me.id = -1
Me.name = String.Empty

End Sub
Sub New(ByVal id As Integer, ByVal name As String)
Me.id = id
Me.name = name

End Sub
Public Sub printid()
Console.WriteLine(“ID= {0}”, Me.id)

End Sub
Public Sub printname()
Console.WriteLine(“Name= {0}”, Me.name)

End Sub
End Class

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: