剪切,复制和粘贴 [英] cut, copy, and paste

查看:72
本文介绍了剪切,复制和粘贴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在vb 2005中编码剪切,复制和粘贴,这样当用户点击工具栏按钮时,剪切/复制/粘贴将适用于任何

光标当前位于的文本框(我在

表格中有大约20个文本框)。还要确保如果光标不在文本框字段中,则不能使用该按钮。并确保剪贴板的内容是文本

已从表单上的一个文本框中剪切/复制的内容。


谢谢


Steve

I''m trying to code cut, copy, and paste in vb 2005 so that when the user
clicks on a toolbar button, the cut/copy/paste will work with whatever
textbox the cursor is current located in (I have about 20 textboxes on the
form). Also to ensure that the button can''t get used if the cursor isn''t in
a textbox field. And to ensure the contents of the clipboard are "text"
contents that have been cut/copied from one of the textboxes on the form.

Thanks

Steve

推荐答案

TextBox控件包含剪切,复制和粘贴成员,因此您可以使用

他们直接。在VB2005中,您还可以使用My.Computer.Clipboard中的功能。

如果您想确保只粘贴来自

计划的内容,可能想要使用(或代替)标准文本将自定义内容类型添加到剪贴板

。在联机帮助中查看My.Computer.Clipboard.GetData()

和.SetData()以获取更多信息。


要确定当前控件,使用Me.ActiveControl。如果是使用此代码的TextBox对象,您可以确定




If(TypeOf Me.ActiveControl是TextBox)然后

''-----在这里添加特殊代码。

结束如果


-----

Tim Patrick - www.timaki.com

从头到尾视觉Basic 2005
The TextBox control includes Cut, Copy, and Paste members, so you can use
them directly. In VB2005, you can also use the features in My.Computer.Clipboard.
If you want to ensure that you are only pasting content that came from your
program, you might want to add a custom content type to the clipboard along
with (or instead of) the standard text. Look at My.Computer.Clipboard.GetData()
and .SetData() in the online help for more information.

To determine the current control, use Me.ActiveControl. You can determine
if it is a TextBox object using this code.

If (TypeOf Me.ActiveControl Is TextBox) Then
'' ----- Add special code here.
End If

-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005

我正在尝试在vb 2005中编码剪切,复制和粘贴,以便当

用户点击工具栏按钮,剪切/复制/粘贴将使用

光标当前所在的任何文本框(我在表单上有大约20

文本框)。还要确保按钮无法使用

如果光标不在文本框字段中。并且为了确保

的内容,剪贴板是文本。已从表格上的一个文本框中删除/复制的内容。


谢谢


史蒂夫
I''m trying to code cut, copy, and paste in vb 2005 so that when the
user clicks on a toolbar button, the cut/copy/paste will work with
whatever textbox the cursor is current located in (I have about 20
textboxes on the form). Also to ensure that the button can''t get used
if the cursor isn''t in a textbox field. And to ensure the contents of
the clipboard are "text" contents that have been cut/copied from one
of the textboxes on the form.

Thanks

Steve



Tim ...


谢谢 - 再往前走一步,我怎么样?验证

剪贴板的内容与目标文本框的结构是否相同。例如,

我已经从文本框中删除了一个货币值,格式为

FormatCurrency。我想只允许在目标

格式相同的情况下发生粘贴。对于FormatPercent也一样。


史蒂夫


Tim Patrick < in ***** @ invalid.com.invalidwrote in message

news:e3 *********************** **@newsgroups.comcas t.net ...
Tim...

Thanks - To go one step farther, how would I verify that the contents of the
clipboard was in the same structure as the target textbox. For instance,
I''ve cut a Currency value out of a textbox that is formatted as
FormatCurrency. I want to only allow the paste to occur if the target
format is the same. Same for FormatPercent.

Steve

"Tim Patrick" <in*****@invalid.com.invalidwrote in message
news:e3*************************@newsgroups.comcas t.net...

TextBox控件包括剪切,复制和粘贴成员,因此您可以使用

他们直接。在VB2005中,您还可以使用
The TextBox control includes Cut, Copy, and Paste members, so you can use
them directly. In VB2005, you can also use the features in



My.Computer.Clipboard中的功能。

My.Computer.Clipboard.


如果你想确保你只是粘贴来自
的内容
If you want to ensure that you are only pasting content that came from



你的

your


程序,您可能想要将自定义内容类型添加到剪贴板
program, you might want to add a custom content type to the clipboard



沿

along


带(或代替)标准文本。看看
with (or instead of) the standard text. Look at



My.Computer.Clipboard.GetData()

My.Computer.Clipboard.GetData()


和.SetData()在在线帮助以获取更多信息。


要确定当前控件,请使用Me.ActiveControl。如果是使用此代码的TextBox对象,您可以确定




If(TypeOf Me.ActiveControl是TextBox)然后

''-----在这里添加特殊代码。

结束如果


-----

Tim Patrick - www.timaki.com

从头到尾视觉Basic 2005
and .SetData() in the online help for more information.

To determine the current control, use Me.ActiveControl. You can determine
if it is a TextBox object using this code.

If (TypeOf Me.ActiveControl Is TextBox) Then
'' ----- Add special code here.
End If

