How to find the object the mouse is hovering over VB.NET - vb.net

I am making an application in VB.NET and would like to know if there is a way to get a pointer to the object the mouse is hovering over when the mouse click is released, essentially a drag-drop operation, however, I would much rather not have to use coordinates, since it would make my program very inefficient.

Related

WinRT - ImageButton for transparent PNGs

I'm using XAML Toolkit ImageButton control to be able to create normal and pressed states for a button. Code is:
<toolkit:ImageButton NormalStateImageSource="ms-appx:///Assets/1_off.png"
PressedStateImageSource="ms-appx:///Assets/1_on.png"
Width="500"
Height="200">
</toolkit:ImageButton>
Issue I'm facing is, say I have a shape which isn't rectangle or square. For example I have PNGs for star and arrow object. Is there a way to set their boundary corresponding to shape? If not, please advice the best approach to handle such scenarios.
There are two options I tried
When clicking using mouse or touch - you'd check the last position of the pointer before click and see if the image in your button has a non-transparent pixel at that position.
Pros:
It's simpler than option 2.
You get most precise information
Cons:
You can't tell if a button got clicked with mouse, touch, pen, keyboard or by narrator using automation, so you could end up filtering out keyboard clicks just because the mouse cursor is a bit off. You could possibly use some heuristics like how long ago was the pointer move or pointer down event before the click event, but it's a bit hacky and might be unreliable.
Generate a vector path for your image and put it in the button template as a Path element with Fill="Transparent", then mark any other non-transparent or hit testable template elements (buttons, borders with Background="Transparent", etc.) as IsHitTestVisible="false".
Pros:
Doesn't break any input methods
Can be quite precise
For some shapes like a circle - the Path.Data could be quite simple or you could even use something like an Ellipse element instead
Cons:
You need to generate the path somehow
A complex path might adversely affect performance
A better solution overall in most cases is to leave the hit-testable area rectangular. The reason is - an arbitrary shape is a finicky and unreliable hit test target so it makes clicking your button more difficult. Using the default rectangular border or at most - an ellipse shape is a lot simpler and more usable.

Movable objects around a wxPanel

In wxWidgets, I would like to have 2 objects on a wxPanel joined by a line and with a mouse down event to relocate the position of either of the 2 objects (The line should automatically be redrawn to follow the new position of the objects). I have tried using wxPaintDC to draw the initial position of the 2 objects (Custom created with mouse click events) and using dc.DrawLine to join these 2 objects together with a line. How should I proceed to allow make those 2 objects movable (mouse down event) along with the line? Can this even be achieve?
Of course it's possible (just about everything is, it's "only" a matter of effort), but it's not completely trivial and you may want to use OGL which does it for you. On the flip side, OGL is very old and completely unmaintained since a long time, so if your needs are really simple, it's probably still better to do it yourself.
If you do, here are some hints:
For mouse handling, you first need an (efficient if possible) hit testing function.
Once you have it, it's easy to detect where a click happens and what object is under it and start moving it if it makes sense. To be more user friendly, the move shouldn't start immediately, but wait until either the mouse moves a little, or stays pressed for some longer time (this will avoid accidental moves).
When the user is dragging the mouse you will get wxEVT_MOTION events. Use wxMouseEvent::Dragging() in your handler to check whether any mouse button is pressed.
Whatever you do, you must always draw from your wxEVT_PAINT handler, i.e. if an object moves, you must not redraw it immediately, but update its position, invalidate the area taken by it before and after the move (invalidating everything is simpler, but less efficient) and draw it from your OnPaint().
You want double buffering to avoid flicker, see wxAutoBufferedPaintDC

Microsoft Visio Dynamic Connectors

I'm creating a bunch of flowcharts for data mapping through this database I'm working with, however it's getting quite messy and I was looking for a solution. Right now I have a ton of lines connecting all the variables together, but I was wondering if there is a way to add mouse over events to a text object or something so that when you hover over it, it display a connecting arrow to whatever it is related to; and removing your mouse from the object would make the connector disappear.
Does visio have any sort of support for this type of action in macros or in the ShapeSheet?
I don't know of any mouseover event in Visio, but there is a mouse move event. So every time the mouse moves you find out if the mouse is over one of your shapes, and if so then draw your arrow, if not, delete any existing arrow(s).
Finding the shapes under the mouse, quickly, may be a challenge. I don't know of any Visio routine to get the shapes that occupy an x, y point. You can draw a circle and use the SpatialNeighbors routine to find other shapes at that point.

How do I change windows skin in api

I really wonder how winamp did it. I tried to change a drawing code to draw on title bar at ncpaint. it was run well but it was complex and it didn't draw,choosing another window.
I searched some source code or article but they used other ways... how do I do it?...
Well, Winamp just creates a borderless, decorationless window, and draws everything itself. Important is, that you still can attach a sysmenu to the window, so that a right click on the taskbar button gives the usual options.
If you want to get fancy you can process the WM_NCPAINT message to perform frame and title drawing yourself on a decorated window: http://msdn.microsoft.com/en-us/library/windows/desktop/dd145212(v=vs.85).aspx
But the easier solution actually is to just emulate the standard Windows decorations and synthesize the events the standard buttons do.

How to implement mouse dragging in Visual Basic?

I need to create a quick-n-dirty knob control in Visual Basic 2005 Express, the value of which is incremented/decremented by "grabbing" it with the mouse and moving the cursor up/down. Because the knob itself doesn't move, I need to keep tracking the mouse movement outside of the rectangle of the control.
I use a Label with an ImageList to implement this (I have a list of 127 bitmaps representing the knob in various positions).
Which events should I react to?
You need the control to handle three events: Mouse Down, Mouse Move and Mouse Up. On the Mouse Down event, you will need to capture the mouse. This means the mouse messages are sent to the control that has the capture. In the mouse move event, if the input is captured then update the displayed image depending on the amount the mouse moved. In the mouse up event, release the capture if the input is captured.
The boolean jjnguy suggests is unnecessary as the Capture property of a Control is readable so it's possible to determine if the capture has been set.
Your problem will be to determine which bitmap you have to display based upon the coordinates the mouse reports in the mouse_move event. You'll need to perform some magic to transform the coordinates and come up with a value that you can use to pick the right image.
It doesn't sound too complicated, just a little bit of trial and error in the math. Skizz has already show you how to capture the events.