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

  • Home
  • SEARCH
  • 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 7458269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:25:33+00:00 2026-05-29T13:25:33+00:00

so I’m working on a basic notepad program designed to be helpful toward web

  • 0

so I’m working on a basic notepad program designed to be helpful toward web designers. I have a list of different blocks of code that can be pasted into the editor, but I’m having trouble pasting them how I want it. Basically, I’d like to be able to click between two lines (or words, whereever) on the text editor, and be able to paste these blocks where the blinking cursor would be.

Here’s my current code for when one of the pasting options is selected:

public void getCodeBlock(string selection)
{
    string[] codeBlocks = System.IO.File.ReadAllLines(@"blocks\" + selection + ".txt");
    foreach (string codeBlock in codeBlocks)
    {
        int cursorPosition = richTextBox1.SelectionStart;
        string insertText = codeBlock + Environment.NewLine;
        richTextBox1.Text = richTextBox1.Text.Insert(cursorPosition, insertText);
        cursorPosition = cursorPosition + insertText.Length;
    }
}

However, instead of pasting it at the cursor, it completely jumbles up the lines, and sometimes even pastes it from the last line to the first. I have absolutely no idea what I’m doing wrong, and could really use some help.

  • 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-29T13:25:33+00:00Added an answer on May 29, 2026 at 1:25 pm

    It’s this line that is causing the problem:

    cursorPosition = cursorPosition + insertText.Length;
    

    Try this instead:

    richTextBox1.SelectionStart = cursorPosition + insertText.Length -1;
    

    The selection position gets reset to 0 when you change the Text property of the richTextBox1. cursorPosition is your local variable which then takes on the new value the next time through the loop.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.