VB.Net - Weird Happenings - Its Freakin Me Out

G

Guest

Using VS.Net 2003 (VB.Net)
WinForm App....

Problem:
I have a form (lets call it Form1)
On Form1 (amongst other things) is a button (btnOne) and an text box
(txtBox).
.....Click on button... Shows another form (lets call it Form2)...
.....All OK so far...
......Close Form2
...Back to Form1...btnOne has focus... All Ok so far...
...Select txtBox... btnOne appears to lose focus (lost focus event fires)
... txtBox appears to gain focus (gotFocus event fires)...
.... type something in txtBox Press <CR>
.... Form2 Shows (onLoad event Fires)
... Problem .... This is not the desired result...
.... Close Form2
.... btnOne has focus
.... Select txtBox ... btnOne loses focus...text box has focus
.... Type something in txtBox ... Press <<CR>
.... This time every thing works as it should and txtBox reacts to the <CR>
keypress...

Question: Why does btnOne appear not to lose focus the first time.

And.. Yes... If I select btnOne and select Form2 again then everything
starts over....

What have I done??
Any help appreciated...
Regards...
 
J

Jon Morley-Jones

What you will find is that on form1 you have a property call AcceptButton
what you will find is that this property has btnOne set to it. So when you
press <CR> that button will run. So if you don't want it to run then change
the AcceptButton property not to be any button.

I hope this helps

Jon
 
N

Nick Malik [Microsoft]

Just to add to Jon's answer:

Your form thinks that you want the button to be a default button, and that
it should fire when you press CR.
This is a feature. Most dialog boxes have "default buttons" (usually
labeled something like OK or Next).
This feature is used to indicate which button you want to be the default
button.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
G

Guest

Nick Malik said:
Just to add to Jon's answer:

Your form thinks that you want the button to be a default button, and that
it should fire when you press CR.
This is a feature. Most dialog boxes have "default buttons" (usually
labeled something like OK or Next).
This feature is used to indicate which button you want to be the default
button.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.

Sorry... Should have mentioned I checked the AcceptButton Property of the
form and this was/is set to 'None'

My work round at the moment is to set focus to the text box prior to
displaying the form in the button_click event....

This has fixed the problem but why I have to do this is frustrating...

Regards...KeithO
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top