class clsLine
{
//must be property, وقت نداشتم فیلد کردمشون
//p1.x<=p2.x , p1.y<=p2.y
public Point p1, p2;
public Pen pen;
public Graphics boom;
//------
}
public void Draw()
{
//چون در این فضا نمی بیند، به سطح کلاس می رود و آنها را پیدا می کند
boom.DrawLine(pen, p1, p2);
}
public void Save()
{
clsDB db1 = new clsDB("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=dbpaint.accdb");
db1.Perform(string.Format("INSERT INTO tblLine(x1,y1,x2,y2,color) VALUES({0},{1},{2},{3},'{4}')",p1.X,p1.Y,p2.X,p2.Y,pen.Color));
}
}
}
ClsEllipse:
using System;
using System.Drawing;
namespace winPaint
{
class clsEllipse
{
//must be property, وقت نداشتم فیلد کردمشون
//p1.x<=p2.x , p1.y<=p2.y
public Point p1, p2;
public Pen pen;
public Graphics boom;
//------
public clsEllipse(Point p1, Point p2, Pen pen, Graphics boom)
{
this.p1 = p1;
this.p2 = p2;
this.pen = pen;
this.boom = boom;
}
public void Draw()
{
//چون در این فضا نمی بیند، به سطح کلاس می رود و آنها را پیدا می کند
boom.DrawEllipse(pen, p1.X,p1.Y, p2.X- p1.X, p2.Y-p1.Y);
}
public void Save()
{
clsDB db1 = new clsDB("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=dbpaint.accdb");
db1.Perform(string.Format("INSERT INTO tblEllipse(x1,y1,x2,y2,color) VALUES({0},{1},{2},{3},'{4}')", p1.X, p1.Y, p2.X, p2.Y, pen.Color));
}
}
}
ClsRectangle:
using System;
using System.Drawing;
namespace winPaint
{
class clsRectangle
{
//must be property, وقت نداشتم فیلد کردمشون
//p1.x<=p2.x , p1.y<=p2.y
public Point p1, p2;
public Pen pen;
public Graphics boom;
//------
public clsRectangle(Point p1, Point p2, Pen pen, Graphics boom)
{
this.p1 = p1;
this.p2 = p2;
this.pen = pen;
this.boom = boom;
}
public void Draw()
{
//چون در این فضا نمی بیند، به سطح کلاس می رود و آنها را پیدا می کند
boom.DrawRectangle(pen, p1.X,p1.Y, p2.X- p1.X, p2.Y-p1.Y);
}
public void Save()
{
clsDB db1 = new clsDB("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=dbpaint.accdb");
db1.Perform(string.Format("INSERT INTO tblRectangle(x1,y1,x2,y2,color) VALUES({0},{1},{2},{3},'{4}')", p1.X, p1.Y, p2.X, p2.Y, pen.Color));
}
}
}
اینم یه کلاس برای یک شکل الکیه:
using System;
using System.Drawing;
using System.Data.OleDb;
using System.Collections.Generic;
public Pen thePen
{
get { return p; }
set { p = value; }
}
private Graphics g;
public Graphics Collaj
{
get { return g; }
set { g = value; }
}
private Point p1;
public Point P1
{
get { return p1; }
set { p1 = value; }
}
private Point p2;
public Point P2
{
get { return p2; }
set { p2 = value; }
}
private ShapeType shType;
protected ShapeType ShType
{
get { return shType; }
set { shType = value; }
}
public virtual void Draw(){}
public virtual bool SaveToDataBase(int paintID)
{
throw new Exception("shape");
cmd.CommandText = string.Format("INSERT INTO tblpaint(x1,y1,x2,y2,color,shType,paintID) VALUES({0},{1},{2},{3},{4},{5},{6})",P1.X,p1.Y,P2.X,P2.Y,thePen.Color.ToArgb(),ShType.ToString(),paintID);
int i=cmd.ExecuteNonQuery();
return (i > 0);
}
public virtual bool LoadFromDataBase(int shapeID)
{
return true;
}
}
#endregion
#region clsLine
//ye mesal as class va verasat biarid ba toozih
public sealed class clsLine : clsShape
{
public static int lineCount = 0;
//foreach (clsShape sh in shapes)
//{
// sh.LoadFromDataBase(this.PaintID);
//}
//return true;
}
}
#endregion
}
اینم فرمای مربوطه:
فرم اول:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace winPaint
{
public partial class Form0 : Form
{
public Form0()
{
InitializeComponent();
}
Graphics g;
private void Form0_Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.Green);
Point p1 = new Point(20, 40);
Point p2 = new Point(110, 90);
g.DrawLine(p, p1, p2);
g.DrawRectangle(p, p1.X, p1.Y, p2.X - p1.X, p2.Y - p1.Y);
g.DrawEllipse(p, p1.X, p1.Y, p2.X - p1.X, p2.Y - p1.Y);
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace winPaint
{
public partial class Form1 : Form
{
Graphics gpanel1;
public Form1()
{
InitializeComponent();
}
علاقه مندی ها (Bookmarks)