繁体   English   中英

C#中的TableLayoutPanel

[英]TableLayoutPanel in c#

我有生成textBox的代码,因此无法一一给出属性。 文本框需要您在其中只能输入数字,请尝试使用KeyPress,但我无法为其分配:

我设法定义了一些属性,如下所示:

  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);

但是对于我来说,生成一个“全局”事件textBox是不可能的。 除了我需要textAlign外,我还尝试如下:

tableLayoutPanel1.TextAlign = ContentAlignment.MiddleCenter

但是我不认识“ TextAlign”。

因此,它们是相对简单的问题,但是花了我很多时间来尝试:(

PD:我的事件KeyPress是:

    private void keyPress(object sender, KeyPressEventArgs e)
    {
        if (((e.KeyChar) < 48 && e.KeyChar != 8) || e.KeyChar > 57)
        {
            e.Handled = true;
        }
    }

但我不能将其分配给生成的textBox,谢谢!

    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);
    }

如果以上代码不能解决您的问题,请在注释中加上说明。 干杯!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM