Solved

How to make Form Keydown event ignore if in Textbox

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
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 video teaches viewers about errors in exception handling.

739 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