Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > Ctrl+C shortcut


Reply
 
Thread Tools Display Modes
  #1  
Old 12-02-2009, 12:37 AM
Thorinair Thorinair is offline
Newcomer
 
Join Date: Nov 2009
Posts: 3
Default 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.
Reply With Quote
  #2  
Old 12-02-2009, 09:31 AM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
Default

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.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 12-02-2009, 09:34 AM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,419
Default

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.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #4  
Old 12-02-2009, 02:00 PM
ericponce ericponce is offline
Freshman
 
Join Date: Sep 2009
Posts: 36
Default

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.
Reply With Quote
  #5  
Old 12-02-2009, 04:48 PM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
Default

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
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #6  
Old 12-11-2009, 02:49 AM
Thorinair Thorinair is offline
Newcomer
 
Join Date: Nov 2009
Posts: 3
Default

Thx for all the help people, it is working now.
Gonna post my solution as soon as I come home!
Reply With Quote
  #7  
Old 12-11-2009, 06:57 AM
Thorinair Thorinair is offline
Newcomer
 
Join Date: Nov 2009
Posts: 3
Default

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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->