dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Events change RichTextBox does not work ?

  1. #1
    Join Date
    Sep 2007
    Posts
    318

    Events change RichTextBox does not work ?

    Drag and drop in form in the Form_Load RichTextBox and his running assign content for events RichTextBox_TextChanged RichTextBox but not running although I have to add this line of code:
    this.RichTextBox.TextChanged + = new System.EventHandler (this.RichTextBox_TextChanged);
    before Form_Load
    Code:
    private void RichTextBox_TextChanged (object sender, System.EventArgs e)
    {
    **** do something ...
    }
    as an example of his small examples on running normally, but in the main program will not run, I do not know what is not right? What advice can you help me fix this.
    Last edited by 2kaud; February 22nd, 2017 at 07:15 AM. Reason: Fixed code tags

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,033

    Re: Events change RichTextBox does not work ?

    Quote Originally Posted by dongtrien View Post
    Drag and drop in form in the Form_Load RichTextBox and his running assign content for events RichTextBox_TextChanged RichTextBox but not running although I have to add this line of code:
    this.RichTextBox.TextChanged + = new System.EventHandler (this.RichTextBox_TextChanged);
    before Form_Load
    I usually find it helpful when learning this basic forms stuff to leverage the tools built into Visual Studio as much as possible. You see, Visual Studio has a forms designer that allow you to add controls to a form and quickly wire up events. If you are one of those guys that don't like to use the built-in tools and have the need to do things manually, then you can use the tools, see how it's done by looking at the generated code and then you'll know how to do it afterwards.

    To answer your question, I first created a sample forms project.
    1) Then I used the Toolbar view to drag a RichTextBox control onto the form.
    2) In the properties page, I renamed the default "richTextBox1" name to "_richTextBox1". Note that the default control name was not "RichTextBox" like you had - that's the name of the class, not the instance (naming an instance of the control with its class name causes confusion.

    Here's what it looks like:
    Name:  Properties.jpg
Views: 12
Size:  21.2 KB

    3) Next, click on the little lightning bolt icon to switch to the events view.
    See the icon circled in red and notice the highlighted TextChanged entry near the bottom:
    Name:  Properties_Events.jpg
Views: 12
Size:  23.4 KB

    4) To add an event handler, simply double-click on the event. Notice how the event handler appears next to the event?
    Name:  Properties_Event1.jpg
Views: 12
Size:  22.4 KB

    That's it. If you like you can go in and manually look at the forms.designer.cs file to see the event entries. But manually changing this file can corrupt the file and then you won't be able to open the form (like in your other post).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)