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);
    

      

  • 相关阅读:
    MySQL-索引
    MySQL-存储引擎
    MySQL-基本概念
    Elasticsearch-分片原理2
    Elasticsearch-分片原理1
    [NOIP模拟33]反思+题解
    [NOIP模拟测试32]反思+题解
    [NOIP模拟测试31]题解
    [jzoj5840]Miner 题解(欧拉路)
    [NOIP模拟测试30]题解
  • 原文地址:https://www.cnblogs.com/wrl-wuqingxue/p/5625828.html
Copyright © 2011-2022 走看看