Click here to Skip to main content
15,889,116 members
Home / Discussions / C#
   

C#

 
QuestionRe: help me about speed of loading data ... Pin
Stefan Prodan3-May-07 13:01
Stefan Prodan3-May-07 13:01 
QuestionFirefox Component Pin
bodikon2-May-07 15:01
bodikon2-May-07 15:01 
AnswerRe: Firefox Component Pin
Judah Gabriel Himango2-May-07 15:59
sponsorJudah Gabriel Himango2-May-07 15:59 
GeneralRe: Firefox Component Pin
bodikon2-May-07 21:32
bodikon2-May-07 21:32 
QuestionA simple form sizing problem Pin
zoroyster2-May-07 14:34
zoroyster2-May-07 14:34 
AnswerRe: A simple form sizing problem Pin
Christian Graus2-May-07 14:42
protectorChristian Graus2-May-07 14:42 
GeneralRe: A simple form sizing problem Pin
zoroyster2-May-07 16:05
zoroyster2-May-07 16:05 
QuestionGraphics ..with c # Pin
mr jets2-May-07 14:27
mr jets2-May-07 14:27 
good evning every one..i really need ur help guys ..my program like that one in Paint ..finally i can save the file as text in C DRIVE but while opening it can read the data from text but cant display it ( draw the lines..)..note it can save & open the lines only.

---> my question : how can i make the program display the file.
this apart of my code guys :
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Data;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;




namespace graphics_practis
{
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{
Point center,radius,v,start,end,a,b;
ArrayList arraypoint=new ArrayList();
ArrayList arraylist_points=new ArrayList();
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button line;
private System.Windows.Forms.Button square;
private System.Windows.Forms.Button circle;
private System.Windows.Forms.Button ellipse;
private System.Windows.Forms.Button polygon;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button ok;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private BinaryFormatter formtter = new BinaryFormatter();
///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
dr = new draw(this.pictureBox1);
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.line = new System.Windows.Forms.Button();
this.square = new System.Windows.Forms.Button();
this.circle = new System.Windows.Forms.Button();
this.ellipse = new System.Windows.Forms.Button();
this.polygon = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.ok = new System.Windows.Forms.Button();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.SystemColors.MenuText;
this.panel1.Controls.Add(this.pictureBox1);
this.panel1.Location = new System.Drawing.Point(96, 32);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(416, 296);
this.panel1.TabIndex = 0;
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.SystemColors.Window;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(416, 296);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
this.pictureBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp);
this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
//
// line
//
this.line.Location = new System.Drawing.Point(24, 32);
this.line.Name = "line";
this.line.Size = new System.Drawing.Size(40, 23);
this.line.TabIndex = 1;
this.line.Text = "line";
this.line.Click += new System.EventHandler(this.line_Click);
//
// square
//
this.square.Location = new System.Drawing.Point(24, 72);
this.square.Name = "square";
this.square.Size = new System.Drawing.Size(40, 23);
this.square.TabIndex = 2;
this.square.Text = "square";
this.square.Click += new System.EventHandler(this.square_Click);
//
// circle
//
this.circle.Location = new System.Drawing.Point(24, 120);
this.circle.Name = "circle";
this.circle.Size = new System.Drawing.Size(48, 23);
this.circle.TabIndex = 3;
this.circle.Text = "circle";
this.circle.Click += new System.EventHandler(this.circle_Click);
//
// ellipse
//
this.ellipse.Location = new System.Drawing.Point(24, 168);
this.ellipse.Name = "ellipse";
this.ellipse.Size = new System.Drawing.Size(56, 23);
this.ellipse.TabIndex = 4;
this.ellipse.Text = "ellipse";
this.ellipse.Click += new System.EventHandler(this.ellipse_Click);
//
// polygon
//
this.polygon.Location = new System.Drawing.Point(16, 216);
this.polygon.Name = "polygon";
this.polygon.Size = new System.Drawing.Size(56, 23);
this.polygon.TabIndex = 5;
this.polygon.Text = "polygon";
this.polygon.Click += new System.EventHandler(this.polygon_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(8, 264);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(40, 20);
this.textBox1.TabIndex = 6;
this.textBox1.Text = "";
//
// ok
//
this.ok.Location = new System.Drawing.Point(48, 264);
this.ok.Name = "ok";
this.ok.Size = new System.Drawing.Size(32, 23);
this.ok.TabIndex = 7;
this.ok.Text = "ok";
this.ok.Click += new System.EventHandler(this.ok_Click);
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3,
this.menuItem4,
this.menuItem5});
this.menuItem1.Text = "File";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "New";
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "Open";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem4
//
this.menuItem4.Index = 2;
this.menuItem4.Text = "Save";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// menuItem5
//
this.menuItem5.Index = 3;
this.menuItem5.Text = "Exit";
this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(192, 344);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(192, 32);
this.button1.TabIndex = 8;
this.button1.Text = "Change Text Color";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(192, 384);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(192, 32);
this.button2.TabIndex = 9;
this.button2.Text = "Change Background Color";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(528, 445);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.ok);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.polygon);
this.Controls.Add(this.ellipse);
this.Controls.Add(this.circle);
this.Controls.Add(this.square);
this.Controls.Add(this.line);
this.Controls.Add(this.panel1);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new Form1());
}
#region variables

