<small id='yirYt'></small><noframes id='yirYt'>

    <i id='yirYt'><tr id='yirYt'><dt id='yirYt'><q id='yirYt'><span id='yirYt'><b id='yirYt'><form id='yirYt'><ins id='yirYt'></ins><ul id='yirYt'></ul><sub id='yirYt'></sub></form><legend id='yirYt'></legend><bdo id='yirYt'><pre id='yirYt'><center id='yirYt'></center></pre></bdo></b><th id='yirYt'></th></span></q></dt></tr></i><div id='yirYt'><tfoot id='yirYt'></tfoot><dl id='yirYt'><fieldset id='yirYt'></fieldset></dl></div>
    • <bdo id='yirYt'></bdo><ul id='yirYt'></ul>
      <legend id='yirYt'><style id='yirYt'><dir id='yirYt'><q id='yirYt'></q></dir></style></legend>
    1. <tfoot id='yirYt'></tfoot>
    2. 如何在没有 NoWrap 的 TextBox 中跟随文本的结尾?

      时间:2023-06-10
      <legend id='EXmg7'><style id='EXmg7'><dir id='EXmg7'><q id='EXmg7'></q></dir></style></legend>
    3. <tfoot id='EXmg7'></tfoot>

          <i id='EXmg7'><tr id='EXmg7'><dt id='EXmg7'><q id='EXmg7'><span id='EXmg7'><b id='EXmg7'><form id='EXmg7'><ins id='EXmg7'></ins><ul id='EXmg7'></ul><sub id='EXmg7'></sub></form><legend id='EXmg7'></legend><bdo id='EXmg7'><pre id='EXmg7'><center id='EXmg7'></center></pre></bdo></b><th id='EXmg7'></th></span></q></dt></tr></i><div id='EXmg7'><tfoot id='EXmg7'></tfoot><dl id='EXmg7'><fieldset id='EXmg7'></fieldset></dl></div>

          <small id='EXmg7'></small><noframes id='EXmg7'>

            <tbody id='EXmg7'></tbody>
            • <bdo id='EXmg7'></bdo><ul id='EXmg7'></ul>

              • 本文介绍了如何在没有 NoWrap 的 TextBox 中跟随文本的结尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在 xaml 中有一个文本框:

                <文本框名称=文本";HorizontalAlignment =左"高度=75"VerticalContentAlignment =中心"TextWrapping =NoWrap"文本=文本框"宽度=336"BorderBrush =黑色"字体大小=40"/>

                我用这个方法给它添加文字:

                private string words = "TextBox 的初始文本内容.";公共异步无效文本旋转(){for(int a =0; a < words.Length; a++){Text.Text = words.Substring(0,a);等待任务.延迟(500);}}

                一旦文本脱离包装,有一种方法可以聚焦结尾,使旧文本消失在左侧,新文本消失在右侧,而不是仅仅将其添加到右侧而不看到.

                解决方案

                一种快速的方法是测量需要滚动的字符串(words)

                I have a TextBox in xaml:

                <TextBox Name="Text" HorizontalAlignment="Left" Height="75"   VerticalContentAlignment="Center" TextWrapping="NoWrap" Text="TextBox" Width="336"  BorderBrush="Black" FontSize="40" />
                

                I add text to it with this method:

                private string words = "Initial text contents of the TextBox.";
                
                public async void textRotation()
                {
                    for(int a =0; a < words.Length; a++)
                    {
                        Text.Text = words.Substring(0,a);
                        await Task.Delay(500);
                    }
                }
                

                Once the text goes of out of the wrap is there a way to focus the end so the old text disappears to the left and the new on the right, as opposed to just adding it to the right without seeing.

                解决方案

                A quick method is to measure the string (words) that needs scrolling with TextRenderer.MeasureText, divide the width measure in parts equals to the number of chars in the string and use ScrollToHorizontalOffset() to perform the scroll:

                public async void textRotation()
                {
                    float textPart = TextRenderer.MeasureText(words, new Font(Text.FontFamily.Source, (float)Text.FontSize)).Width / words.Length;
                    for (int i = 0; i < words.Length; i++)
                    {
                        Text.Text = words.Substring(0, i);
                        await Task.Delay(100);
                        Text.ScrollToHorizontalOffset(textPart * i);
                    }
                }
                

                Same, but using the FormattedText class to measure the string:

                public async void textRotation()
                {
                    var textFormat = new FormattedText(
                        words, CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight,
                        new Typeface(this.Text.FontFamily, this.Text.FontStyle, this.Text.FontWeight, this.Text.FontStretch),
                        this.Text.FontSize, null, null, 1);
                
                    float textPart = (float)textFormat.Width / words.Length;
                    for (int i = 0; i < words.Length; i++)
                    {
                        Text.Text = words.Substring(0, i);
                        await Task.Delay(200);
                        Text.ScrollToHorizontalOffset(textPart * i);
                    }
                }
                

                这篇关于如何在没有 NoWrap 的 TextBox 中跟随文本的结尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何设置文本框 textmode=date ASP.NET C# 的值 下一篇:asp:TextBox ReadOnly=true 还是 Enabled=false?

                相关文章

                <legend id='r436u'><style id='r436u'><dir id='r436u'><q id='r436u'></q></dir></style></legend>

              • <i id='r436u'><tr id='r436u'><dt id='r436u'><q id='r436u'><span id='r436u'><b id='r436u'><form id='r436u'><ins id='r436u'></ins><ul id='r436u'></ul><sub id='r436u'></sub></form><legend id='r436u'></legend><bdo id='r436u'><pre id='r436u'><center id='r436u'></center></pre></bdo></b><th id='r436u'></th></span></q></dt></tr></i><div id='r436u'><tfoot id='r436u'></tfoot><dl id='r436u'><fieldset id='r436u'></fieldset></dl></div>
                <tfoot id='r436u'></tfoot>

                      <bdo id='r436u'></bdo><ul id='r436u'></ul>
                  1. <small id='r436u'></small><noframes id='r436u'>