name property???

  • Thread starter Thread starter e-mid
  • Start date Start date
E

e-mid

where is the name property!?

i create controls dynamically in a loop, but i cant give them name!,

how can seperate them then?
 
william; what i do is something like this:

for(int i = 0 ; i< 3 ;i++)
{
TextBox myTx = new Textbox();
myTx.Location = new Point(8, 8+(30*i))
panel1.Controls.Add(myTx);

}
//Now There is 3 textboxes on the panel, but i cant know which is which cos
i cant name them
 
Well, there's always the easy way ;-). Compile this into a Class Library
and you can use it w/ VB.NET or C#: Just create an instance of the
subclassed control and set ControlName as you create them. You can also
override the Name property but I just called it ControlName for the sake of
clarity.

using System;

using System.Data;

using System.Windows.Forms;

namespace ControlLib

{

/// <summary>

/// Summary description for Class1.

/// </summary>

public class NewTextBox: System.Windows.Forms.TextBox

{

private string _ControlName;

public string ControlName

{

get{return _ControlName;}

set{_ControlName = value;}

}

public NewTextBox(){}

public NewTextBox(string name)

{

this.ControlName = name;


}

}

}


--

W.G. Ryan, eMVP

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
 
thknz William, good idea :-)

William Ryan eMVP said:
Well, there's always the easy way ;-). Compile this into a Class Library
and you can use it w/ VB.NET or C#: Just create an instance of the
subclassed control and set ControlName as you create them. You can also
override the Name property but I just called it ControlName for the sake of
clarity.

using System;

using System.Data;

using System.Windows.Forms;

namespace ControlLib

{

/// <summary>

/// Summary description for Class1.

/// </summary>

public class NewTextBox: System.Windows.Forms.TextBox

{

private string _ControlName;

public string ControlName

{

get{return _ControlName;}

set{_ControlName = value;}

}

public NewTextBox(){}

public NewTextBox(string name)

{

this.ControlName = name;


}

}

}


--

W.G. Ryan, eMVP

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
 
Back
Top