Graphics g ;
Pen p = new Pen(Color.Black,1);
ArrayList lines = new ArrayList();
ArrayList squeres = new ArrayList();
ArrayList circles = new ArrayList();
ArrayList ellipses = new ArrayList();
ArrayList polygons = new ArrayList();
int drawwhat;
int n ;//for the No. of polygon
draw dr;
#endregion
#region mouse down
private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
start.X = e.X;
start.Y = e.Y;
arraylist_points.Add(start);



}
#endregion
#region mouse move
private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
g = pictureBox1.CreateGraphics();
if(e.Button == MouseButtons.Left)
{
refresh();
DrawReq(new Point(e.X,e.Y));
}
}
#endregion
#region mouse_up
private void pictureBox1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{

end.X = e.X;
end.Y = e.Y;
DrawReq();
arraylist_points.Add(end);

}
}
#endregion
#region FormLoad
private void Form1_Load(object sender, System.EventArgs e)
{

Bitmap bmp =
new Bitmap(pictureBox1.Width,
pictureBox1.Height);
pictureBox1.BackgroundImage = bmp;
g = Graphics.FromImage(bmp);
g.Clear(pictureBox1.BackColor);
}
#endregion


private void line_Click(object sender, System.EventArgs e)
{
drawwhat = 1;
}
#region Drawwhat
private void DrawReq()
{

if(drawwhat == 1)
{
dr.line(p,start,end);
Line l = new Line();
l.Pen = p;
l.First = start;
l.Second = end;
lines.Add(l);
l = null;

}
else if(drawwhat == 2)
{
dr.square(new Pen(Color.Black,1),start,end);
Line l = new Line();
l.Pen = p;
l.First = start;
l.Second = end;
squeres.Add(l);
l = null;
}
else if(drawwhat == 3)
{
dr.circle(p,start,end);
Line l = new Line();
l.Pen = p;
l.First = start;
l.Second = end;
circles.Add(l);
l = null;
}
else if(drawwhat == 4)
{
dr.ellipse(p,start,end);
Line l = new Line();
l.Pen = p;
l.First = start;
l.Second = end;
ellipses.Add(l);
l = null;
}
else if (drawwhat == 5 && n!=0)
{
dr.polygon(n,p,start,end);
Polygon np = new Polygon();
np.Pen = p;
np.First = start;
np.Second = end;
np.n = n;
polygons.Add(np);
np = null;
}

}
//______________________________________________________________
private void DrawReq(Point last)// overloading to draw during moving
{
end = last;
if(drawwhat == 1)
{
dr.line(p,start,end);

}
else if(drawwhat == 2)
{
dr.square(p,start,end);

}
else if(drawwhat == 3)
{
dr.circle(p,start,end);
}
else if(drawwhat == 4)
{
dr.ellipse(p,start,end);
}
else if (drawwhat == 5)
{
dr.polygon(n,p,start,end);
}


}
//________________________________________________________________

