Control tag as an object

M

Michael Clarke

Hi everyone

I have just started using a common event handler with controls
by using the tag property of the control to store the index.

Now seeing the tag property is an object is there any more overhead involved
if I store my own personal object there?

That way if I ever need to evolve the tag capabilities it will be easier?

I know I can just store a string there ... anyway does anyone have some
better ideas?

I don't like the idea of having to create a new object though for each tag I
am so used
to OOP in VB classic!

private void InitialiseCustom()
{

System.EventHandler btnEh = new System.EventHandler(btnClick);


TagHandler th0 = new TagHandler(0,1001);

this.btn0.Click += btnEh;

this.btn0.Tag = th0;

TagHandler th1= new TagHandler(1,1002);

this.btn1.Click += btnEh;

this.btn1.Tag = th1;


System.EventHandler txtEh = new System.EventHandler(txtChanged);

TagHandler th2 = new TagHandler(0);

this.txt0.TextChanged += txtEh;

this.txt0.Tag = th2;

TagHandler th3 = new TagHandler(1);

this.txt1.TextChanged += txtEh;

this.txt1.Tag = th3;

}
 
R

Ryan Trudelle-Schwarz

Michael Clarke said:
Now seeing the tag property is an object is there any more
overhead involved if I store my own personal object there?

No, there should be less overhead in that case since there is no need to box
/ unbox the object as there is when you store an integer. Mind you, that is
negligable overhead so nothing to worry about.
 

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