473,396 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Windows.Form: Event on active control change

Hi,

Is there an event of windows.forms.form which informs me that the active
control will be changed before it will be changed? Something like:

Private Sub Form_Validating(ByVal sender As Object, ByVal e As ...) Handles
Form."EVENT HERE"
dim Ok as Boolean = False
...
If Not (ok = True) Then
e.Cancel = True
End If
End Sub

I don't want to add an event handler for each control on the form, because
there is one base class which should be able to validate the user input
independently by special criteria not mentioned here.

thanks volker jobst
Nov 20 '05 #1
4 7822
Hi Volker,

I thought not, however when you use this sample code you can create them. I
use the lost focus but you can take whatever you like. (look to the right
events then)

I hope this helps?

Cor
\\\
Dim last As String
Private Sub Form5_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doset(Me)
End Sub
Private Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
AddHandler ctr.LostFocus, AddressOf meLostFocus
AddHandler ctr.GotFocus, AddressOf meGotFocus
doSet(ctr)
Next
End Sub
Private Sub meLostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
last = DirectCast(sender, Control).Name
End Sub
Private Sub meGotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Control).Text = last
End Sub

///
Nov 20 '05 #2
"Volker Jobst" <bu****@gmx.de> schrieb
Hi,

Is there an event of windows.forms.form which informs me that the
active control will be changed before it will be changed? Something
like:

Private Sub Form_Validating(ByVal sender As Object, ByVal e As ...)
Handles Form."EVENT HERE"
dim Ok as Boolean = False
...
If Not (ok = True) Then
e.Cancel = True
End If
End Sub

I don't want to add an event handler for each control on the form,
because there is one base class which should be able to validate the
user input independently by special criteria not mentioned here.

You can use the same event handler for all controls. You could add them in a
loop, also in a base class.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
* "Volker Jobst" <bu****@gmx.de> scripsit:
Is there an event of windows.forms.form which informs me that the active
control will be changed before it will be changed? Something like:

Private Sub Form_Validating(ByVal sender As Object, ByVal e As ...) Handles
Form."EVENT HERE"
dim Ok as Boolean = False
...
If Not (ok = True) Then
e.Cancel = True
End If
End Sub

I don't want to add an event handler for each control on the form, because
there is one base class which should be able to validate the user input
independently by special criteria not mentioned here.


I didn't test it, but try to listen in the form's 'WndProc' for
'WM_KILLFOCUS'. The 'wParam' parameter will store the handle of the
control that receives focus, or 'NULL'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uO**************@TK2MSFTNGP12.phx.gbl...
Hi Volker,

I thought not, however when you use this sample code you can create them. I use the lost focus but you can take whatever you like. (look to the right
events then)

I hope this helps?

Cor
\\\
Dim last As String
Private Sub Form5_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doset(Me)
End Sub
Private Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
AddHandler ctr.LostFocus, AddressOf meLostFocus
AddHandler ctr.GotFocus, AddressOf meGotFocus
doSet(ctr)
Next
End Sub
Private Sub meLostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
last = DirectCast(sender, Control).Name
End Sub
Private Sub meGotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Control).Text = last
End Sub

///


Thank you, this solution works fine!!
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dave | last post by:
How do I check in a Windows Forms app if any controls have changed? I have a form that collects data, and I want to prompt the user if they try to exit the app, or load a new file, without saving...
1
by: Dave Wurtz | last post by:
All, Is there an event on the Form that will get fired when the text in another control (i.e. textbox) is changed? I know there is a TextChanged event on the control, but I'm looking for...
6
by: Fred Morrison | last post by:
1. No Columns collection. 2. No ability to easily synchronize the underlying DataTable of a DataGrid when a row is deleted in the Grid. Once you sort (via the column headers) all bets are off as...
3
by: Jason Huang | last post by:
Hi, How do I let the X Close Control Box incurr a Close Button when I click the X Close Control Box? Thanks for help. Jason
0
by: hazz | last post by:
I would like to have control over datagridview events so that when a user 'single clicks' anywhere on the grid, a method call is made to a service and if a user 'double clicks' a Customer detail...
13
by: active | last post by:
With VS2005 the windows form designer uses the files *.Designer.vb I hope no one at MS is reading this because I know it will upset them to know - I like the old way better! I've been looking...
3
by: bsturg21 | last post by:
Hello, I have a windows form that has a series of linklabels on it, and I need to have each linklabel, when clicked, open a separate windows form that has a single paramter passed into it. The...
0
by: morathm | last post by:
I have a windows client database management application written in C# that connects to remote web services to do all the heavy work. The thin-client app uses strong typed datasets, all maintained at...
8
by: martinsmith160 | last post by:
Hi all I have a picture box placed within a panel so i can scroll across the picture due to it being very wide. My problem is I want to draw an image over the picture box when a user clicks at a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.