 |
 |

12-02-2009, 12:37 AM
|
|
Newcomer
|
|
Join Date: Nov 2009
Posts: 3
|
|
Ctrl+C shortcut
|
Hello all, im new to the forum!
I recently started coding in VB 2008, and I have a question:
I'm using the following code for the Ctrl+C input:
Code:
Private Sub Form1_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer)
If Shift And vbCtrlMask Then
If KeyCode = vbKeyC Then
MsgBox("Ctrl + C pressed")
End If
End If
End Sub
That should work, but there is a strange problem. It says:
Name 'vbKeyC' is not declared.
Name 'vbCtrlMask' is not declared.
Aren't those values VB keywords? If they are, why does it say I need to declare them?
Please help me, and sry for my noobishness...
EDIT: Nvm, I have found the solution 
|
Last edited by Thorinair; 12-02-2009 at 03:36 AM.
|

12-02-2009, 09:31 AM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
|
Um... that code is for VB6 and you are using VB2008.
Yes, those are 'VB' constants (not keywords), but they are VB6 constants.
(Keywords are like If, Then, End If, universal to all versions of VB)
Delete all of that code above and either find the equivalent code using .NET, or go into VB2008 and browse in the code window for the equivalent in .NET - Form -> Keydown. You will have sender As Object and e as something like KeyEventArgs.
|
|

12-02-2009, 09:34 AM
|
 |
Fabulous Florist
Forum Leader * Guru *
|
|
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,419
|
|
|
Could you post the solution? Then other people wouldn't have to ask the same question again.
Personally I'm interested because the event handler you posted is not a .NET event handler, so I'm curious what you did to make things work.
|
|

12-02-2009, 02:00 PM
|
|
Freshman
|
|
Join Date: Sep 2009
Posts: 36
|
|
I dont know if this would work but from what i do know about keydown is this:
Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.ControlKey
Select Case e.Keycode
Case Keys.C
MsgBox("Whatever You Want")
End Select
End Select
End Sub
Hope this helps idk if it works
|
Last edited by Flyguy; 12-02-2009 at 02:11 PM.
|

12-02-2009, 04:48 PM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
Well, seeing as how e.Keycode can only be one value, I don't think that MsgBox (MessageBox.Show) would show.
Looking here, you can process Ctrl+C by using the following:
Code:
If e.Control Then 'User pressed Ctrl+___
If e.KeyCode = Keys.C Then 'User pressed Ctrl+C
'Your Ctrl+C code here
End If
End If
|
|

12-11-2009, 02:49 AM
|
|
Newcomer
|
|
Join Date: Nov 2009
Posts: 3
|
|
|
Thx for all the help people, it is working now.
Gonna post my solution as soon as I come home!
|
|

12-11-2009, 06:57 AM
|
|
Newcomer
|
|
Join Date: Nov 2009
Posts: 3
|
|
Ok, it is for a calculator, so you know. I used the following code:
Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles MyBase.KeyDown
If e.Control AndAlso e.KeyCode = Keys.C Then
Clipboard.Clear()
Clipboard.SetText(TextBox1.Text)
ElseIf e.Control AndAlso e.KeyCode = Keys.V Then
Dim Number As Double
Try
Number = CDbl(Clipboard.GetText)
TextBox1.Text = Clipboard.GetText
Catch
MsgBox("Value must be a number")
End Try
End If
End Sub
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|