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

A

Aphazel

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
 
D

Dragon

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
 
G

Guest

Aph,

Here is one way:

Dim tbox As TextBox

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

Kerry Moorman
 
A

Aphazel

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
 
A

Aphazel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top