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 8417287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:59:53+00:00 2026-06-10T01:59:53+00:00

I am making a text editor and I was wondering if there are any

  • 0

I am making a text editor and I was wondering if there are any faster/more reliable ways to do perform these functions. What I have written here is the best I think I can do and might be able to be done, except I have a feeling FirstVisibleLine and LineCount are done but VisibleLines could return faster…?

VisibleLines should return how many lines of text are visible in the text area.
FirstVisibleLine should return the first visible line in the text area
LineCount should return the number of lines in the text area

    private int VisibleLines()
    {
        int topIndex = this.GetCharIndexFromPosition(new Point(0, 0));
        int bottomIndex = this.GetCharIndexFromPosition(new Point(0, this.Height - 1));

        int topLine = this.GetLineFromCharIndex(topIndex);
        int bottomLine = this.GetLineFromCharIndex(bottomIndex);

        return bottomLine - topLine;
    }

    private int FirstVisibleLine()
    {
        return this.GetLineFromCharIndex(this.GetCharIndexFromPosition(new Point(0,0)));
    }

    public int LineCount
    {
        get
        {
            Message msg = Message.Create(this.Handle, EM_VISIBLELINES, IntPtr.Zero, IntPtr.Zero);
            base.DefWndProc(ref msg);
            return msg.Result.ToInt32();
        }
    }
  • 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-06-10T01:59:54+00:00Added an answer on June 10, 2026 at 1:59 am

    You can get the first visible line by sending an message to the text box to get the top line instead of using GetCharIndexFromPosition and GetLineFromCharIndex once. I’m not sure why the TextBox (or TextBoxBase) class doesn’t implement this.

    private const int EM_GETFIRSTVISIBLELINE = 206;
    private int GetFirstVisibleLine(TextBox textBox) 
    {
        return SendMessage(textBox.Handle, EM_GETFIRSTVISIBLELINE, 0, 0);
    }
    

    As for VisibleLines, I think you’ll have to continue calculating bottomLine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making text editor in netbeans and have added jMenuItems called Copy,Cut &
I'm making a fairly simple text editor, and I have a question about my
So I'm making a text editor using Qt and right now I have a
I'm making a simple text editor, and I have a JTextPane and changed the
I am making my own WYSIWYG editor. But i can't make any text bold
I am making my Rich text editor. I have a textarea and an iframe.
hello there i am making a text editor in Tkinter (python) and so i
I am making a text editor using Java swing. I am using JTextArea for
I am making a text based game in Java. I have a text field,
So I decided to have a stab at making a text highlighting system. At

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.