Solved

How to make Form Keydown event ignore if in Textbox

Posted on 2008-06-18
6
727 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
  • 2
6 Comments
 
LVL 27

Accepted Solution

by:
planocz earned 500 total points
Comment Utility
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
Comment Utility
If TypeOf Me.ActiveControl Is TextBox Then
0
 

Author Comment

by:fvcctv
Comment Utility
Found solution myself
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now