开发者

How to find text in a richtextbox on another form c#

开发者 https://www.devze.com 2022-12-21 06:45 出处:网络
I have 2 forms, one with containing a richtextbox and the other used for finding text in this rtb. On this Find form is a textbox and 2 buttons , \"Find\" and \"FindNext\"

I have 2 forms, one with containing a richtextbox and the other used for finding text in this rtb.

On this Find form is a textbox and 2 buttons , "Find" and "FindNext"

I've no 开发者_开发技巧idea how to link the 2 forms together to find the text and also how to find the text

:-S

Any help please??


To each of your forms you can add a property that will reference the other form. This will give you access to the other form and all the controls on it through the property.

public property Form RTForm { get; set;}

You can then set this property in the place you construct the forms.

Form myForm = new Form();
Form rtForm = new RTForm();
myForm.RTForm = rtForm();


There are several ways. You could just define a property on the one form which contains the richtextbox, which can be found by your other form.

public static string RTextboxText
{
    get
    {
        return myrichtextbox.Text;
    }
    set
    {
        myrichtextbox.Text = value;
    }
}

Setter can be dropped ofc.

Another way is to use a class between the 2 forms. I think you also use specific actions on the text? You might want to put all your code about that, in that class as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号