簡體   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