Solved

How to make Form Keydown event ignore if in Textbox

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

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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.
This video teaches viewers about errors in exception handling.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

627 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