0

Guys

I have a textbox, I wana enter 4 digit and when I press enter it should show a label I have add the label but its not working the code I have look more like this

if(e.KeyChar == 4)
{
        this.Controls.Add(label);
        e.Handled = true;
}

Any help will be highly Appreciated

Thanx in advance

4
Contributors
5
Replies
6
Views
9 Years
Discussion Span
Last Post by tawadchai
0

Hi,

I wana enter 4 digit

means you have to allow only 4 digits?

or

you mean, when you press '4'
If so, put quote before 4 in

if(e.KeyChar == 4)
if(e.KeyChar == '4')

because u checking the char

0

I mean I wana allow 4 digits that is 1234 then when I press enter the label should be added

0

Then you need to change the keypress value to that of the return key, as well as montior for the length of input to be 4

0
namespace car_radio
{
    public partial class Form1 : Form
    {

        Byte[] data = new byte[1];
        int car;
        int car1;
        
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

        private void button6_Click(object sender, EventArgs e)
        {
            //box color
            button1.BackColor = Color.Black;
            button2.BackColor = Color.Black;
            button3.BackColor = Color.Black;
            button4.BackColor = Color.Black;
            button5.BackColor = Color.Black;
            button6.BackColor = Color.Green;
            button9.BackColor = Color.Black;
            button13.BackColor = Color.Black;
            button14.BackColor = Color.Black;
            button15.BackColor = Color.Black;

            //
            car = 5;
            data[0] = Convert.ToByte(car);
            serialPort1.Write(data, 0, 1);
            textBox1.Text = "รถเดินหน้าเลี้ยวซ้าย";
            label1.Text = "" + car;
        }

Edited by __avd: Added [code] tags.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.