Solved

How to make Form Keydown event ignore if in Textbox

Posted on 2008-06-18
6
796 Views
Last Modified: 2008-06-27
Hi,

I have got a project where I need to detect a key press at any time that the form is open and send out different serial data dependent on the keycode detected.  The form however has text boxes, which I need to be able to type into and not flag up as a form keydown event.

I know in VB5 you could use the following...

If TypeOf Screen.ActiveControl Is TextBox Then
    Exit sub

is there a VB.NET equivalent?

Thanks in advance
0
Comment
Question by:fvcctv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 27

Accepted Solution

by:
planocz earned 500 total points
ID: 21814553
Use something like this. just change thee code to match what you need.

 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        HandleTextBoxes(Me)
    End Sub
   Private Sub HandleTextBoxes(ByVal container As Control)
        Dim Ctl As Control
        For Each Ctl In container.Controls
            If TypeOf Ctl Is TextBox Then
                AddHandler CType(Ctl, TextBox).TextChanged, AddressOf Me.OnTextboxChange
            ElseIf Ctl.Controls.Count > 0 Then
                HandleTextBoxes(Ctl) ' recurse into another container
            End If
        Next
    End Sub
 
  Public Sub OnTextboxChange(ByVal sender As Object, ByVal e As EventArgs)
        Debug.WriteLine("Text changed in " & sender.name)
    End Sub

Open in new window

0
 

Author Comment

by:fvcctv
ID: 21814896
If TypeOf Me.ActiveControl Is TextBox Then
0
 

Author Comment

by:fvcctv
ID: 21814900
Found solution myself
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This video teaches viewers about errors in exception handling.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question