当前位置: 首页>>代码示例>>C#>>正文


C# TextBox.TransformToVisual方法代码示例

本文整理汇总了C#中Windows.UI.Xaml.Controls.TextBox.TransformToVisual方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.TransformToVisual方法的具体用法?C# TextBox.TransformToVisual怎么用?C# TextBox.TransformToVisual使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.UI.Xaml.Controls.TextBox的用法示例。


在下文中一共展示了TextBox.TransformToVisual方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetTextboxSelectionRect

        // returns a rect for selected text
        // if no text is selected, returns caret location
        // textbox should not be empty
        private Rect GetTextboxSelectionRect(TextBox textbox)
        {
            Rect rectFirst, rectLast;
            if (textbox.SelectionStart == textbox.Text.Length)
            {
                rectFirst = textbox.GetRectFromCharacterIndex(textbox.SelectionStart - 1, true);
            }
            else
            {
                rectFirst = textbox.GetRectFromCharacterIndex(textbox.SelectionStart, false);
            }

            int lastIndex = textbox.SelectionStart + textbox.SelectionLength;
            if (lastIndex == textbox.Text.Length)
            {
                rectLast = textbox.GetRectFromCharacterIndex(lastIndex - 1, true);
            }
            else
            {
                rectLast = textbox.GetRectFromCharacterIndex(lastIndex, false);
            }

            rectFirst.Union(rectLast);

            GeneralTransform transform = textbox.TransformToVisual(null);
            return transform.TransformBounds(rectFirst);
        }
开发者ID:AJ-COOL,项目名称:Windows-universal-samples,代码行数:30,代码来源:Scenario2.xaml.cs

示例2: GetTextboxSelectionRect

        // returns a rect for selected text
        // if no text is selected, returns caret location
        // textbox should not be empty
        private Rect GetTextboxSelectionRect(TextBox textbox)
        {
            Rect rectFirst, rectLast;
            if (textbox.SelectionStart == textbox.Text.Length)
            {
                rectFirst = textbox.GetRectFromCharacterIndex(textbox.SelectionStart - 1, true);
            }
            else
            {
                rectFirst = textbox.GetRectFromCharacterIndex(textbox.SelectionStart, false);
            }

            var lastIndex = textbox.SelectionStart + textbox.SelectionLength;
            if (lastIndex == textbox.Text.Length)
            {
                rectLast = textbox.GetRectFromCharacterIndex(lastIndex - 1, true);
            }
            else
            {
                rectLast = textbox.GetRectFromCharacterIndex(lastIndex, false);
            }

            var buttonTransform = textbox.TransformToVisual(null);
            var point = buttonTransform.TransformPoint(new Point());

            // Make sure that we return a valid rect if selection is on multiple lines
            // and end of the selection is to the left of the start of the selection.
            double x, y, dx, dy;
            y = point.Y + rectFirst.Top;
            dy = rectLast.Bottom - rectFirst.Top;
            if (rectLast.Right > rectFirst.Left)
            {
                x = point.X + rectFirst.Left;
                dx = rectLast.Right - rectFirst.Left;
            }
            else
            {
                x = point.X + rectLast.Right;
                dx = rectFirst.Left - rectLast.Right;
            }

            return new Rect(x, dx, y, dy);
        }
开发者ID:aursad,项目名称:FoxtrotMessageBoard,代码行数:46,代码来源:Settings.xaml.cs

示例3: AnimateShift

        public void AnimateShift(bool reverse, TextBox textBox)
        {
            var page = (Window.Current.Content as Frame).Content as Page;
            page.RenderTransform = new TranslateTransform();

            var upDistance = -textBox.TransformToVisual(page).TransformPoint(new Point(0, 0)).Y + textBox.Margin.Top + 32 - 8;
            var animation = new DoubleAnimation(){
                Duration = new Duration(TimeSpan.FromMilliseconds(250)),
                From = reverse ? upDistance : 0,
                To = reverse ? 0 : upDistance
            };

            Storyboard.SetTarget(animation, page.RenderTransform);
            Storyboard.SetTargetProperty(animation, "Y");

            var storyboard = new Storyboard();
            storyboard.Children.Add(animation);
            storyboard.Begin();
        }
开发者ID:JulianMH,项目名称:music-3,代码行数:19,代码来源:SearchItem.xaml.cs

示例4: GetTextBoxRect

        private Rect GetTextBoxRect(TextBox t)
        {
            Rect temp = t.GetRectFromCharacterIndex(t.SelectionStart, false);

            GeneralTransform transform = t.TransformToVisual(null);
            Point point = transform.TransformPoint(new Point());
            point.X = point.X + temp.X;
            point.Y = point.Y + temp.Y;

            return new Rect(point, new Size(temp.Width, temp.Height));
        }
开发者ID:Jxperez,项目名称:31DaysOfWindows8,代码行数:11,代码来源:MainPage.xaml.cs

示例5: GetTextboxSelectionRect

        // Se crea el Rectangulom y su posición 
        private Rect GetTextboxSelectionRect(TextBox textbox)
        {
            Rect rectFirst, rectLast;
            if (textbox.SelectionStart == textbox.Text.Length)
            {
                rectFirst = textbox.GetRectFromCharacterIndex(textbox.SelectionStart - 1, true);
            }
            else
            {
                rectFirst = textbox.GetRectFromCharacterIndex(textbox.SelectionStart, false);
            }

            int lastIndex = textbox.SelectionStart + textbox.SelectionLength;
            if (lastIndex == textbox.Text.Length)
            {
                rectLast = textbox.GetRectFromCharacterIndex(lastIndex - 1, true);
            }
            else
            {
                rectLast = textbox.GetRectFromCharacterIndex(lastIndex, false);
            }

            GeneralTransform buttonTransform = textbox.TransformToVisual(null);
            Point point = buttonTransform.TransformPoint(new Point());

            double x, y, dx, dy;
            y = point.Y + rectFirst.Top;
            dy = rectLast.Bottom + rectFirst.Top;
            if (rectLast.Right > rectFirst.Left)
            {
                x = point.X + rectFirst.Left;
                dx = rectLast.Right - rectFirst.Left;
            }
            else
            {
                x = point.X + rectLast.Right;
                dx = rectFirst.Left - rectLast.Right;
            }

            return new Rect(x,y,dx,dy);
        }
开发者ID:Zhionit,项目名称:ModernUI,代码行数:42,代码来源:MainPage.xaml.cs


注:本文中的Windows.UI.Xaml.Controls.TextBox.TransformToVisual方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。