public partial class MultiTexbox_2 : Window
{
Control texbox_full_details = null; //get all textbox property and method in when gotfocused
Control button_full_details; //get all button property and method in when click event
Button keyboard_button; //behave like button
public MultiTexbox_2()
{
this.InitializeComponent();
// Insert code required on object creation below this point.
}
private void btn_a_Click(object sender, RoutedEventArgs e)
{
button_full_details = (Control)sender;
all_in_one();
//var caretIndex = txt_diplay_1.CaretIndex;
//txt_diplay_1.Text = txt_diplay_1.Text.Insert(caretIndex, btn_a.Content.ToString());
//txt_diplay_1.Focus();
//txt_diplay_1.CaretIndex = caretIndex + 1;
}
private void btn_b_Click(object sender, RoutedEventArgs e)
{
button_full_details = (Control)sender;
all_in_one();
}
private void btn_c_Click(object sender, RoutedEventArgs e)
{
button_full_details = (Control)sender;
all_in_one();
}
private void txt_diplay_1_GotFocus(object sender, RoutedEventArgs e)
{
texbox_full_details = (Control)sender;
}
private void txt_diplay_2_GotFocus(object sender, RoutedEventArgs e)
{
texbox_full_details = (Control)sender;
}
public void all_in_one()
{
keyboard_button = button_full_details as Button;
if (texbox_full_details != null)
{
//TextBox tb = texbox as TextBox;
//tb.Text += btn.Content;
TextBox txt_box = texbox_full_details as TextBox;
var caret_index = txt_box.CaretIndex;
txt_box.Text = txt_box.Text.Insert(caret_index, keyboard_button.Content.ToString());
txt_box.Focus();
txt_box.CaretIndex = caret_index + 1;
}
}
}
它的输出将是这样的
但需要这样的输出
单击按钮时,它的内容将绑定在文本框中。此时当前绑定的文本框文本的背景颜色、字体颜色和字体大小应该改变。我应该怎么做才能得到那种输出。请帮帮我。