如何在C#中创建静态richtextbox [英] how to create static richtextbox in C#

查看:164
本文介绍了如何在C#中创建静态richtextbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< b>:笑:

我想让我的richtextbox静态,以便我可以在其他表单上获取我的richtextbox的内容。

但我的条件当你点击查找menustrip然后找到对话框时,你可能已经在记事本中看到了记事本,点击查找下一个按钮后,调用了查找方法,文本突出显示。

通过使用变量i将在另一个表单上获取richtextbox的文本,但我无法突出显示我的richtextbox的文本。

请帮忙吗?

如果你提供解决方案,请提前谢谢。< / b>

<b>:laugh:
I want to make my richtextbox static so that i can get the contents of my richtextbox on other form.
but my condition is that u might have seen the notepad in notepad when u click on find menustrip then find dialogbox appears and after clicking on Find next button the find method is called and the text is highlighted.
By using variable i will get the text of richtextbox on another form but i cant highlight the text of my richtextbox.
So pls help?
Thanks in advance if u provide the solution.</b>

推荐答案

如果我理解正确,你想在记事本中实现类似于查找对话框的内容。这是正确的吗?



如果是这样的话,听起来你正试图以一种奇怪的方式解决这个问题。



我假设您已创建表单来执行查找或正在执行的任何操作。更改构造函数以包含 RichTextBox 即...



If I am understanding correctly, you want to implement something like the find dialog in notepad. Is that correct?

If so, it sounds like you're trying to go about this in a weird way.

I assume you've created the form to do the finding or whatever it's doing. Change the constructor to include a RichTextBox ie...

public FindForm(RichTextBox TextBoxToSearch)
{
   ...
}





这是我刚测试的一个例子:



Here's an example that I just tested:

public partial class find : Form
{
    private RichTextBox _textBoxToUse;

    public find(RichTextBox textBoxToUse)
    {
        InitializeComponent();
        _textBoxToUse = textBoxToUse;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        _textBoxToUse.Select(5, 5);
    }
}







然后,当用户点击查找时该表单上的按钮,只需浏览该文本框并更改 SelectionStart SelectionLength 属性以突出显示整个工作。



你不需要把它变成静态的......只要将它传递给另一种形式,任何形成它的东西都会发生在原始形式上。只需确保您已将 RichTextBox HideSelection 属性更改为False,以便即使它没有重点,选择将显示。




Then, when the user clicks the "Find" button on that form, just go through that textbox and change the SelectionStart and SelectionLength properties to highlight the entire work.

You don't need to make it static...just pass it to the other form and anything that form does to it will happen to the original. Just make sure that you have changed the RichTextBox's HideSelection property to False so that even when it doesn't have the focus, the selection will show.


这篇关于如何在C#中创建静态richtextbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