-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005

我正在尝试在vb 2005中编码剪切,复制和粘贴,以便当

用户点击工具栏按钮,剪切/复制/粘贴将使用

光标当前所在的任何文本框(我在表单上有大约20

文本框)。还要确保按钮无法使用

如果光标不在文本框字段中。并且为了确保

的内容,剪贴板是文本。已从表格上的一个文本框中删除/复制的内容。


谢谢


史蒂夫
I''m trying to code cut, copy, and paste in vb 2005 so that when the
user clicks on a toolbar button, the cut/copy/paste will work with
whatever textbox the cursor is current located in (I have about 20
textboxes on the form). Also to ensure that the button can''t get used
if the cursor isn''t in a textbox field. And to ensure the contents of
the clipboard are "text" contents that have been cut/copied from one
of the textboxes on the form.

Thanks

Steve




一种解决方案是利用可用的TextBox.Tag属性。

在每个文本框的Tag属性中,存储一个短名称,表示允许的

数据。例如,使用货币和货币。或百分比或PetNames或PetNames。或者其他。

然后当您使用My.Computer.Clipboard.SetData将内容复制到剪贴板时,

使用该标记名称作为格式名称。然后当有人试图粘贴它时,你可以将格式名称与目标

文本框的Tag属性中的名称进行比较。您还可以在包含格式类型的cliipboard

上存储更复杂的数据结构,然后使用SetData使用的单个通用格式名称

。无论哪种方式都可行。

-----

Tim Patrick - www.timaki.com

从头到尾Visual Basic 2005
One solution would be to take advantage of the available TextBox.Tag property.
In each text box''s Tag property, store a short name that indicates the allowed
data. For instance, use "Currency" or "Percent" or "PetNames" or whatever.
Then when you copy the content to the clipboard using My.Computer.Clipboard.SetData,
use that tag name as the format name. Then when someone tries to paste it,
you can compare the format name to what was in the Tag property of the target
text box. You could also store a more complex data structure on the cliipboard
that included the format type, and then just use a single common format name
used by SetData. Either way would work.
-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005

Tim ...


谢谢 - 为了更进一步,我如何验证剪贴板的内容与目标文本框的结构是否相同。对于

实例,我已经从格式化的文本框中删除了一个货币值

作为FormatCurrency。我想只允许在

目标格式相同的情况下发生粘贴。对于FormatPercent也一样。


史蒂夫


Tim Patrick < in ***** @ invalid.com.invalidwrote in message

news:e3 *********************** **@newsgroups.comcas t.net ...
Tim...

Thanks - To go one step farther, how would I verify that the contents
of the clipboard was in the same structure as the target textbox. For
instance, I''ve cut a Currency value out of a textbox that is formatted
as FormatCurrency. I want to only allow the paste to occur if the
target format is the same. Same for FormatPercent.

Steve

"Tim Patrick" <in*****@invalid.com.invalidwrote in message
news:e3*************************@newsgroups.comcas t.net...

> TextBox控件包括剪切,复制和粘贴成员,因此您可以使用
他们直接。在VB2005中,您还可以使用
>The TextBox control includes Cut, Copy, and Paste members, so you can
use them directly. In VB2005, you can also use the features in



My.Computer.Clipboard中的功能。

My.Computer.Clipboard.


>如果你想确保你只粘贴来自
的内容
>If you want to ensure that you are only pasting content that came
from



你的

your


>程序,您可能想要将自定义内容类型添加到剪贴板
>program, you might want to add a custom content type to the clipboard



沿

along


>使用(或代替)标准文本。看看
>with (or instead of) the standard text. Look at



My.Computer.Clipboard.GetData()

My.Computer.Clipboard.GetData()


>和.SetData()在线帮助中获取更多信息。

要确定当前控件,请使用Me.ActiveControl。您可以使用此代码确定它是否是TextBox对象。

If(TypeOf Me.ActiveControl是TextBox)然后
''-----在这里添加特殊代码。
结束如果
-----
Tim Patrick - www .timaki.com
从头到尾Visual Basic 2005
>and .SetData() in the online help for more information.

To determine the current control, use Me.ActiveControl. You can
determine if it is a TextBox object using this code.

If (TypeOf Me.ActiveControl Is TextBox) Then
'' ----- Add special code here.
End If
-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005

>>我正在尝试编码剪切,复制,并粘贴在vb 2005中,以便当
用户点击工具栏按钮时,剪切/复制/粘贴将与光标当前所在的任何文本框一起使用(我有大约20个/ br / >表单上的文本框)。还要确保如果光标不在文本框字段中,则无法使用该按钮。并确保剪贴板的内容是文本。已从表格上的其中一个文本框中剪切/复制的内容。

感谢史蒂夫
>>I''m trying to code cut, copy, and paste in vb 2005 so that when the
user clicks on a toolbar button, the cut/copy/paste will work with
whatever textbox the cursor is current located in (I have about 20
textboxes on the form). Also to ensure that the button can''t get
used if the cursor isn''t in a textbox field. And to ensure the
contents of the clipboard are "text" contents that have been
cut/copied from one of the textboxes on the form.

Thanks

Steve



这篇关于剪切,复制和粘贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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