Draw outside the area of a form

0

Using C # with the Windows Forms Application project type is it possible to draw things out of the form? I would like to draw a mouse-stretchable and repositionable square, where should I start?

Here's an example image of what I'm looking for:

The goal is actually to take a print from such an area, if it had another mode it would be very good too:)

    
asked by anonymous 02.08.2016 / 11:01

1 answer

1

Second this response in the OS is possible in two ways, both with disabilities:

var f = new Form();
f.BackColor = Color.White;
f.FormBorderStyle = FormBorderStyle.None;
f.Bounds = Screen.PrimaryScreen.Bounds;
f.TopMost = true;
f.TransparencyKey = Color.White;

It's easy for the user to leave his application and not notice with ALT + TAB , outside it will not work. In other words, it is a beautiful gambiarra.

Or you may not use a Form . A simplified code would look like this (it might be better written):

[DllImport("User32.dll")]
public static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("User32.dll")]
public static extern void ReleaseDC(IntPtr hwnd, IntPtr dc);

...


IntPtr desktopPtr = GetDC(IntPtr.Zero);
Graphics g = Graphics.FromHdc(desktopPtr);
var b = new SolidBrush(Color.White);
g.FillRectangle(b, new Rectangle(0, 0, 1920, 1080)); //o algoritmo seria mais sofisticado
g.Dispose();
ReleaseDC(IntPtr.Zero, desktopPtr);

If the canvas is updated, the drawing will disappear, you can redesign it.

In practice the solution goes through something much more sophisticated.

If I find some other method, I'll update it here.

    
02.08.2016 / 13:24