當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。