Autor Beitrag
tomycat
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Mo 27.02.17 20:34 
Hallo,
Ich habe 10 Button mit der Beschreiftung 1,2,3...0

Dann habe ich 3 Textboxen A,B,C

Ich habe einen Touchscreen Monitor. Ich klicke auf A und danach drei mal auf 5, dann soll 555 in der Textbox A drin sein.
Meine Lösung:
ausblenden C#-Quelltext
1:
meinetextboxA.Text += "5";					

Blöd ist es, wenn ich etwas in B oder C reinschreiben möchte.

Idee A
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
if(meinetextboxA.Focus())
   meinetextboxA.Text += "5";

if(meinetextboxB.Focus())
   meinetextboxB.Text += "5";

if(meinetextboxC.Focus())
   meinetextboxC.Text += "5";

geht aber nicht :-(

Moderiert von user profile iconTh69: C#-Tags hinzugefügt
Moderiert von user profile iconTh69: Topic aus C# - Die Sprache verschoben am Mo 27.02.2017 um 19:57
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 27.02.17 21:04 
Merke dir beim Fokus (Control.GotFocus) auf eine TextBox die entsprechende TextBox in einer (Member-)Variablen:
ausblenden C#-Quelltext
1:
2:
3:
4:
void textbox_GotFocus(object sender, EventArgs e)
{
    lastFocusedTextBox = sender as TextBox;
}

Und greife darauf dann in den Button_Clicked-Methoden zu:
ausblenden C#-Quelltext
1:
lastFocusedTextBox.Text += "5";					


PS: Nicht wundern, ich habe deinen selbst-zitierten Beitrag gelöscht und dafür im ersten Beitrag die C#-Tags hinzugefügt.
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4700
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Mo 27.02.17 23:26 
Alternative. Sorge dafür das deine Buttons selbst keinen Focus haben können und sende dann das Zeichen des Buttons einfach an das aktive Control.
Etwa
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
// Button ohne Focus
public class UnfocusableButton : System.Windows.Forms.Button
{
    public UnfocusableButton()
    {
        SetStyle(ControlStyles.Selectable, false);
    }
}


ausblenden C#-Quelltext
1:
2:
3:
4:
private void MyLovelyUnfocusableButtonForValueFive_Click(object sender, EventArgs e)
{
    ActiveControl.Text += "5";
}