看板 C_Sharp 關於我們 聯絡資訊
沒有錯誤訊息 但是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
Rezzard:你的程式碼在我的專案能畫出你的需求... 11/26 18:49
Rezzard:你程式有透過事件處理嗎...+= MouseEventHandler( 此類? 11/26 18:52
hirabbitt:這段是我99%的程式碼了耶 沒有用到你說的東西 11/26 18:58
hirabbitt:然後有40%也是複製別人的程式碼 就奇怪怎麼出不來=.= 11/26 18:59
Rezzard:你點pictureBox1屬性裡面有個事件..找MouseDown跟MouseMov 11/26 19:01
Rezzard:連點兩下...事件就會幫你處理進去了 你試看看 11/26 19:01
hirabbitt:有了!!! 大感謝 11/26 19:27