Results 1 to 7 of 7

Thread: hehe.. stop beep when pressing Enter

  1. #1

    Thread Starter
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    hehe.. stop beep when pressing Enter

    You know how the system beeps if you try to press
    Enter in a single-line textbox...

    Well, anyway, I making a usercontrol that I want to just pass a TAB along to the system... I found this code in C#, I know Pirate has # skills, so perhaps he can convert this to VB...

    Code:
    const int WM_KEYDOWN = 0x100;
    const int WM_KEYUP = 0x101;
    
    public override bool PreProcessMessage(ref
    System.Windows.Forms.Message msg)
     {
    Keys keyCode=(Keys)(int)msg.WParam & Keys.KeyCode;
    
    if((msg.Msg==WM_KEYDOWN || msg.Msg==WM_KEYUP) &&
    keyCode==Keys.Enter)
     {
    msg.WParam=(System.IntPtr)Keys.Tab;
    }
    return base.PreProcessMessage(ref msg);
    }
    Here's what I have so far....

    VB Code:
    1. Dim keyCode As Keys = CType(msg.WParam, IntPtr).ToInt32
    2.  
    3.  
    4.         If msg.Msg = Convert.ToInt32("0x100") Then
    5.             If keyCode = Keys.Enter Then
    6.                 msg.WParam = New IntPtr(Keys.Tab)
    7.                 Return True
    8.             End If
    9.         End If
    10.         Return MyBase.ProcessKeyEventArgs(msg)

    I think that's correct except msg.Msg = "0x100"
    probably stops this routine from working correctly.

    So, how do I say:

    If msg.Msg = WM_KEYUP or msg.Msg = WM_KEYDOWN
    Last edited by nemaroller; Oct 17th, 2003 at 11:37 AM.

  2. #2

    Thread Starter
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Ok... I got this part to work... no beep, but I still want it to send a Tab...

    VB Code:
    1. Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
    2.         Dim keyCode As Keys = CType(msg.WParam, IntPtr).ToInt32
    3.         Const WM_KEYDOWN As Integer = &H100
    4.         Const WM_KEYUP As Integer = &H101
    5.  
    6.         If msg.Msg = WM_KEYDOWN AndAlso keyCode = Keys.Enter Then
    7.             msg.WParam = New IntPtr(Keys.Tab)
    8.             Return True
    9.         End If
    10.         Return MyBase.ProcessCmdKey(msg, keyData)
    11.     End Function

  3. #3
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    hmm I dont know what you're doing... if you want to stop the beep sonud, just set e.Handled to true in the keypress event of a textbox or whatever (or maybe it's the keydown sub)

    0x100 in VB.NET would be &H100 I think. and 0x101 would be &H101. so you would have
    Const WM_KEYDOWN as integer = &H100

    I dont understand how this hex thingie works though
    edit: too late
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4

    Thread Starter
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    I tried e.handled, but could not get it work properly...

    Anyway, the above code works, but now I have to figure out why its not replacing the .Wparam with the tab instead of Enter.

  5. #5

    Thread Starter
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    YES!

    GOT IT! (by cheating using me.parentform.selectnextcontrol, but ***)

    VB Code:
    1. Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
    2.         Dim keyCode As Keys = CType(msg.WParam, IntPtr).ToInt32
    3.         Const WM_KEYDOWN As Integer = &H100
    4.         'Const WM_KEYUP As Integer = &H101   in case people need this
    5.  
    6.         If msg.Msg = WM_KEYDOWN AndAlso keyCode = Keys.Enter Then
    7.             Me.ParentForm.SelectNextControl(Me, True, True, False, True)
    8.             Return True
    9.  
    10.         End If
    11.         Return MyBase.ProcessCmdKey(msg, keyData)
    12.     End Function

  6. #6
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    umm I'm not answering your directly but, you coudl do something like tihs:

    Me.SelectNextControl(TextBox1, True, True, True, True)

    that would select the control after textbox1.... that is, if you are trying to pass teh focus to some other control
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  7. #7
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    lol one minute late
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width