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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:56:26+00:00 2026-06-11T01:56:26+00:00

Ok, this one’s easy for you guys, I basically have a C# winform app,

  • 0

Ok, this one’s easy for you guys, I basically have a C# winform app, all it has is a RichTextBox, and there’s a class called Terminal, inside that class there’s a RichTextBox data memeber and some other things, I pass the RichTextBox of my form to the constructor of Terminal, like this:

public Terminal(RichTextBox terminalWindow)
{
  this.terminalWindow = terminalWindow;
  CommandsBuffer = new List<string>();
  currentDirectory = homeDirectory;
  this.terminalWindow.TextChanged += new EventHandler(terminalWindow_TextChanged);
  InsertCurrentDirectory();
}

this is what I’m doing in the InsertCurrentDirectory() method:

private void InsertCurrentDirectory()
{
  terminalWindow.Text = terminalWindow.Text.Insert(0, currentDirectory);
  terminalWindow.Text = terminalWindow.Text.Insert(terminalTextLength, ":");
  terminalWindow.SelectionStart = terminalTextLength + 1;
}

As you can see I’ve registered the event before calling this method, but the problem is, the event is not firing even though I’m changing the text from inside this method.
But it actually fired when I changed the text in the constructor right after registering the event, like this for example:

public Terminal(RichTextBox terminalWindow)
{
  // ...  
  this.terminalWindow.TextChanged += new EventHandler(terminalWindow_TextChanged);
  this.terminalWindow.Text = "the event fired here"; 
}

This is the TextChanged event just in case you wanna know what’s in it:

void terminalWindow_TextChanged(object sender, EventArgs e)
{
  terminalTextLength = terminalWindow.Text.Length;
}

why did this happen? why didn’t the event fire from inside the method? how can i fire it?

Thanks.

  • 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-11T01:56:27+00:00Added an answer on June 11, 2026 at 1:56 am

    Probably you create your Terminal class inside your form constructor (After the InitializeComponenet).
    At this point in time the form handle and all the handles for your controls exist only in the framework infrastucture, but not in the windows system and thus no message (TextChanged) will be fired.

    If you create your Terminal class inside the Form_Load event the TextChanged of the RichTextBox will be called without problems.

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

Sidebar

Related Questions

This one has us all baffled at work. We have two services running on
This one has me perplexed. I have a web app that does many functions,
This one has been driving me nuts. I have a div that has it's
This one should be easy, I think. I have a paginated image gallery, and
This one has me stumped. #!/bin/ksh AWKSCRIPT='END { print all done; }' OUTPUT=`echo hello
This one really has me. I have this validation in my user model: validates
This one has me beat; I have a WPF window with two (important for
This one has me stumped. Is it possible at all to change the background
This one has been bugging me for a while now. Is there a way
This one has me puzzled. It seemed like an easy task, but the solution

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.