Click here to Skip to main content
15,886,072 members
Home / Discussions / C#
   

C#

 
AnswerRe: Showdialog() question Pin
OriginalGriff12-Nov-15 21:36
mveOriginalGriff12-Nov-15 21:36 
GeneralRe: Showdialog() question Pin
randor13-Nov-15 3:14
randor13-Nov-15 3:14 
GeneralRe: Showdialog() question Pin
OriginalGriff13-Nov-15 4:04
mveOriginalGriff13-Nov-15 4:04 
QuestionEvent that fires on existing form when another is selected Pin
Member 1212588812-Nov-15 9:58
Member 1212588812-Nov-15 9:58 
AnswerRe: Event that fires on existing form when another is selected Pin
Richard Andrew x6412-Nov-15 10:12
professionalRichard Andrew x6412-Nov-15 10:12 
AnswerRe: Event that fires on existing form when another is selected Pin
BillWoodruff12-Nov-15 10:57
professionalBillWoodruff12-Nov-15 10:57 
QuestionHow to design a keypad in C#? Pin
naouf1012-Nov-15 9:34
naouf1012-Nov-15 9:34 
AnswerRe: How to design a keypad in C#? Pin
BillWoodruff12-Nov-15 10:40
professionalBillWoodruff12-Nov-15 10:40 
edit #1

All you need to do to keep the Focus on the TextBox Control when a Button is clicked is to set the TextBox 'Capture property to 'true in the Click EventHandler. Example:
C#
private void button1_Click(object sender, EventArgs e)
{
    CurrentTextBox.Text += "A";
    CurrentTextBox.Capture = true;
}
See below for how to keep the 'CurrentTextBox field up to date as the user changes which TextBox they use.


end edit #1

The word "keypad" suggests to me a bunch of Buttons that you click on, and things happen.

I am not clear what you are doing with the TextBoxes here; please clarify.

In WinForms the 'ActiveControl property of the ContainerControl Class will always return which Control has Focus in the ContainerControl (which could be Form, a Panel, etc.) [^].

Control activeFormControl = this.ActiveControl;    // of the Form<br />
Control activePanelControl = panel1.ActiveControl;       // of a Panel

A way I often use to keep track of which of several TextBoxes has Focus currently, or has had Focus most recently is: wire all of them up to the same 'Enter EventHandler, and:
C#
TextBox CurrentTextBox;

private void TextBoxes1To4_Enter(object sender, EventArgs e)
{
    CurrentTextBox = sender as TextBox;

    // remove when testing is complete
    if(CurrentTextBox == null) 
    {
        throw new ArgumentNullException("Illegal use TextBox Enter");
    }

    // example of code that will do something when TextBox is entered
    switch (CurrentTextBox.Name)
    {
        case "textBox1":
            // do something specific to textBox1 getting Focus, being Acive
            // example:
            textBox1.Text = "Entered";
            break;
        case "textBox2":
            break;
        case "textBox3":
            break;
        case "textBox4":
            break;
    }
}

«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.


modified 14-Nov-15 3:56am.

AnswerRe: How to design a keypad in C#? Pin
Gerry Schmitz13-Nov-15 1:37
mveGerry Schmitz13-Nov-15 1:37 
AnswerRe: How to design a keypad in C#? Pin
GrooverFromHolland13-Nov-15 15:40
GrooverFromHolland13-Nov-15 15:40 
GeneralRe: How to design a keypad in C#? Pin
BillWoodruff14-Nov-15 8:39
professionalBillWoodruff14-Nov-15 8:39 
Generalcreating a packet using c# or vb Pin
Member 1140244512-Nov-15 2:52
Member 1140244512-Nov-15 2:52 
GeneralRe: creating a packet using c# or vb Pin
John Torjo12-Nov-15 3:40
professionalJohn Torjo12-Nov-15 3:40 
GeneralRe: creating a packet using c# or vb Pin
Dave Kreskowiak12-Nov-15 3:53
mveDave Kreskowiak12-Nov-15 3:53 
GeneralRe: creating a packet using c# or vb Pin
Member 1140244512-Nov-15 4:44
Member 1140244512-Nov-15 4:44 
GeneralRe: creating a packet using c# or vb Pin
Gerry Schmitz12-Nov-15 6:57
mveGerry Schmitz12-Nov-15 6:57 
Questionin c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
Member 1212766511-Nov-15 23:08
Member 1212766511-Nov-15 23:08 
AnswerRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
Pete O'Hanlon11-Nov-15 23:16
mvePete O'Hanlon11-Nov-15 23:16 
GeneralRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
John Torjo12-Nov-15 2:56
professionalJohn Torjo12-Nov-15 2:56 
GeneralRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
Dave Kreskowiak12-Nov-15 4:10
mveDave Kreskowiak12-Nov-15 4:10 
GeneralRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
Member 1212766512-Nov-15 2:58
Member 1212766512-Nov-15 2:58 
AnswerRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
Richard Andrew x6412-Nov-15 3:08
professionalRichard Andrew x6412-Nov-15 3:08 
AnswerRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
Bernhard Hiller12-Nov-15 4:12
Bernhard Hiller12-Nov-15 4:12 
GeneralRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
BillWoodruff12-Nov-15 5:45
professionalBillWoodruff12-Nov-15 5:45 
AnswerRe: in c#. how to serilialize and deserialize object with object of other classes inside it??? Pin
BillWoodruff12-Nov-15 6:03
professionalBillWoodruff12-Nov-15 6:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.