簡體   English   中英

如何更改一行中的文本框屬性?

[英]How can I change textbox properties in a line?

我想在一行中更改fontweight屬性。

TextBox.Foreground = Brushes.Blue;
TextBox.FontWeight = FontWeights.Bold;
TextBox.Text += "Send\t:\t";

TextBox.FontWeight = FontWeights.Normal;
TextBox.Text += (MsgTextBox.Text+"\n");

但是以前的fontweight更改不起作用。

結果圖像

我怎么解決這個問題?

其實我想知道TextBox何時更新。

謝謝。

這是一個示例,如何使用textblock做到這一點

                public TextBlockCodeBehindSample()
            {
                    InitializeComponent();
                    TextBlock tb = new TextBlock();
                    tb.TextWrapping = TextWrapping.Wrap;
                    tb.Margin = new Thickness(10);
                    tb.Inlines.Add("An example on ");
                    tb.Inlines.Add(new Run("the TextBlock control ") { FontWeight = FontWeights.Bold });
                    tb.Inlines.Add("using ");
                    tb.Inlines.Add(new Run("inline ") { FontStyle = FontStyles.Italic });
                    tb.Inlines.Add(new Run("text formatting ") { Foreground = Brushes.Blue });
                    tb.Inlines.Add("from ");
                    tb.Inlines.Add(new Run("Code-Behind") { TextDecorations = TextDecorations.Underline });
                    tb.Inlines.Add(".");
                    this.Content = tb;
            }

看起來像

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM