zoukankan      html  css  js  c++  java
  • WPF文本框TextBox获取输入位置坐标

    方法一、

     public Point GetPositionFromCharacterIndex(TextBox txtContent)
            {
                int lastIndex = txtContent.GetLastVisibleLineIndex();
                int firstIndex = txtContent.GetFirstVisibleLineIndex();
                int rowCount = lastIndex - firstIndex;
                string lineVal = txtContent.GetLineText(lastIndex);
                Typeface typeface = new Typeface(txtContent.FontFamily,
                 txtContent.FontStyle,
                 txtContent.FontWeight,
                 txtContent.FontStretch);
                FormattedText formattedText = new FormattedText(lineVal,
                    CultureInfo.CurrentCulture,
                    FlowDirection.LeftToRight,
                    typeface, txtContent.FontSize, txtContent.Background);
                double X = 0d;
                double Y = 0d;
                if (lastIndex > 0)
                {
                    X = formattedText.Width;
                    Y = rowCount * formattedText.Height > txtContent.ActualHeight ? (txtContent.ActualHeight - pp.Height - formattedText.Height) : ((rowCount - 1) * formattedText.Height - pp.Height);
                }
                else
                {
                    X = formattedText.Width;
                    Y = -pp.Height;
                }
                Point point = new Point(X, Y);
                return point;
            }
    

      方法二、

            [DllImport("user32")]
            public static extern bool GetCaretPos(out System.Drawing.Point lpPoint);
    

      

  • 相关阅读:
    HDU 1505 & POJ 1964 City Game (递推+扫描法)
    web页面内容优化管理与性能技巧
    POJ2406简单KMP
    poj2418map或者字典树
    poj2418map或者字典树
    POJ2296二分2sat
    POJ2296二分2sat
    poj2186强联通(牛仰慕)
    poj2186强联通(牛仰慕)
    poj2175费用流消圈算法
  • 原文地址:https://www.cnblogs.com/wrl-wuqingxue/p/5625828.html
Copyright © 2011-2022 走看看