Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop Mouse click on form

Status
Not open for further replies.

waytech2003

Programmer
Jul 14, 2003
316
US
I have a minor, but anoying problem. My main form1 opens up form2 (vbmodal). On form2, I have a flexgrid that the user double-clicks on to make their selection. As soon as they do, I hide form2, and form1 gets some information from a few public variables on form2. I then unload form2 and set it to nothing.

This all works ok, but sometimes as form2 hides, the users mouse pointer may be over a command button on form1. When they are that command button triggers. How can I make form1 reject the mouse action?

Open to any and all suggestions.

Wayne
 
Doesn't it work if you do Form1.Enabled = False in the code where you open Form2, and then Form1.Enabled = True in the Form_QueryUnload event of Form2?

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Andy;

No, I just tried it. Previously I did Disable form1 just before opening form2. Then I Enabled form1 when I set form2 to nothing. My way, nor your way works.
 
try to disable the command button in form 1 after showing the form 2 and enable it back when form 2 is unloaded.
on the form2 load event or activate events enter the code:
form1.commandbutton1.enabled = false

on the form2_queryUnload event enter the code:
form1.commandbutton1.enabled = true

this will enable the command button in form1 after the form2 unload.

I hope this will work for you as it work for me :)

 
tonioJ

Just tried your idea, still gives the same effect. I am using this on Win XP. Maybe your idea works on other versions, but my XP still reacts the same.

At this point I have decided to not to allow DblClick on the form2 grid, the user must hit <Enter>. The other fix I came up with is to move the command button to the far right on form1. I will wait a few days to see if I get other ideas at fixing this problem.
 
In the Command button click event on Form1, you could try adding:

If Form2.Visible = False Then
'Do your stuff
Else: 'Do nothing
End If

[gray]Experience is something you don't get until just after you need it.[/gray]
 
bigalbigal;

Thanks, but this did not do it either, exact same effect
 
Try this:

In the form2_Load() event disable form1 buttons (form1.enable = false). Then in the form1_Activate() event place a timer that will time out then enable the form1 buttons. So if the button gets clicked when form2 unloads, nothing should happen because the buttons on form1 are disabled until a future time, say 1 second.

Place this code in form1_Activate() event.
Code:
Dim StartTime as long

StartTime = GetTickCount
Do
 DoEvents
Loop Until GetTickCount > StartTime + 1000
form1.Enable = True



HyperEngineer
If it ain't broke, it probably needs improvement.
 
I have tried everyone's suggestions, but all attempts with timer and/or form1.enable failed to work. I have however created a solution.

On form1, I made a global Boolean flag that I set to True, just before I open form2. Then in the form1.command.click event, I check to see if the flag is True. If it is, I False it, and exit the sub. Now the first click is rejected and all is OK.

Thanks all, for your suggestions. Maybe my solution will help others.

Wayne
 
@Wayne,

are you using MDI form? If yes, there should be no problem with this. if you are not using MDI form then try this code on the Command button event that will show Form2

private sub Command1_Click
Form2.Show 1, Form1
end sub

The code above will make the Form1 as the owner of Form2. In this way it will make the form2 as the only active form in your program.
 
UPDATE:

I found the problem!!!

I was using a SSCommand button, not a standard Command button. When I replaced it with a standard button, the problem went away.[blush]

It seems the the SSCommand button fires on Mouse Up too.
 
tonioJ;

Not using MDI. Tried your suggestion, same results.

Again, thanks to all who tried to help.

Wayne
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top