2 Replies - 2006 Views - Last Post: 06 November 2012 - 07:48 AM Rate Topic: -----

#1 James1992   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 132
  • Joined: 30-October 12

How do I change text in a rich text box whilst in another form?

Posted 06 November 2012 - 07:02 AM

Let's say Form1 has a rich text box. You are currently in form2, and you want to communicate with form1's richtextbox. Reason being, I want to do a find and replace.

On form2 I have a find button and 2 combo box's(cboFind and cboReplace).

This is the code I use to find and replace text.

form1.RichTextBox.Text = Replace(RichTextBox.Text, cboFind.Text, cboReplace.Text)


Problem is, I get a blue line underneath the "(RichTextBox.Text," saying,

Reference to a non-shared member requires an object reference. This is because the RichTextBox is actually in a different form. How would I reference it correctly?

Is This A Good Question/Topic? 0
  • +

Replies To: How do I change text in a rich text box whilst in another form?

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: How do I change text in a rich text box whilst in another form?

Posted 06 November 2012 - 07:33 AM

That entire design of reaching into another class like that as evil.
Making the GUI controls public in order to do that is evil.
This comes up a LOT (Like 10 times a week). See FAQ 3.

TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated NOV 2012
Spoiler



Was This Post Helpful? 0
  • +
  • -

#3 James1992   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 132
  • Joined: 30-October 12

Re: How do I change text in a rich text box whilst in another form?

Posted 06 November 2012 - 07:48 AM

Sorted it!

This post has been edited by James1992: 06 November 2012 - 08:00 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1