Many thanks Alan, I'll give it a try. I knew Profox would come up with the goods 😊
John
John Weller 07976 393631
-----Original Message----- From: ProfoxTech profoxtech-bounces@leafe.com On Behalf Of Alan Bourke Sent: 10 January 2022 14:58 To: profoxtech@leafe.com Subject: Re: [NF] Help With VB.Net
Assuming you are using Windows Forms and not WPF ...
You can detect an 'Enter' keypress via the KeyPress event.
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs)Handles TextBox1.KeyPress If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then MessageBox.Show("Enter") End If End Sub
That won't detect focus leaving the textbox via tab or mouse click etc though. For that you might have to use the Validating event.
Private Sub TextBox1_Validating(sender As Object, e AsSystem.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
Dim isValid As Boolean isValid = True ' Check what you need to check here. If isValid = False Then e.Cancel = True End If End Sub-- Alan Bourke alanpbourke (at) fastmail (dot) fm
On Mon, 10 Jan 2022, at 2:14 PM, John@johnweller.co.uk wrote:
I am trying to help a friend write an app in VB.Net. I need some code to fire when a number is entered into a textbox and Enter pressed, as in the Valid event in VFP, but can’t seem to find the appropriate VB event – any suggestions gratefully received. I’m asking here because it is easier to specify the problem in VFP terms 😊
TIA
John
John Weller
07976 393631
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html
[excessive quoting removed by server]