[問題] 用Graphics卻出不來
沒有錯誤訊息
但是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
推
11/26 18:49, , 1F
11/26 18:49, 1F
→
11/26 18:52, , 2F
11/26 18:52, 2F
→
11/26 18:58, , 3F
11/26 18:58, 3F
→
11/26 18:59, , 4F
11/26 18:59, 4F
推
11/26 19:01, , 5F
11/26 19:01, 5F
→
11/26 19:01, , 6F
11/26 19:01, 6F
→
11/26 19:27, , 7F
11/26 19:27, 7F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 3 篇):