I have the code that generates the textBox therefore can not give properties one by one. TextBox need you in it can only enter numbers, try the KeyPress but I can not assign it:
I managed to define some properties as follows:
tableLayoutPanel1.Controls [a * size+ b].enabled = false;
tableLayoutPanel1.Controls [a * size + b]= Color.FromArgb.BackColor (255, 255, 153);
tableLayoutPanel1.Controls [a + b * size].font = new Font(tableLayoutPanel1.Controls [a + b * size].font, FontStyle.Bold);
But a "Global" event for me textBox generated was impossible. Besides I need the textAlign, I tried as follows:
tableLayoutPanel1.TextAlign = ContentAlignment.MiddleCenter
But I do not recognize the "TextAlign".
So they are relatively simple questions but has spent my time trying everything :(
PD: My Event KeyPress is:
private void keyPress(object sender, KeyPressEventArgs e)
{
if (((e.KeyChar) < 48 && e.KeyChar != 8) || e.KeyChar > 57)
{
e.Handled = true;
}
}
But i cant asigned it to the generated textBox, thanks!
private void Txt_KeyPress(object sender, KeyPressEventArgs e)
{
if (((e.KeyChar) < 48 && e.KeyChar != 8) || e.KeyChar > 57)
{
e.Handled = true;
}
}
private void Form1_Load(object sender, EventArgs e)
{
TextBox txt = new TextBox();
txt.KeyPress += Txt_KeyPress; // attach event handler to textbox created at runtime.
tableLayoutPanel1.Controls.Add(txt);
}
If the above code not solving your problem, just comment with explanation. Cheers !
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.