Search code examples
c#formsselectbuttonfocus

Get Focus / maintain Selected a TextBox and a Button | C#


Im trying to get the focus like this picture:

https://i.sstatic.net/CkMtH.png

-

So I can have a selected TextBox and Write to it while having aswell the Focus on the Accept button

    private void frm_redimensionar_Load(object sender, EventArgs e)
    {
        if (frm_MonoPaint.Exporto == " ")
        {
            num_amplada.Value = 32;
            num_alcada.Value = 32;
        }
        num_amplada.Focus(); //
        bttn_enviar.Focus(); // 
    }
    private void bttn_cancelar_Click(object sender, EventArgs e)
    {
        Close();
    }
    private void bttn_enviar_Click(object sender, EventArgs e)
    {
        DialogResult = DialogResult.OK;
        Close();
    }
    public int redAlcada()
    {
        return Convert.ToInt32(num_alcada.Value);
    }
    public int redAmplada()
    {
        return Convert.ToInt32(num_amplada.Value);
    }
    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        if (keyData == Keys.Escape)
        {
            this.Close();
            return true;
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }

Solution

  • Well i found the answer to my own question.

     ""this."" AcceptButton = yourbuttonname;
    

    Was a bad title for this post but when you dont know what ur doing it happens. .-.