xynx
❔ WinForms, Drawing Box on screen that stays
got some errors and looks like the box doesnt update:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WHITEBOX
{
public partial class Form1 : Form
{
[DllImport("User32.dll")]
public static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("User32.dll")]
public static extern void ReleaseDC(IntPtr hwnd, IntPtr dc);
public Form1()
{
InitializeComponent();
}
private void tmrRefresh_Tick(object sender, EventArgs e)
{
this.Hide();
tmrRefresh.Interval = 1;
IntPtr desktopPtr = GetDC(IntPtr.Zero);
Graphics g = Graphics.FromHdc(desktopPtr);
int iXScreen = 1920;
int iYScreen = 1080;
int iXSize = 240;
int iYSize = 240;
int iX = (iXScreen / 2) - (iXSize / 2);
int iY = (iYScreen / 2) - (iYSize / 2);
Pen P = new Pen(Color.White, 1);
Rectangle rect = new Rectangle(iX, iY, iXSize, iYSize);
g.DrawRectangle(P, rect);
g.Dispose();
ReleaseDC(IntPtr.Zero, desktopPtr);
}
private void Form1_Load(object sender, EventArgs e)
{
this.Hide();
tmrRefresh.Enabled = true;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WHITEBOX
{
public partial class Form1 : Form
{
[DllImport("User32.dll")]
public static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("User32.dll")]
public static extern void ReleaseDC(IntPtr hwnd, IntPtr dc);
public Form1()
{
InitializeComponent();
}
private void tmrRefresh_Tick(object sender, EventArgs e)
{
this.Hide();
tmrRefresh.Interval = 1;
IntPtr desktopPtr = GetDC(IntPtr.Zero);
Graphics g = Graphics.FromHdc(desktopPtr);
int iXScreen = 1920;
int iYScreen = 1080;
int iXSize = 240;
int iYSize = 240;
int iX = (iXScreen / 2) - (iXSize / 2);
int iY = (iYScreen / 2) - (iYSize / 2);
Pen P = new Pen(Color.White, 1);
Rectangle rect = new Rectangle(iX, iY, iXSize, iYSize);
g.DrawRectangle(P, rect);
g.Dispose();
ReleaseDC(IntPtr.Zero, desktopPtr);
}
private void Form1_Load(object sender, EventArgs e)
{
this.Hide();
tmrRefresh.Enabled = true;
}
}
}
4 replies