Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a window with an arrow pointing to another window?

I would like to be able to design something similar to what you see when you get an exception in Visual Studio, a sort of window with a line connecting the window to a point in the code window. I've included a picture of this below:

Example

I notice that whenever the code window loses focus, the exception window disappears. When focused, though, I can move the window around, and the arrow continues to point at the target.

How is this being done? Specifically, how can I draw a line from one window into another?

I'm coding in C# and using Windows Forms.

like image 637
Charlie Salts Avatar asked Apr 11 '11 14:04

Charlie Salts


2 Answers

In your example, the window with the exception will not always disappear if the text box loses focus!

By investigating a little bit with the Spy++ tool (put the find window cursor exactly on the line), you will notice that the line you see between the yellow text and the exception window is contained in a window (with a transparent background) (with a class window of type "WindowsForms10.Window.8.app.0.34f5582_r41_ad1" in VS 2010). This window also has the WS_POPUP style, and is the exact bounding box of the line (its size and position fit exactly the line).

So you can do the same thing: create a transparent popup window, draw a line on it and set its location and size so that the line appears between the controls you want.

like image 50
Andrei Pana Avatar answered Oct 20 '22 05:10

Andrei Pana


I dont know exactly how its done but you may be able to do something similar with this idea.

  1. Create a new form
  2. Overide the paint event so its not drawn
  3. draw a line from one corner to another (this could vary depending on the direction of the line
  4. Size and position the form so the line runs between your two points.
  5. Not sure on the focus part yet!
like image 24
WraithNath Avatar answered Oct 20 '22 06:10

WraithNath