Solved

How to make Form Keydown event ignore if in Textbox

Posted on 2008-06-18
6
773 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
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why does my excel data start at B1 instead of A1. 9 83
Search an image for an image 3 30
Math Equation 23 87
MailAddress in vb 4 15
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

777 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