Click here to Skip to main content
15,887,386 members
Home / Discussions / C#
   

C#

 
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
GeneralRe: Handwriting program help? Pin
Guffa18-May-06 4:05
Guffa18-May-06 4:05 
GeneralRe: Handwriting program help? Pin
eric_tran18-May-06 4:09
eric_tran18-May-06 4:09 
GeneralRe: Handwriting program help? Pin
mav.northwind18-May-06 5:22
mav.northwind18-May-06 5:22 
QuestionVery Important : How to Get Value of DatagridBoolColumn in Datagrid ? Pin
hdv21218-May-06 3:29
hdv21218-May-06 3:29 
AnswerRe: Very Important : How to Get Value of DatagridBoolColumn in Datagrid ? Pin
Naveed Kamboh18-May-06 5:01
Naveed Kamboh18-May-06 5:01 
Questionsynchronise folder structures Pin
V.V.Thakur18-May-06 3:21
V.V.Thakur18-May-06 3:21 
Questiona few important questions about forms ? Pin
cmpeng3418-May-06 2:59
cmpeng3418-May-06 2:59 
AnswerRe: a few important questions about forms ? Pin
stancrm18-May-06 3:13
stancrm18-May-06 3:13 
AnswerRe: a few important questions about forms ? Pin
Leyu18-May-06 8:13
Leyu18-May-06 8:13 
QuestionThe Server is not operational when authenticating user to active directory Pin
krishna nimmalapudi18-May-06 2:46
krishna nimmalapudi18-May-06 2:46 
AnswerRe: The Server is not operational when authenticating user to active directory Pin
mav.northwind18-May-06 5:20
mav.northwind18-May-06 5:20 
QuestionRe:Palm Desktop software Pin
Smithasondur18-May-06 2:31
Smithasondur18-May-06 2:31 
Questiontrying to change screen resolution Pin
Alex Cutovoi18-May-06 2:21
Alex Cutovoi18-May-06 2:21 
QuestionRemoving stopwords Pin
Rizwan Rathore18-May-06 1:51
Rizwan Rathore18-May-06 1:51 
AnswerRe: Removing stopwords Pin
Robert Rohde18-May-06 2:36
Robert Rohde18-May-06 2:36 
GeneralRe: Removing stopwords Pin
Rizwan Rathore18-May-06 2:49
Rizwan Rathore18-May-06 2:49 
GeneralRe: Removing stopwords Pin
Robert Rohde18-May-06 3:00
Robert Rohde18-May-06 3:00 

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.