Results 1 to 2 of 2

Thread: Image control & events

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2016
    Posts
    216

    Image control & events

    How can i force an image control (in WPF) to react to the assigned mouse events when there is no image assigned? Took over an our to finally realize WPF seems to disable image controls when they are empty. (assuming this would have a code solution.. )

  2. #2
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Image control & events

    Hi Cwitt, the "imageless" Image control isn't really disabled -- at least the Initialized event still fires regardless. But mouse events only fire when the pointer is over non-transparent areas of the image.

    The Image has to be put into some or other container such as a Border control.
    So, for example, you could get the mouse position (in device independent units) like this:
    Code:
        Private Sub Image1_MouseMove(sender As Object, e As MouseEventArgs) Handles Image1.MouseMove, Border1.MouseMove
            Console.WriteLine(e.GetPosition(Border1))
        End Sub
    This assumes that Image1 has its Stretch property set to Fill and StretchDirection to Both, so the Image coordinates will be the same as the Border coordinates (equivalent to PictureBox.SizeMode.Stretch).

    If you use a different Image setting such as UniformToFill (more like PictureBox.SizeMode.Zoom) you'd have to do some arithmetic to get the coordinates to be consistent. It would be easier in that case just to use the Border1.PreviewMouseMove event instead of MouseMove, since that would give the same mouse position whether or not the image is showing.

    BB

Tags for this Thread

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