How to draw graphics in C # without form

I currently have a console application. How to draw graphics on the screen without having to have a shape.

+5
source share
3 answers

EDIT - Based on the CuddleBunny comment, I created a class that will basically "draw graphics on the screen."

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication4 { class test : Form { public test() : base() { this.TopMost = true; this.DoubleBuffered = true; this.ShowInTaskbar = false; this.FormBorderStyle = FormBorderStyle.None; this.WindowState = FormWindowState.Maximized; this.BackColor = Color.Purple; this.TransparencyKey = Color.Purple; } protected override void OnPaint(PaintEventArgs e) { e.Graphics.DrawRectangle(Pens.Black, 0, 0, 200, 200); this.Invalidate(); //cause repaint } public static void Main(String[] args) { Application.Run(new test()); } } } 

Hope this helps.

old wrong answer


You can get hwnd of another window and do it. I'm not sure how to draw in full screen, although I always thought about it myself.

A simple example:

  Process p = Process.GetProcessById(0); //id of the process or some other method that can get the desired process using (Graphics g = Graphics.FromHwnd(p.MainWindowHandle)) { g.DrawRectangle(Pens.Black, 0, 0, 100, 100); } 
+7
source

You need to create some kind of window for drawing graphics. You cannot just draw directly on the screen.

+2
source

You can draw a full screen without a window using directx if you are creating a full-screen line. The screen is all yours (there is no Windows desktop at all).

+1
source

Source: https://habr.com/ru/post/952207/


All Articles