如何绘制类似隧道的效果?
How to draw a tunnel-like effect?
我知道如何在 GDI 中绘制东西,但我发现很难确定如何绘制不仅仅是正方形和圆形的实际形状。
我正在尝试通过绘制一大堆彼此重叠的正方形或矩形来绘制隧道,但我不知道如何正确定位。
这种效果怎么画?
你可以尝试这样的事情。一旦您了解了如何使用 GDI 进行绘图的基础知识,您应该能够非常轻松地完成此类操作。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Autodraw
{
public partial class Form1 : Form
{
private bool canDraw;
public class NPanel : Panel
{
protected override bool DoubleBuffered
{
get
{
return base.DoubleBuffered;
}
set
{
base.DoubleBuffered = true;
}
}
}
public NPanel nPanel = new NPanel();
public Form1()
{
InitializeComponent();
this.DoubleBuffered = true;
panel = nPanel;
}
private void panel_Paint(object sender, PaintEventArgs e)
{
if (canDraw)
{
for (int r = 0; r <= 255; r++)
{
e.Graphics.DrawRectangle(new Pen(Color.FromArgb(r, 0, 0), 1), r, r, r, r);
}
for (int r = 0; r <= 255; r++)
{
e.Graphics.DrawRectangle(new Pen(Color.FromArgb(0, r, 0), 1), r, r, r, r);
}
for (int r = 0; r <= 255; r++)
{
e.Graphics.DrawRectangle(new Pen(Color.FromArgb(0, 0, r), 1), r, r, r, r);
}
}
}
private void timer_Tick(object sender, EventArgs e)
{
this.Refresh();
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == (char)Keys.Escape)
{
timer.Stop();
canDraw = false;
}
}
private void Form1_Shown(object sender, EventArgs e)
{
canDraw = true;
timer.Start();
}
}
}
我知道如何在 GDI 中绘制东西,但我发现很难确定如何绘制不仅仅是正方形和圆形的实际形状。
我正在尝试通过绘制一大堆彼此重叠的正方形或矩形来绘制隧道,但我不知道如何正确定位。
这种效果怎么画?
你可以尝试这样的事情。一旦您了解了如何使用 GDI 进行绘图的基础知识,您应该能够非常轻松地完成此类操作。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Autodraw
{
public partial class Form1 : Form
{
private bool canDraw;
public class NPanel : Panel
{
protected override bool DoubleBuffered
{
get
{
return base.DoubleBuffered;
}
set
{
base.DoubleBuffered = true;
}
}
}
public NPanel nPanel = new NPanel();
public Form1()
{
InitializeComponent();
this.DoubleBuffered = true;
panel = nPanel;
}
private void panel_Paint(object sender, PaintEventArgs e)
{
if (canDraw)
{
for (int r = 0; r <= 255; r++)
{
e.Graphics.DrawRectangle(new Pen(Color.FromArgb(r, 0, 0), 1), r, r, r, r);
}
for (int r = 0; r <= 255; r++)
{
e.Graphics.DrawRectangle(new Pen(Color.FromArgb(0, r, 0), 1), r, r, r, r);
}
for (int r = 0; r <= 255; r++)
{
e.Graphics.DrawRectangle(new Pen(Color.FromArgb(0, 0, r), 1), r, r, r, r);
}
}
}
private void timer_Tick(object sender, EventArgs e)
{
this.Refresh();
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == (char)Keys.Escape)
{
timer.Stop();
canDraw = false;
}
}
private void Form1_Shown(object sender, EventArgs e)
{
canDraw = true;
timer.Start();
}
}
}