I currently have a Console application. How would I draw graphics to the screen without having to have a form.
EDIT - based on CuddleBunny's comment, I have 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 it helps.
old faulty answer
You can get the hwnd of another window and draw on that. I'm not sure how to draw on the entire screen though, I've always wondered that 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);
}
You have to create a window of some kind to draw graphics to. You can't just draw directly to the screen.
You can draw on the entire screen without a window using directx if you create a full screen directdrawsurface. The screen is all yours (no windows desktop at all).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With