Control tag as an object

  • Thread starter Thread starter Michael Clarke
  • Start date Start date
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;

}
 
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.
 
Back
Top