Results 1 to 6 of 6

Thread: .Click + .MouseEnter events on the same object at the same time

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2018
    Posts
    3

    Question .Click + .MouseEnter events on the same object at the same time

    Hello everyone,

    I have a little problem with VB :
    I have a PictureBox, which is clickable and can fire an event. I decided to add an event handler for .MouseEnter which, when the mouse comes in the PictureBox physical borders sets to 'true' the .Visible attribute to a label that completely covers the PictureBox.
    The problem is, I want to able to click the PictureBox(or the label, it doesn't matter in my case). When I click, I see for a few milliseconds the picture in the PictureBox that's under the label with the label disappearing, but no event is fired whatsoever, as if I was clicking in void.
    I tried both solutions :
    subname() Handles PictureBox.Click
    subname() Handles Label.Click
    but neither of them work, and I don't particularly want to add buttons, my interface is already quite full.

    To make it short, what I would like to know is :
    Is it possible to click on any of the two objects (PictureBox or Label) with the MouseEnter event ?

    Thanks a lot for your help, I hope my explanations were clear enough,
    Have a great day.

  2. #2
    Frenzied Member
    Join Date
    Nov 2017
    Posts
    1,646

    Re: .Click + .MouseEnter events on the same object at the same time

    What code do you have in the .Click event? Is it possible that the code in the .Click event is firing? Have you set a breakpoint inside the .Click event to see if that code is ever reached?

    If the .Click event is coded to do something like hide the Label control again so that the PictureBox is visible, it probably is working exactly as coded, it hides the Label so that the PictureBox is again visible (like you say, for a few milliseconds), after which the .MouseEnter event is immediately triggered which puts the label back on top of the Picturebox and hides it.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2018
    Posts
    3

    Re: .Click + .MouseEnter events on the same object at the same time

    Thank you for answering,

    The code in the .click event opens a new form, which is a code that I did in other .click events fired by other objects and it works for the others. My only way of telling that the .click in not working is that no form is not popping up.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    36,285

    Re: .Click + .MouseEnter events on the same object at the same time

    That's not a good enough test. The first thing you need to do is use a breakpoint. Testing by looking for side effects is risky, because you are not just testing whether the condition is happening (the click event is being called, in this case), but that the side effect is behaving correctly (the form is showing). A breakpoint will tell you whether the click event is happening at the right time, or not. If it is, then you have to figure out why the form isn't showing. If it is not, then that's a different issue.

    If you aren't familiar with breakpoints, you need to be, so either look them up, or ask about them. Nothing is more useful, including this forum.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2018
    Posts
    3

    Re: .Click + .MouseEnter events on the same object at the same time

    Okay, I'll check them out and if it's not working I'll try another way,

    Thanks a lot for your help,
    Good evening

  6. #6
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: .Click + .MouseEnter events on the same object at the same time

    Based on the code you've posted I can tell you: you have a problem. If you want more information, you have to show me more.

    My psychic guess is you're trying to do something that won't work. It sounds like you want a MouseEnter on the PictureBox to display a Label that covers the entire PictureBox. Then you want to be able to click on the PictureBox. that's impossible. You can't click on something if it's covered by another thing.

    OptionBase1 is making some guesses, and I think they are good guesses, but I don't like making guesses anymore. They lead me to spend hours describing solutions that are wasted if I guess wrong. But if it's true that clicking the Label hides the label, then that transition would make the PictureBox in view again and probably eligible to raise a MouseEnter again, which would display the Label again.

    Also consider: you said the click is supposed to display another form. That form will take focus, which also mucks with whether MouseEnter might be raised again.

    What also really concerns me is this:
    Is it possible to click on any of the two objects (PictureBox or Label) with the MouseEnter event ?
    Most professionally: no. The only thing capable of clicking is a mouse or pointing device.

    Technically: yes. You can write code that sends the same Windows messages that using the mouse would send. This is considered unprofessional and hacky and there is almost always a better way to accomplish the goal.

    Worrisome psychic guess: many novices try to accomplish "clicking" by manually calling one of their own Click event handlers. Like the last paragraph, this is not considered professional or even "journeyman". There is almost always a better way to accomplish the goal.

    Please clarify what you are trying to do, and what code you've written to accomplish that goal. Write it with such excruciating detail that you think if you handed it to someone else, they could write the program exactly as you did. If you fail to write with that level of detail, we can't write what you wrote, so we'll be trying to fix something different.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width