Add custom properties to controls at runtime

  • Thread starter Thread starter neilsanner
  • Start date Start date
N

neilsanner

Hi,

I would like to add two or three custom properties to some textboxes
and comboboxes controls at runtime.

Any ideas on how to do this?

NeilSanner
 
Neil,

At runtime is your textbox and your combobox an object, not a class.

You can only add properties to a class, so therefore you have first to make
your own combobox and textbox classes by inheriting the originals.

I hope this helps,

Cor
 
That's a great idea if I ever want to be able to edit the properties at
design time! Thanks!

I found a workaround for adding properties to a control at runtime
using the tag property and the HashTable object:

Dim ht As New Hashtable
ht.Add("Optional", True)
ht.Add("WhereInRegistry",_
"HKEY_CURRENT_USER\Software\MySoft\Settings\Paths\\BitmapsFolder")
TextBox_Folder_Clients.Tag = ht
MsgBox(TextBox_Folder_Bitmaps.Tag("Optional").ToString)
MsgBox(TextBox_Folder_Bitmaps.Tag("WhereInRegistry").ToString)

It's almost as using a custom property!!

Cheers!
NeilSanner
 
Way better to do the clone method before storing into the t:

Instead of this: TextBox_Folder_Clients.Tag = ht
This: TextBox_Folder_Clients.Tag = ht.clone

NeilSanner
 
Back
Top