سلام
انا هنا فى الكود التالى بجاول ارسم خط على فورمة
و لكن هناك error لا استطيع التغلب عليه
انا مبتدئ c# على فكرة
و هاك الكود
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace painter
{
public partial class Form_draw : Form
{
Point p_start = new Point();
Point p_end = new Point();
public Form_draw()
{
InitializeComponent();
this.Controls.AddRange(new Control[] { Line_button, oval_button, rect_button, roundrect_button, erase_button });
}
public void Line_button_MouseDown(object sender, MouseEventArgs e)
{
p_start.X = e.X;
p_start.Y = e.Y;
p_end = p_start;
}
public void Line_button_MouseMove(object sender, MouseEventArgs e)
{
Form thisform = new Form();
p_end.X = e.X;
p_end.Y = e.Y;
if (Line_button.Click+=new System.EventHandler(sender, e))
{
ControlPaint.DrawReversibleLine(thisform.PointToScreen(p_start), thisform.PointToScreen(p_end), Color.Black);
p_end = new Point(e.X, e.Y);
ControlPaint.DrawReversibleLine(thisform.PointToScreen(p_start), thisform.PointToScreen(p_end), Color.Black);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Line_button_MouseUp(object sender, MouseEventArgs e)
{
Form thisform = new Form();
Graphics g = thisform.CreateGraphics();
Pen p = new Pen(Color.Blue, 2);
if (Line_button.Click+=new System.EventHandler(sender, e))
{
ControlPaint.DrawReversibleLine(thisform.PointToScreen(p_start), thisform.PointToScreen(p_end), Color.Black);
g.DrawLine(p, p_start, p_end);
}
}
private void Line_button_Click(object sender, EventArgs e)
{
}
}
}
و ده بقى كود الأدوات الى انا عملتلها drag and drop
namespace painter
{
public partial class Form_draw
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.button8 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.erase_button = new System.Windows.Forms.Button();
this.roundrect_button = new System.Windows.Forms.Button();
this.rect_button = new System.Windows.Forms.Button();
this.oval_button = new System.Windows.Forms.Button();
this.Line_button = new System.Windows.Forms.Button();
this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.BackColor = System.Drawing.SystemColors.ControlDark;
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Controls.Add(this.button8, 1, 3);
this.tableLayoutPanel1.Controls.Add(this.button7, 0, 3);
this.tableLayoutPanel1.Controls.Add(this.button6, 1, 2);
this.tableLayoutPanel1.Controls.Add(this.erase_button, 0, 2);
this.tableLayoutPanel1.Controls.Add(this.roundrect_button, 1, 1);
this.tableLayoutPanel1.Controls.Add(this.rect_button, 0, 1);
this.tableLayoutPanel1.Controls.Add(this.oval_button, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.Line_button, 0, 0);
this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 35);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 4;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50.42017F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 49.57983F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 69F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 72F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(147, 274);
this.tableLayoutPanel1.TabIndex = 0;
//
// button8
//
this.button8.Location = new System.Drawing.Point(76, 204);
this.button8.Name = "button8";
this.button8.Size = new System.Drawing.Size(67, 67);
this.button8.TabIndex = 7;
this.button8.Text = "button8";
this.button8.UseVisualStyleBackColor = true;
//
// button7
//
this.button7.Location = new System.Drawing.Point(3, 204);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(67, 67);
this.button7.TabIndex = 6;
this.button7.Text = "button7";
this.button7.UseVisualStyleBackColor = true;
//
// button6
//
this.button6.Location = new System.Drawing.Point(76, 135);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(67, 63);
this.button6.TabIndex = 5;
this.button6.Text = "button6";
this.button6.UseVisualStyleBackColor = true;
//
// erase_button
//
this.erase_button.Image = global::painter.Properties.Resources.erase;
this.erase_button.Location = new System.Drawing.Point(3, 135);
this.erase_button.Name = "erase_button";
this.erase_button.Size = new System.Drawing.Size(67, 63);
this.erase_button.TabIndex = 4;
this.erase_button.UseVisualStyleBackColor = true;
//
// roundrect_button
//
this.roundrect_button.Image = global::painter.Properties.Resources.roundrect;
this.roundrect_button.Location = new System.Drawing.Point(76, 70);
this.roundrect_button.Name = "roundrect_button";
this.roundrect_button.Size = new System.Drawing.Size(67, 59);
this.roundrect_button.TabIndex = 3;
this.roundrect_button.UseVisualStyleBackColor = true;
//
// rect_button
//
this.rect_button.Image = global::painter.Properties.Resources.rect;
this.rect_button.Location = new System.Drawing.Point(3, 70);
this.rect_button.Name = "rect_button";
this.rect_button.Size = new System.Drawing.Size(67, 59);
this.rect_button.TabIndex = 2;
this.rect_button.UseVisualStyleBackColor = true;
//
// oval_button
//
this.oval_button.Image = global::painter.Properties.Resources.circle;
this.oval_button.Location = new System.Drawing.Point(76, 3);
this.oval_button.Name = "oval_button";
this.oval_button.Size = new System.Drawing.Size(67, 61);
this.oval_button.TabIndex = 1;
this.oval_button.UseVisualStyleBackColor = true;
//
// Line_button
//
this.Line_button.Image = global::painter.Properties.Resources.line;
this.Line_button.Location = new System.Drawing.Point(3, 3);
this.Line_button.Name = "Line_button";
this.Line_button.Size = new System.Drawing.Size(67, 61);
this.Line_button.TabIndex = 8;
this.Line_button.UseVisualStyleBackColor = true;
this.Line_button.Click += new System.EventHandler(this.Line_button_Click);
this.Line_button.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Line_button_MouseDown);
this.Line_button.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Line_button_MouseMove);
this.Line_button.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Line_button_MouseUp);
//
// Form_draw
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ButtonShadow;
this.ClientSize = new System.Drawing.Size(783, 482);
this.Controls.Add(this.tableLayoutPanel1);
this.Name = "Form_draw";
this.Text = "painter";
this.Load += new System.EventHandler(this.Form1_Load);
this.tableLayoutPanel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.Button button8;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button erase_button;
private System.Windows.Forms.Button roundrect_button;
private System.Windows.Forms.Button rect_button;
private System.Windows.Forms.Button oval_button;
private System.Windows.Forms.Button Line_button;
}
}
المشكلة فى الكود الاول كانت فى السطرين دول
if (Line_button.Click+=new System.EventHandler(sender, e))
ونفس السطر فى الدالة بتاعة الmouseup()
و ياريت لو حد يقولى ازاى اقدر ارسم على panel
بدل الform
شكرا
معلش انا اعدت طبع الكود تانى لانه متنسقش المرة الاولى
namespace painter
{
public partial class Form_draw
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.button8 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.erase_button = new System.Windows.Forms.Button();
this.roundrect_button = new System.Windows.Forms.Button();
this.rect_button = new System.Windows.Forms.Button();
this.oval_button = new System.Windows.Forms.Button();
this.Line_button = new System.Windows.Forms.Button();
this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.BackColor = System.Drawing.SystemColors.ControlDark;
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Controls.Add(this.button8, 1, 3);
this.tableLayoutPanel1.Controls.Add(this.button7, 0, 3);
this.tableLayoutPanel1.Controls.Add(this.button6, 1, 2);
this.tableLayoutPanel1.Controls.Add(this.erase_button, 0, 2);
this.tableLayoutPanel1.Controls.Add(this.roundrect_button, 1, 1);
this.tableLayoutPanel1.Controls.Add(this.rect_button, 0, 1);
this.tableLayoutPanel1.Controls.Add(this.oval_button, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.Line_button, 0, 0);
this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 35);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 4;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50.42017F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 49.57983F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 69F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 72F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(147, 274);
this.tableLayoutPanel1.TabIndex = 0;
//
// button8
//
this.button8.Location = new System.Drawing.Point(76, 204);
this.button8.Name = "button8";
this.button8.Size = new System.Drawing.Size(67, 67);
this.button8.TabIndex = 7;
this.button8.Text = "button8";
this.button8.UseVisualStyleBackColor = true;
//
// button7
//
this.button7.Location = new System.Drawing.Point(3, 204);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(67, 67);
this.button7.TabIndex = 6;
this.button7.Text = "button7";
this.button7.UseVisualStyleBackColor = true;
//
// button6
//
this.button6.Location = new System.Drawing.Point(76, 135);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(67, 63);
this.button6.TabIndex = 5;
this.button6.Text = "button6";
this.button6.UseVisualStyleBackColor = true;
//
// erase_button
//
this.erase_button.Image = global::painter.Properties.Resources.erase;
this.erase_button.Location = new System.Drawing.Point(3, 135);
this.erase_button.Name = "erase_button";
this.erase_button.Size = new System.Drawing.Size(67, 63);
this.erase_button.TabIndex = 4;
this.erase_button.UseVisualStyleBackColor = true;
//
// roundrect_button
//
this.roundrect_button.Image = global::painter.Properties.Resources.roundrect;
this.roundrect_button.Location = new System.Drawing.Point(76, 70);
this.roundrect_button.Name = "roundrect_button";
this.roundrect_button.Size = new System.Drawing.Size(67, 59);
this.roundrect_button.TabIndex = 3;
this.roundrect_button.UseVisualStyleBackColor = true;
//
// rect_button
//
this.rect_button.Image = global::painter.Properties.Resources.rect;
this.rect_button.Location = new System.Drawing.Point(3, 70);
this.rect_button.Name = "rect_button";
this.rect_button.Size = new System.Drawing.Size(67, 59);
this.rect_button.TabIndex = 2;
this.rect_button.UseVisualStyleBackColor = true;
//
// oval_button
//
this.oval_button.Image = global::painter.Properties.Resources.circle;
this.oval_button.Location = new System.Drawing.Point(76, 3);
this.oval_button.Name = "oval_button";
this.oval_button.Size = new System.Drawing.Size(67, 61);
this.oval_button.TabIndex = 1;
this.oval_button.UseVisualStyleBackColor = true;
//
// Line_button
//
this.Line_button.Image = global::painter.Properties.Resources.line;
this.Line_button.Location = new System.Drawing.Point(3, 3);
this.Line_button.Name = "Line_button";
this.Line_button.Size = new System.Drawing.Size(67, 61);
this.Line_button.TabIndex = 8;
this.Line_button.UseVisualStyleBackColor = true;
this.Line_button.Click += new System.EventHandler(this.Line_button_Click);
this.Line_button.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Line_button_MouseDown);
this.Line_button.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Line_button_MouseMove);
this.Line_button.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Line_button_MouseUp);
//
// Form_draw
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ButtonShadow;
this.ClientSize = new System.Drawing.Size(783, 482);
this.Controls.Add(this.tableLayoutPanel1);
this.Name = "Form_draw";
this.Text = "painter";
this.Load += new System.EventHandler(this.Form1_Load);
this.tableLayoutPanel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.Button button8;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button erase_button;
private System.Windows.Forms.Button roundrect_button;
private System.Windows.Forms.Button rect_button;
private System.Windows.Forms.Button oval_button;
private System.Windows.Forms.Button Line_button;
}
}using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace painter
{
public partial class Form_draw : Form
{
Point p_start = new Point();
Point p_end = new Point();
public Form_draw()
{
InitializeComponent();
this.Controls.AddRange(new Control[] { Line_button, oval_button, rect_button, roundrect_button, erase_button });
}
public void Line_button_MouseDown(object sender, MouseEventArgs e)
{
p_start.X = e.X;
p_start.Y = e.Y;
p_end = p_start;
}
public void Line_button_MouseMove(object sender, MouseEventArgs e)
{
Form thisform = new Form();
p_end.X = e.X;
p_end.Y = e.Y;
if (Line_button.Click+=new System.EventHandler(sender, e))
{
ControlPaint.DrawReversibleLine(thisform.PointToScreen(p_start), thisform.PointToScreen(p_end), Color.Black);
p_end = new Point(e.X, e.Y);
ControlPaint.DrawReversibleLine(thisform.PointToScreen(p_start), thisform.PointToScreen(p_end), Color.Black);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Line_button_MouseUp(object sender, MouseEventArgs e)
{
Form thisform = new Form();
Graphics g = thisform.CreateGraphics();
Pen p = new Pen(Color.Blue, 2);
if (Line_button.Click+=new System.EventHandler(sender, e))
{
ControlPaint.DrawReversibleLine(thisform.PointToScreen(p_start), thisform.PointToScreen(p_end), Color.Black);
g.DrawLine(p, p_start, p_end);
}
}
private void Line_button_Click(object sender, EventArgs e)
{
}
}
}