作者hirabbitt (兔子)
看板C_Sharp
标题[问题] 用Graphics却出不来
时间Thu Nov 26 18:09:19 2009
没有错误讯息
但是form里面没有图
做了picturebox之後也没有
有设point
画笔也有颜色+有粗度
不知道是哪个步骤弄错了
QQ
程式码在下面
因为试了很多方式
所以有点乱
请帮我看一下
谢谢
using System.Drawing;
public partial class Form1 : Form
{
Point p1 = new Point(400, 400);
Point p2 = new Point(50, 50);
Point[] p3 = new Point[4];
Color c1 = Color.Red;
Pen pe1 = new Pen(Color.Red, 3);
private Graphics g2;
private Point point1;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
button1.BackColor = c1;
pe1.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
p3[0] = new Point(0, 0);
p3[1] = new Point(0, 120);
p3[2] = new Point(20, 120);
p3[3] = new Point(20, 0);
}
private void button1_Click(object sender, EventArgs e)
{
System.Console.WriteLine("X: " + p1.X + ", Y: " + p1.Y);
Graphics g1 = pictureBox1.CreateGraphics();
g1.DrawLine(pe1, p1, p2);
g1.DrawLines(pe1, p3);
}
private void pictureBox1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Pen pen = new Pen(Color.Black, 1);
Point point2 = new Point(e.X, e.Y);
g2.DrawLine(pen, point1, point2);
point1 = new Point(e.X, e.Y);
}
}
private void pictureBox1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
g2 = pictureBox1.CreateGraphics();
point1 = new Point(e.X, e.Y);
}
}
--
◤ __ \__◣
◢◤◢◤ ψhirabbitt
◢ ◤ ◢███◣
◢███◣
黑兔子我啊 █████
█████ 所以所以
██
●█
● █▇███
最喜欢白兔子了 ██
╱╲ ●◥█████◣● 我们要一直在一起喔
◥
╱█
╱╱ ● ◥████ ˇ
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 163.13.127.91
1F:推 Rezzard:你的程式码在我的专案能画出你的需求... 11/26 18:49
2F:→ Rezzard:你程式有透过事件处理吗...+= MouseEventHandler( 此类? 11/26 18:52
3F:→ hirabbitt:这段是我99%的程式码了耶 没有用到你说的东西 11/26 18:58
4F:→ hirabbitt:然後有40%也是复制别人的程式码 就奇怪怎麽出不来=.= 11/26 18:59
5F:推 Rezzard:你点pictureBox1属性里面有个事件..找MouseDown跟MouseMov 11/26 19:01
6F:→ Rezzard:连点两下...事件就会帮你处理进去了 你试看看 11/26 19:01
7F:→ hirabbitt:有了!!! 大感谢 11/26 19:27