/// <summary> /// Method for calling rectangle class /// </summary> /// <param name="width">getting width of the </param> /// <param name="height"></param> private void DrawRectangle(int width, int height) { gap = Panel_Draw.CreateGraphics(); gap.RotateTransform(rotation);//for rotating the shape _s1 = Xaxis; _s2 = Yaxis; _s3 = width; _s4 = height; ShapeFactory shapeFactory = new ShapeFactory(); Shape c = shapeFactory.GetShape("rectangle"); c.set(fill, pcolor, _s1, _s2, _s3, _s4); c.Draw(gap); }
int fill = 0;//this is for the fill on and off option /// <summary> /// all logic to run command in commnad line /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_run_Click(object sender, EventArgs e) { Regex regexRun = new Regex(@"run"); Regex regexClear = new Regex(@"clear"); Regex regexReset = new Regex(@"reset"); Regex regexMT = new Regex(@"moveto (.*[\d])([,])(.*[\d])"); Regex regexDT = new Regex(@"drawto (.*[\d])([,])(.*[\d])"); Regex regexR = new Regex(@"rectangle (.*[\d])([,])(.*[\d])"); Regex regexC = new Regex(@"circle (.*[\d])"); Regex regexT = new Regex(@"triangle (.*[\d])([,])(.*[\d])([,])(.*[\d])"); Match matchRun = regexRun.Match(textBox2.Text.ToLower()); Match matchClear = regexClear.Match(textBox2.Text.ToLower()); Match matchReset = regexReset.Match(textBox2.Text.ToLower()); Match matchMT = regexMT.Match(textBox2.Text.ToLower()); Match matchDT = regexDT.Match(textBox2.Text.ToLower()); Match matchR = regexR.Match(textBox2.Text.ToLower()); Match matchC = regexC.Match(textBox2.Text.ToLower()); Match matchT = regexT.Match(textBox2.Text.ToLower()); if (matchRun.Success || matchClear.Success || matchReset.Success || matchMT.Success || matchDT.Success || matchR.Success || matchC.Success || matchT.Success) { //----------------RECTANGLE-----------------------// if (matchR.Success) { try { gap = Panel_Draw.CreateGraphics(); // g.RotateTransform(rotation);//for rotating the shape _s1 = Xaxis; _s2 = Yaxis; _s3 = int.Parse(matchR.Groups[1].Value); _s4 = int.Parse(matchR.Groups[3].Value); ShapeFactory shapeFactory = new ShapeFactory(); Shape c = shapeFactory.GetShape("rectangle"); c.set(fill, pcolor, _s1, _s2, _s3, _s4); c.Draw(gap); } catch (Exception ex) { MessageBox.Show("wrong parameter: should be like this \"rectangle width, height\""); } } //----------------CIRCLE-----------------------// else if (matchC.Success) { try { gap = Panel_Draw.CreateGraphics(); // g.RotateTransform(rotation);//for rotating the shape _s1 = Xaxis; _s2 = Yaxis; _s3 = int.Parse(matchC.Groups[1].Value); ShapeFactory shapeFactory = new ShapeFactory(); Shape c = shapeFactory.GetShape("circle"); c.set(fill, pcolor, _s1, _s2, _s3 * 2, _s3 * 2); //c.draw(set); c.Draw(gap); } catch (Exception ex) { MessageBox.Show("wrong parameter: should be like this \"circle radius\""); } } // ----------------TRIANGLE---------------------- -// else if (matchT.Success) { try { gap = Panel_Draw.CreateGraphics(); // g.RotateTransform(rotation);//for rotating the shape _s1 = Xaxis; _s2 = Yaxis; _s3 = int.Parse(matchT.Groups[1].Value); _s4 = int.Parse(matchT.Groups[3].Value); _s5 = int.Parse(matchT.Groups[5].Value); xi1 = _s1; yi1 = _s2; xi2 = Math.Abs(_s3); yi2 = _s2; xii1 = _s1; yii1 = _s2; xii2 = _s1; yii2 = Math.Abs(_s4); xiii1 = Math.Abs(_s3); yiii1 = _s2; xiii2 = _s1; yiii2 = Math.Abs(_s4); ShapeFactory shapeFactory = new ShapeFactory(); Shape c = shapeFactory.GetShape("triangle"); //new rectangles(); c.set(fill, pcolor, xi1, yi1, xi2, yi2, xii1, yii1, xii2, yii2, xiii1, yiii1, xiii2, yiii2); c.Draw(gap); } catch (Exception ex) { MessageBox.Show("wrong parameter: should be like this \"triangle side, side, side\""); } } // ----------------CLEAR------------------------// else if (matchClear.Success) { Panel_Draw.Refresh(); this.Panel_Draw.BackgroundImage = null; } // ----------------RUN-----------------------// else if (matchRun.Success) { btn_exec_Click(this, new EventArgs()); } // ----------------RESET------------------------// else if (matchReset.Success) { _s1 = 0; _s2 = 0; Xaxis = 0; Yaxis = 0; rotation = 0; } // ----------------MOVETO------------------------// else if (matchMT.Success) { try { _s1 = int.Parse(matchMT.Groups[1].Value); _s2 = int.Parse(matchMT.Groups[3].Value); Xaxis = _s1; Yaxis = _s2; } catch (Exception ex) { MessageBox.Show(ex.Message); } } // ----------------DRAWTO------------------------// else if (matchDT.Success) { try { Pen p = new Pen(pcolor); _s1 = int.Parse(matchMT.Groups[1].Value); _s2 = int.Parse(matchMT.Groups[3].Value); gap.DrawLine(p, _s1, _s2, Xaxis, Yaxis); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } else { MessageBox.Show("Command doesnot exist"); } }