📄 mainform.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace UseGdiPlus
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
this.Hide();
}
private void MainForm_Paint(object sender, PaintEventArgs e)
{
Color[] colors = new Color[]{
Color.Red,
Color.Green,
Color.Blue,
Color.Yellow
};
Pen p = new Pen(Color.Empty);
int initX = 10, initY = 10;
int initW = 200, initH = 150;
int incr = 20;
for(int i = 0; i < 4; i++)
{
p.Color = colors[i];
p.Width = (i + 1) * 3.0f;
int x = initX + i * incr;
int y = initY + i * incr;
int w = initW - i * incr * 2;
int h = initH - i * incr * 2;
e.Graphics.DrawRectangle(p, x, y, w, h);
}
p.Dispose();
}
private void MainForm_MouseMove(object sender, MouseEventArgs e)
{
Graphics g = this.CreateGraphics();
Brush b = new SolidBrush(Color.Red);
g.FillRectangle(b, e.X - 1, e.Y - 1, 1, 1);
g.FillRectangle(b, -10, -10, 100, 100);
b.Dispose();
g.Dispose();
}
[DllImport("coredll", EntryPoint = "GetDC")]
static extern IntPtr GetDC(IntPtr hwnd);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -