Add custom properties to controls at runtime

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
 
C

Cor Ligthert [MVP]

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
 
N

neilsanner

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
 
N

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top