Click here to Skip to main content
15,896,207 members
Home / Discussions / C#
   

C#

 
AnswerRe: how to count elements inside an array? Pin
donkaiser18-May-06 10:35
donkaiser18-May-06 10:35 
QuestionDo not start application from byte[] Pin
Dima Filipiuk18-May-06 4:40
Dima Filipiuk18-May-06 4:40 
AnswerRe: Do not start application from byte[] Pin
leppie18-May-06 5:24
leppie18-May-06 5:24 
GeneralRe: Do not start application from byte[] Pin
Dima Filipiuk18-May-06 7:43
Dima Filipiuk18-May-06 7:43 
GeneralRe: Do not start application from byte[] Pin
Rei Miyasaka18-May-06 10:00
Rei Miyasaka18-May-06 10:00 
GeneralRe: Do not start application from byte[] Pin
Dima Filipiuk18-May-06 11:01
Dima Filipiuk18-May-06 11:01 
GeneralRe: Do not start application from byte[] Pin
Rei Miyasaka18-May-06 11:31
Rei Miyasaka18-May-06 11:31 
GeneralRe: Do not start application from byte[] Pin
Dima Filipiuk18-May-06 20:28
Dima Filipiuk18-May-06 20:28 
GeneralRe: Do not start application from byte[] Pin
Rei Miyasaka18-May-06 20:32
Rei Miyasaka18-May-06 20:32 
GeneralRe: Do not start application from byte[] Pin
Dima Filipiuk18-May-06 22:49
Dima Filipiuk18-May-06 22:49 
GeneralRe: Do not start application from byte[] Pin
Rei Miyasaka18-May-06 23:12
Rei Miyasaka18-May-06 23:12 
GeneralRe: Do not start application from byte[] Pin
Dima Filipiuk19-May-06 0:27
Dima Filipiuk19-May-06 0:27 
GeneralRe: Do not start application from byte[] Pin
Rei Miyasaka19-May-06 0:34
Rei Miyasaka19-May-06 0:34 
GeneralRe: Do not start application from byte[] Pin
Dima Filipiuk19-May-06 1:03
Dima Filipiuk19-May-06 1:03 
GeneralRe: Do not start application from byte[] Pin
Rei Miyasaka19-May-06 1:13
Rei Miyasaka19-May-06 1:13 
Questiona question about mainMenuStrip ? Pin
cmpeng3418-May-06 4:37
cmpeng3418-May-06 4:37 
AnswerRe: a question about mainMenuStrip ? Pin
NaNg1524118-May-06 4:50
NaNg1524118-May-06 4:50 
AnswerRe: a question about mainMenuStrip ? Pin
Wjousts18-May-06 6:47
Wjousts18-May-06 6:47 
QuestionGetObject Pin
samoilb18-May-06 4:22
samoilb18-May-06 4:22 
AnswerRe: GetObject Pin
Colin Angus Mackay18-May-06 4:28
Colin Angus Mackay18-May-06 4:28 
GeneralRe: GetObject Pin
samoilb18-May-06 5:52
samoilb18-May-06 5:52 
AnswerRe: GetObject Pin
mav.northwind19-May-06 5:37
mav.northwind19-May-06 5:37 
QuestionHow to Register Windows Service usijng Registry Editor Pin
VenkataRamana.Gali18-May-06 4:21
VenkataRamana.Gali18-May-06 4:21 
AnswerRe: How to Register Windows Service usijng Registry Editor Pin
Ravi Bhavnani18-May-06 4:39
professionalRavi Bhavnani18-May-06 4:39 
QuestionHandwriting program help? Pin
eric_tran18-May-06 3:39
eric_tran18-May-06 3:39 
Good day everyone,

I've been doing a handwriting program. User can use mouse pointer to draw lines and eraser lines

I use 2 methods AddPoint and RemovePoint to add points when user draw lines and remove points when user erase lines by using ArrayList pointArray.

