[英]using painteventargs in a c# form; how do I draw a larger image to the Graphics object (with scrollbars as well)?
[英]How do I draw graphics in C# without a form
我目前有一个控制台应用程序。 如何在不需要表格的情况下将图形绘制到屏幕上。
编辑 - 根据CuddleBunny的评论,我创建了一个基本上“在屏幕上绘制图形”的类。
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());
}
}
}
希望能帮助到你。
老错误的答案
你可以得到另一个窗口的hwnd并绘制它。 我不知道如何在整个屏幕上画画,我总是想知道自己。
一个简单的例子:
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);
}
你必须创建一个窗口来绘制图形。 你不能直接画到屏幕上。
如果您创建全屏直接绘图表,则可以使用directx在没有窗口的情况下在整个屏幕上绘图。 屏幕全是你的(根本没有Windows桌面)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.