// Gan cac gia tri cho m_Shape private void Gan(CShape shape) { shape.SetDrawMode(GDI.R2_NOTXORPEN); shape.SetWidth(int.Parse(tcmbWidth.SelectedItem.ToString())); shape.SetPenStyle(Chon(tcmbPenStyle.SelectedItem.ToString())); shape.SetColor(_RGB(m_R, m_G, m_B)); }
private void toolBar1_ButtonClick(object sender, ToolBarButtonClickEventArgs e) { foreach (ToolBarButton tbb in toolBar1.Buttons) { if (tbb == e.Button) { tbb.Pushed = true; } else { tbb.Pushed = false; } } if (e.Button.ImageIndex == 1) // Line { if (m_Shape is CLine) { return; } m_Shape = new CLine(); } else { if (m_Shape is CEllipse) { return; } m_Shape = new CEllipse(); } }
private void tButRectangle_Click(object sender, EventArgs e) { UnChecked(); tButRectangle.Checked = true; Xoa(); flag = false; m_Shape = new CRectangle(); Gan(m_Shape); }
private void DrawShape_MouseDown(MouseButtonEventArgs e) { ChangeImage(); if (adlayer != null) { shape.RemoveAdorner(adlayer); } colorBit = true; Thickness = Int32.Parse(borderSizeComboBox.SelectedItem.ToString()); switch (type) { case DrawType.CLine: shape = new CLine(); break; case DrawType.CRectangle: shape = new CRectangle(); break; case DrawType.CSquare: shape = new CSquare(); break; case DrawType.CEllipse: shape = new CEllipse(); break; case DrawType.CCircle: shape = new CCircle(); break; case DrawType.CHeart: shape = new CHeart(); break; case DrawType.CStar: shape = new CStar(); break; case DrawType.CArrow: shape = new CArrow(); break; } fiveColorLGB = new LinearGradientBrush(); fiveColorLGB.StartPoint = new Point(0, 0); fiveColorLGB.EndPoint = new Point(1, 0); GS1 = new GradientStop(); GS1.Color = (Color)colorPicker2.SelectedColor; GS1.Offset = 1 - (float)Offset.Value; fiveColorLGB.GradientStops.Add(GS1); GS2 = new GradientStop(); GS2.Color = (Color)colorPicker3.SelectedColor; GS2.Offset = 1; fiveColorLGB.GradientStops.Add(GS2); shape.m_Fill = fiveColorLGB; shape.m_Stroke = new SolidColorBrush((Color)colorPicker1.SelectedColor); shape.m_ThinkNess = Thickness; shape.m_Dash = dashes; shape.DrawDown(paintCanvas, startPoint); }
private void tButPolygon_Click(object sender, EventArgs e) { UnChecked(); tButPolygon.Checked = true; Xoa(); flag = false; m_Shape = new CPolygon(); m_Shape.SetWidth(int.Parse(tcmbWidth.SelectedItem.ToString())); m_Shape.SetPenStyle(Chon(tcmbPenStyle.SelectedItem.ToString())); m_Shape.SetColor(_RGB(m_R, m_G, m_B)); }
public Form1() { InitializeComponent(); m_Start = new Point(); m_End = new Point(); m_Shape = new CLine(); flag = false; toolBar1.Buttons[0].Pushed = true; m_Color = Color.Black; m_Fill = Color.White; mnuColor.Text = "Color(" + ColorToString(m_Color) + ")"; mnuFill.Text = "Fill(" + ColorToString(m_Fill) + ")"; CreateBitmap(); }
private void Form1_MouseDown(object sender, MouseEventArgs e) { m_End.X = e.X; m_End.Y = e.Y; flag = !flag; if (flag) // bat dau ve { m_Start.X = e.X; m_Start.Y = e.Y; } else { // Chuyen toa do 2 diem thanh mang cac diem Point[] T = new Point[2]; T[0] = m_Start; T[1] = m_End; // Them tham so cho hinh can ve m_Shape.SetPoints(T); m_Shape._Color = m_Color; m_Shape.Fill = m_Fill; // Ve Graphics grImage = Graphics.FromImage(bmpNew); Graphics gr = this.CreateGraphics(); m_Shape.Draw(gr); // ve len man hinh m_Shape.Draw(grImage); // ve len anh (trong vung nho) gr.Dispose(); grImage.Dispose(); // Them hinh vao tap hop m_arrShape.Add(m_Shape); switch (m_Shape.ToString()) { case "CLine": m_Shape = new CLine(); break; case "CEllipse": m_Shape = new CEllipse(); break; } } }
private void New() { tlbl.Visible = true; m_R = 0; m_G = 0; m_B = 0; m_Shape = new CLine(); flag1 = false; flag = false; tcmbPenStyle.SelectedIndex = 0; tcmbWidth.SelectedIndex = 0; m_Start.x = m_Start.y = m_End.x = m_End.y = 0; m_arrShape = null; m_arrPoint = null; UnChecked(); tButLine.Checked = true; Gan(m_Shape); }
private void panel1_MouseDown(object sender, MouseEventArgs e) { flag = !flag; if (flag) // bat dau ve { tlbl.Visible = false; tcmbPenStyle.Enabled = false; tcmbWidth.Enabled = false; m_Start.x = m_End.x = e.X; m_Start.y = m_End.y = e.Y; if (m_Shape.ToString() == "CPolygon") { HDC hdc = (HDC)User.GetDC(panel1.Handle); CRectangle rec = new CRectangle(m_End.x - distance, m_End.y - distance, m_End.x + distance, m_End.y + distance); rec.SetDrawMode(GDI.R2_NOTXORPEN); rec.Draw(hdc); User.ReleaseDC(panel1.Handle, hdc); m_arrPoint = new POINT[1]; m_arrPoint[0] = m_End; } } else { HDC hdc = (HDC)User.GetDC(panel1.Handle); if (m_Shape.ToString() == "CPolygon") { if (e.Clicks != 2) { m_Start = m_End; flag = !flag; CRectangle rec = new CRectangle(m_End.x - distance, m_End.y - distance, m_End.x + distance, m_End.y + distance); rec.SetDrawMode(GDI.R2_NOTXORPEN); rec.Draw(hdc); User.ReleaseDC(panel1.Handle, hdc); Array.Resize <POINT>(ref m_arrPoint, m_arrPoint.Length + 1); m_arrPoint[m_arrPoint.Length - 1] = m_End; return; } else { m_Shape.SetPoints(m_arrPoint); foreach (POINT t in m_arrPoint) { CRectangle rec = new CRectangle(t.x - distance, t.y - distance, t.x + distance, t.y + distance); rec.SetDrawMode(GDI.R2_NOTXORPEN); rec.Draw(hdc); } m_arrPoint = null; } } m_Shape.SetDrawMode(GDI.R2_COPYPEN); m_Shape.Draw(hdc); // Them hinh vao tap hop if (m_arrShape == null) { m_arrShape = new CShape[1]; } else { Array.Resize <CShape>(ref m_arrShape, m_arrShape.Length + 1); } m_arrShape[m_arrShape.Length - 1] = m_Shape; switch (m_Shape.ToString()) { case "CLine": m_Shape = new CLine(); break; case "CEllipse": m_Shape = new CEllipse(); break; case "CPolygon": m_Shape = new CPolygon(); break; case "CRectangle": m_Shape = new CRectangle(); break; } Gan(m_Shape); User.ReleaseDC(panel1.Handle, hdc); tcmbPenStyle.Enabled = true; tcmbWidth.Enabled = true; tlbl.Visible = true; } }