2017-06-25 1 views
1
eingeben

ich diesen Code geschrieben, wenn ich auf Textfeld Auswahl char klicken oder konzentrieren wird markieren, aber während ich (Edit) Highlight eingeben kann nicht zeigen (Textbox hat Standard-Text)C# beleuchten aktuelle Zeichen in Textfeld während

 textBox1.GotFocus += textbox1_OnFocus; 

    private void textBox1_KeyPress(object sender, KeyPressEventArgs e) 
    { 
     if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.')) 
     { 
      e.Handled = true; 
     } 

     // only allow one decimal point 
     if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1)) 
     { 
      e.Handled = true; 
     } 

     textBox1.SelectionStart = textBox1.SelectionStart; 
     textBox1.SelectionLength = 1; 

    } 

    private void textbox1_OnFocus(object sender, EventArgs e) 
    { 
     textBox1.Focus(); 
     textBox1.SelectionStart = 0 ; 
     textBox1.SelectionLength = 1; 

    } 

    private void textBox1_MouseClick(object sender, MouseEventArgs e) 
    { 
     listBox1.Items.Add(textBox1.SelectionStart); 
     textBox1.SelectionStart = textBox1.SelectionStart; 
     textBox1.SelectionLength = 1; 
    } 

Wie kann ich meinen Code bearbeiten, um meine richtige Antwort zu erhalten?

Antwort

0

Ich schrieb dieses es Arbeit, aber ich denke, das

 private void textBox1_KeyUp(object sender, KeyEventArgs e) 
    { 
     textBox1.SelectionStart = textBox1.SelectionStart; 
     textBox1.SelectionLength = 1; 
    } 
nicht guter Weg ist,