Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 503131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:21:46+00:00 2026-05-13T06:21:46+00:00

How to get caret position (x, y) in the visible client zone in TextBox

  • 0

How to get caret position (x, y) in the visible client zone in TextBox control? I need to add an auto complete feature to the text box.

I’ve found solution for WPF, but it can’t be applied in Silverlight.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:21:46+00:00Added an answer on May 13, 2026 at 6:21 am
    public class AutoCompleteTextBox : TextBox
    {
        public Point GetPositionFromCharacterIndex(int index)
        {
            if (TextWrapping == TextWrapping.Wrap) throw new NotSupportedException();
    
            var text = Text.Substring(0, index);
    
            int lastNewLineIndex = text.LastIndexOf('\r');
    
            var leftText = lastNewLineIndex != -1 ? text.Substring(lastNewLineIndex + 1) : text;
    
            var block = new TextBlock
                            {
                                FontFamily = FontFamily,
                                FontSize = FontSize,
                                FontStretch = FontStretch,
                                FontStyle = FontStyle,
                                FontWeight = FontWeight
                            };
    
            block.Text = text;
            double y = block.ActualHeight;
    
            block.Text = leftText;
            double x = block.ActualWidth;
    
            var scrollViewer = GetTemplateChild("ContentElement") as ScrollViewer;
    
            var point = scrollViewer != null
                            ? new Point(x - scrollViewer.HorizontalOffset, y - scrollViewer.VerticalOffset)
                            : new Point(x, y);
            point.X += BorderThickness.Left + Padding.Left;
            point.Y += BorderThickness.Top + Padding.Top;
    
            return point;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get the caret position inside text area (Internet Explorer only). I
How to get / set caret position in silverlight textbox ?
I am trying to get the caret position for some text inside an iframe
How do you get the caret position in a <textarea> using JavaScript? For example:
How can I get the caret position from within an input field? I have
How can I get the caret's position in a textarea using jQuery? I'm looking
Say I have a string text, a caret position caret and then want to
I get a URL from a user. I need to know: a) is the
I'm toying with the idea for my text input box of clicking on a
With this code I can check the caret position in a textarea in firefox:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.