Draw outside a form area

Asked

Viewed 226 times

0

Using C# with Windows Forms Application project type is it possible to draw things out of the form? I would like to draw a square that can be stretched by the mouse and repositioned, where I should start?

Follow an image as an example of what I seek:

The goal actually is kind of to take a print of such area, if there were any other way would be very good too :)

  • Did the answer solve what you were looking to know? Do you think you can accept it now? If not, you need something else to be improved?

1 answer

1

Second that 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 is easy for the user to leave their application and not even notice with ALT+TAB, out of it won’t work. In other words, it’s a beautiful gambiarra.

Or you might not use one Form. A code would simply be like this (it can 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);

I put in the Github for future reference.

If the screen is updated, the drawing will disappear, you can go redesigning it.

In practice the solution is something much more sophisticated.

If I find any other method, I update here.

  • I was thinking of a form with a transparent background, then the user would drag by the top of the window and resize normally as with a window, what do you think?

  • This is what I answered, but it does not mean that it will work as expected always, depends on matching with the user do nothing different than expected, which is not ideal.

  • So what kind of design/language would you do this?

  • Maybe in C# even, as I never needed to, I never studied deeply.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.