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;
}
}
}
它的輸出會是這樣如何突出文本框在WPF的當前輸入
不過需要這樣
輸出當單擊該按鈕,它的內容將綁定到文本框中。那時,當前綁定的文本框文本的背景色,字體顏色和字體大小應該會改變。我該怎麼做才能得到那種輸出。請幫助我。
但它不是很好。請嘗試我的代碼,然後給我正確的代碼。 –
答案與問題沒有關係(-1)... – GameAlchemist
@VincentPiel我不同意。我們必須以不同的方式閱讀問題。它處理一部分請求。 – kenny