Link to home
Start Free TrialLog in
Avatar of leg1
leg1

asked on

right click causes focus to go to another control

I suspect the solution to this falls under the category of reformat your disk, reinstall everything, then get a new computer.  I have WIN 98, vb 6, sp 3, 64 mb Ram.

Don't bother trying to re-create this - it used to work fine and I'm sure it will work fine in your code.

Here's the problem:
I have a text box (plus other controls) where I have a mouseup event handler where I test for right button and then popup a context menu if it was.
This worked fine until I made a lot of changes in another part of the form.
Then what would happen is if I right clicked on the text box, instead of the context menu, focus would transfer to another text box.
I tried closing vb, reboot, build EXE and run that, all give same behavior.
I then made a copy of the text box which was getting the focus, deleted the original text box, and gave the new textbox the name of the one I deleted.
Now instead of that textbox getting the focus on rightclick, a command button got the focus.
I noticed that the command button had tabindex one higher than the textbox I was right clicking on - I changed tabindexes which resulted in different controls getting the focus (the next control in tab order would get it).
I copied the textbox with mouseup handler, gave the copy the original name and deleted the original.  I still have the problem.
If I don't right click there is no problem  (Yes, I know; I can solve the problem by instructing the user not to right click and if I get any complaints about weird behavior with right clicking, I can sneer and ask "don't you read the documentation?").

I guess the next step is to reinstall VB (after deleting it - as I've read here on EE).
Avatar of vettranger
vettranger

If you'd like to send me the project just so you can verify the behavior on another vb6 sp3 system, I'd be happy to take a look at it for you :
vetteranger@carolina.rr.com
Post the code for your Mouse events for the textbox in question.
Avatar of leg1

ASKER

Vettranger: thanks for the offer - it's a good idea but I'll just try it on a second machine I have.

Erick37: I removed the mouseup eventhandler altogether and it still happens.
Avatar of leg1

ASKER

In fact I removed all event handlers for the text box, I right click on it, and off it goes.  It now switched targets and focus ended up on a different control.
ASKER CERTIFIED SOLUTION
Avatar of AnswerTheMan
AnswerTheMan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of leg1

ASKER

Aha!
I've managed to outfox myself again.
I didn't give a complete description above in the interest of brevity.  I thought I was explaining everything that was relevant but I left out something.  The textbox with the mouseup event handler is placed over a listbox to allow the user to modify entries in the listbox.  (the user is really modifying the textbox which gets placed over the listbox entry which is selected).

What I didn't realize was that a "lostfocus" event handler for the listbox sets the textbox.visible to false, but this occurs at the time that I right-click on the textbox.  The interesting thing is that the textbox mouseup event handler still fires even though the textbox is now invisible.  So it never occurred to me that the textbox was invisible (also, it looks like the listbox entry below it).

I don't understand how the next control to receive the focus is selected.  A few times it was the following tabindex but other times it is not.

At least I have more confidence in VB and can dig my way out

Thanks for your support.

As far as awarding the points, it was of course impossible to answer, given the data I supplied, but I guess AnswerTheMan came closest in saying "check all that very carfully".
I'll accept your answer tomorrow so you don't have to pay points to see my response.