//________________________________________________________________
#endregion
#region Refresh
private void refresh()
{
pictureBox1.Refresh();
foreach(Line l in lines)
{
dr.line(l.Pen,l.First,l.Second);
}
foreach(Line l in squeres)
{
dr.square(l.Pen,l.First,l.Second);
}
foreach(Line l in circles)
{
dr.circle(l.Pen,l.First,l.Second);
}
foreach(Line l in ellipses)
{
dr.ellipse(l.Pen,l.First,l.Second);
}
foreach(Polygon p in polygons)
{
dr.polygon(p.n,p.Pen,p.First,p.Second);
}

}
#endregion

private void square_Click(object sender, System.EventArgs e)
{
drawwhat = 2;
}

private void circle_Click(object sender, System.EventArgs e)
{
drawwhat = 3;
}

private void pictureBox1_Click(object sender, System.EventArgs e)
{

}

private void ellipse_Click(object sender, System.EventArgs e)
{
drawwhat = 4;
}

private void polygon_Click(object sender, System.EventArgs e)
{
drawwhat = 5;
}

private void ok_Click(object sender, System.EventArgs e)
{
try
{
n = int.Parse(textBox1.Text.ToString());
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void menuItem4_Click(object sender, System.EventArgs e)
{
// save the file

string str_Line;
System.IO.FileStream fs = new System.IO.FileStream("c:\\graphics.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);
StreamWriter streamWriter=new StreamWriter(fs);
if(drawwhat==1)
{
for(int j=0;j
AnswerRe: Graphics ..with c # Pin
Christian Graus2-May-07 14:45
protectorChristian Graus2-May-07 14:45 
GeneralRe: Graphics ..with c # Pin
mr jets2-May-07 14:58
mr jets2-May-07 14:58 
GeneralRe: Graphics ..with c # Pin
Christian Graus2-May-07 15:28
protectorChristian Graus2-May-07 15:28 
QuestionHow to get a mini dump? Pin
Super Lloyd2-May-07 13:33
Super Lloyd2-May-07 13:33 
AnswerRe: How to get a mini dump? Pin
Super Lloyd2-May-07 17:20
Super Lloyd2-May-07 17:20 
QuestionSelect from another select statement to a repeater Pin
simsen2-May-07 11:28
simsen2-May-07 11:28 
QuestionHow can I have my Cursor visiable? Pin
Khoramdin2-May-07 11:26
Khoramdin2-May-07 11:26 
AnswerRe: How can I have my Cursor visiable? Pin
AFSEKI7-May-07 5:56
AFSEKI7-May-07 5:56 
QuestionUpdate() database from DataSet Pin
aecordoba2-May-07 10:58
aecordoba2-May-07 10:58 
AnswerRe: Update() database from DataSet Pin
Paul Conrad2-May-07 11:03
professionalPaul Conrad2-May-07 11:03 
GeneralRe: Update() database from DataSet Pin
Giorgi Dalakishvili2-May-07 11:11
mentorGiorgi Dalakishvili2-May-07 11:11 
GeneralRe: Update() database from DataSet Pin
aecordoba2-May-07 12:52
aecordoba2-May-07 12:52 
GeneralRe: Update() database from DataSet Pin
PIEBALDconsult2-May-07 11:19
mvePIEBALDconsult2-May-07 11:19 
GeneralRe: Update() database from DataSet Pin
Paul Conrad2-May-07 11:26
professionalPaul Conrad2-May-07 11:26 
GeneralRe: Update() database from DataSet Pin
PIEBALDconsult2-May-07 11:43
mvePIEBALDconsult2-May-07 11:43 
GeneralRe: Update() database from DataSet Pin
Paul Conrad2-May-07 11:49
professionalPaul Conrad2-May-07 11:49 
GeneralRe: Update() database from DataSet Pin
Dave Kreskowiak2-May-07 16:18
mveDave Kreskowiak2-May-07 16:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.