But they're not working

Please help me if you are interested in this program.

Thanks so much




private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			//Read file and Draw ellipse around points
			if (!isMouseDown)
			{
				using (sr = new StreamReader("DataPoints.txt"))
				{
					string str = sr.ReadLine();
					if (str == null)
						return;
					string [] strs = str.Split(' ');
					if (strs.Length != 2)
						return;
					Point pt1 = new Point(int.Parse(strs[0]),int.Parse(strs[1]));

 			 

					Graphics g = e.Graphics;
					while ((str = sr.ReadLine()) != null)
					{
						strs = str.Split(' ');
						if (strs.Length != 2)
							break;
						Point pt2 = new Point(int.Parse(strs[0]),int.Parse(strs[1]));							
							 
						g.DrawEllipse(Pens.Blue, pt2.X-2, pt2.Y-2, 4, 4);
						g.DrawLine(Pens.Black, pt1, pt2);
						pt1 = pt2;
							 
					}
				}
				 
			}
		}

		private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (line)
			{
				isMouseDown = true;
				pt1 = new Point(e.X, e.Y);
				point = pt1;				

				//Open file 
				sw = new StreamWriter("DataPoints.txt");
								 
			}

			if (eraser)
			{				
				//Eraser
				pt.X = e.X;
				pt.Y = e.Y;
				g.FillRectangle(bgBrush, pt.X-10, pt.Y-10, 20, 20);
				g.DrawRectangle(Pens.Red, pt.X-10, pt.Y-10, 20, 20);
			}
		}

		private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (line)
			{
			
				if (isMouseDown)
				{
					pointArray.Add("nvcls");
					pointArray.Add("Eric");

					pt2 = new Point(e.X, e.Y);
					Graphics g = this.CreateGraphics();
					g.DrawLine(pen, point, pt2);
					tempG.DrawLine(pen, point, pt2);
					point = pt2;


					ptCount = point;
					AddPoint(ptCount);

					//this.Refresh();					 
					 				
				}
			}


			if (eraser)
			{
				if (isMouseDown)
				{
					line = false;

					//Eraser
					g.FillRectangle(bgBrush,e.X-10,e.Y-10,20,20);
					g.DrawRectangle(Pens.Red,e.X-10,e.Y-10,20,20);
					//Erase area
					g.DrawRectangle(new Pen(this.BackColor),pt.X-10, pt.Y-10, 20, 20);
						
					pt.X = e.X;
					pt.Y = e.Y;

					RemovePoint(ptCount);	
				}
			}
		}

		private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (line)
			{
				isMouseDown = false;
			
				//tempG.DrawLine(pen, pt1, pt2);
				this.BackgroundImage = (Bitmap) tempImage.Clone();

				//write points to file 
				//				sw.WriteLine(e.X + " " + e.Y);

				sw.Close();

				this.Refresh();
			}			 
			
		}


		private void Form1_Resize(object sender,System.EventArgs e)
		{
			this.BackgroundImage = (Bitmap) tempImage.Clone();
		}
    

	 
		private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			if ( e.Button == tbPolygon)
				line = true;
			else if (e.Button == tbEraser)
			{
				//				line = false;
				eraser = true;
			}
			else if (e.Button == tbSave) 
				Save();

		}



		public void AddPoint(Point ptCount)
		{
			pointArray.Add(ptCount);
		}


		private static void RemovePoint(Point ptCount)
		{
			//Remove points from list
			for (int i = 0; i <= pointArray.Count; i ++)
			{
				bool isMatch = Object.Equals(pointArray[i], ptCount);
				if (isMatch)
					pointArray.Remove(pointArray[i]);
			}
		}


		private void Save()
		{
			//			sw = new StreamWriter("DataPoints.txt");
			foreach (string s in pointArray)
			{
				sw.WriteLine(s);
			}
			sw.Close();
		}


eric

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.