472,990 Members | 3,207 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,990 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 7783
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.