By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,780 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,780 IT Pros & Developers. It's quick & easy.

[VB2005EE] accessing control-specific functions via form's ActiveControl

P: n/a
I got serveral textboxes in a form and want to copy/cut/paste text to
clipboard from currently selected (focused) textbox.

It's simple to cut/copy/paste when using specified control directly ie
Me.TextBox1.Cut()

But there's no .Cut() function when i try to use Me.ActiveControl. Is the a
way to access textbox'es .Cut() via ActiveControl knowing that it's a
textbox object?

I also tried an other way:
Clipboard.SetText(Me.ActiveControl.Text)
and
Clipoboard.SetText(Me.ActiveControl.Text.ToString( ))
but it produces errors.

Does anyone knows a solution?
Thx, Aph

May 11 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Aph,

Here is one way:

Dim tbox As TextBox

tbox = CType(Me.ActiveControl, TextBox)
tbox.SelectAll()
tbox.Copy()

Kerry Moorman
"Aphazel" wrote:
I got serveral textboxes in a form and want to copy/cut/paste text to
clipboard from currently selected (focused) textbox.

It's simple to cut/copy/paste when using specified control directly ie
Me.TextBox1.Cut()

But there's no .Cut() function when i try to use Me.ActiveControl. Is the a
way to access textbox'es .Cut() via ActiveControl knowing that it's a
textbox object?

I also tried an other way:
Clipboard.SetText(Me.ActiveControl.Text)
and
Clipoboard.SetText(Me.ActiveControl.Text.ToString( ))
but it produces errors.

Does anyone knows a solution?
Thx, Aph

May 11 '06 #2

P: n/a
Hi,

Form.ActiveControl is of type Control, so you need to cast it manually:

~
If TypeOf Me.ActiveControl Is TextBox Then
DirectCast(Me.ActiveControl, TextBox).Cut()
End If
~

Roman
May 11 '06 #3

P: n/a
Thx for your advice Kerry :) however I've always liked this style more:
DirectCast(Me.ActiveControl, TextBox).Cut() It's just my personal preference but I don't like to declare additionas dims
for such actions.
Which way is better? I'm not the one to judge here, not enough knowledge ;)
It's just IMHO code looks better this way. Neat, I'd say. :D

Aph
Here is one way:

Dim tbox As TextBox

tbox = CType(Me.ActiveControl, TextBox)
tbox.SelectAll()
tbox.Copy()

Kerry Moorman


May 11 '06 #4

P: n/a
Sup :)
This is exaclty what I wanted. THX, I owe you man :)))
I used to use similar stuff in Delphi and BCB, just couldn't find easy
enough what's the syntax in VB.Net so I've dediced to ask here.

Aph
~
If TypeOf Me.ActiveControl Is TextBox Then
DirectCast(Me.ActiveControl, TextBox).Cut()
End If
~


May 11 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.