如何复制单独选择的RichTextBox的内容? [英] How can I copy the contents of an individually selected RichTextBox?

查看:143
本文介绍了如何复制单独选择的RichTextBox的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有42个RichTextBoxes(RTB),我想将ContextMenuStrip添加到它们中的每一个(已经完成),但是我遇到的问题是当应用程序正在运行并且ContextMenuItem为复制"时例如,当我单击它时,我只想复制任何一个RTB的内容,就只能使其复制一个RTB的上下文.
因此,正如我提到的,我有42个实时出价工具,但是我在获取重点实时出价工具的内容时遇到了麻烦.下面的代码只是复制1个RTB,而当我在另一个RTB上复制时,它将复制RTB1的内容.
我最初是这样开始的,但仅适用于一个RTB,而当我在下面的代码中添加多个代码时,这简直是一场灾难..

Hello, I have 42 RichTextBoxes (RTBs) and I would like to add my ContextMenuStrip to each of them (which I have already done), but the problem I am having is when the application is running and the ContextMenuItem "Copy" for example is clicked, I can only make it copy the context of one of the RTBs, when I would like it to copy the contents of any individual one.
So as I mentioned, I have 42 RTBs, but I am having trouble getting the contents of the focused RTB. The below code is just copying the 1 RTB and when I Copy on another RTB, it copies the contents of RTB1.
I originally started out with like so, but is just for the one RTB and when I add more than one in the code below it''s even more of a disaster..

Private Sub Copy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Copy.Click
    RichTextBox1.Copy()
End Sub


我尝试使用此功能,但不确定如何将复制功能添加到其中:


I tried using this, but I was not sure how to add the copy function into it:

Private Sub Copy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Copy.Click
    Try
        For Each itm As Control In EnumerateAllControls(Me)
            For Each c As Control In itm.Controls
                If TypeOf c Is RichTextBox Then
                    ****NOT SURE WHAT CODE TO PUT HERE..****
                End If
            Next
        Next
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub


因此,如果任何人都可以帮助我的Copy ContextMenuItem专注于以用户为中心的RTB,我将不胜感激! :)


So If anyone can help my Copy ContextMenuItem to focus on the user focused RTB, I would greatly appreciate it! :)

推荐答案

您将执行以下操作

You would do something like this

if TypeOf c is RichTextBox then
  c.Copy
end if



但这只会将其复制到剪贴板,并将被其他Richtextbox中的数据覆盖.



But this only copies it to the clipboard and will be overwritten with the data from the other Richtextboxs.


这篇关于如何复制单独选择的RichTextBox的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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