private void OpenFile() { if (g_blFileHasBeenEdited == true) { DialogResult result = MessageBox.Show("文件已做修改,是否保存?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { if (g_blFileIsNewed == true) { SaveFileAs(); } if (g_blFileIsOpened == true) { SaveFile(); } } } OpenFileDialog openFileDialog1 = new OpenFileDialog(); //create an openfiledialog openFileDialog1.FileName = ""; openFileDialog1.Filter = "Grafic Files(*.gcd)|*.gcd|Image Files(*.bmp,*.jpg,*.gif)|*.bmp;*.jpg;*.gif"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { if (openFileDialog1.FilterIndex == 1) { g_intNumberOfShape = 0; g_lstShapeList.Clear(); //Clear the ShapeList in the new file frmLayerBox.ClearItem(); frmLayerBox.AddBackgroundItem(); g_bmBackground = new Bitmap(g_intPaperWidth, g_intPaperHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(g_bmBackground); g.Clear(Color.White); BinaryFormatter binFormat = new BinaryFormatter(); Stream fStream = File.OpenRead(openFileDialog1.FileName); g_lstShapeList = (List<Shape>)binFormat.Deserialize(fStream); this.pnlBackground.Invalidate(); fStream.Close(); for (int i = 0; i < g_lstShapeList.Count; i++) { frmLayerBox.AddItem(i+1, 7); g_intNumberOfShape++; } } else if (openFileDialog1.FilterIndex == 2) { g_bmBackground = new Bitmap(openFileDialog1.FileName); //Send the openfile to the background frmLayerBox.ClearItem(); //Clear the layerbox first g_lstShapeList.Clear(); //Clear the ShapeList in the new file g_intNumberOfShape = 0; //Clear the counter of the Shape frmLayerBox.AddBackgroundItem(); //Add in layerbox } g_blFileIsOpened = true; g_blFileHasBeenEdited = false; g_blFileIsNewed = false; m_strOpenFileName = openFileDialog1.FileName; //Store the path and name for saving this.Text = openFileDialog1.FileName; mnuItemSaveAs.Enabled = true; //Enable the mnuItems and toolStrip mnuItemAdjust.Enabled = true; mnuItemZoomIn.Enabled = true; mnuItemZoomOut.Enabled = true; toolStripSave.Enabled = true; toolStripUnderline.Enabled = true; toolStripBold.Enabled = true; toolStripItatic.Enabled = true; toolStripFontFamily.Enabled = true; toolStripFontSize.Enabled = true; mnuItemSave.Enabled = true; //Enable the mnuItems and toolStrip this.Text = m_strOpenFileName; this.picRubberBandLayer.Width = g_bmBackground.Width; //Set up the sizes of three picturebox this.picRubberBandLayer.Height = g_bmBackground.Height; this.pnlBackground.Width = g_bmBackground.Width; this.pnlBackground.Height = g_bmBackground.Height; g_rtFillRectangle = new Rectangle(0, 0, g_bmBackground.Width, g_bmBackground.Height); g_bmDrawingPaper = g_bmBackground; //Save a copy as drawing one this.toolStripFontFamily.SelectedIndex = 1; //Initializing the Font combobox this.toolStripFontSize.SelectedIndex = 6; this.toolStripFontSize.BackColor = Color.White; this.toolStripFontFamily.BackColor = Color.White; this.mnuItemAdjust.Checked = false; m_blAdjusting = false; m_abAdjustingBox = new AdjustingBox(); this.Invalidate(); } }
private void NewFile() { if (g_blFileHasBeenEdited == true) { DialogResult result = MessageBox.Show("文件已做修改,是否保存?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { if (g_blFileIsNewed == true) { SaveFileAs(); } if (g_blFileIsOpened == true) { SaveFile(); } } } g_blFileIsNewed = true; g_blFileIsOpened = false; g_blFileHasBeenEdited = false; g_bmBackground = new Bitmap(g_intPaperWidth, g_intPaperHeight, //Making the backgound a blank white paper System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(g_bmBackground); g.Clear(Color.White); m_strOpenFileName = "untitled"; mnuItemSaveAs.Enabled = true; //Enable the mnuItems mnuItemAdjust.Enabled = true; mnuItemZoomIn.Enabled = true; mnuItemZoomOut.Enabled = true; toolStripSave.Enabled = true; toolStripUnderline.Enabled = true; toolStripBold.Enabled = true; toolStripItatic.Enabled = true; toolStripFontFamily.Enabled = true; toolStripFontSize.Enabled = true; mnuItemSave.Enabled = true; //Enable the mnuItems frmLayerBox.ClearItem(); //Clear the layerbox first frmLayerBox.AddBackgroundItem(); //Add in layerbox g_lstShapeList.Clear(); //Clear the ShapeList in the new file g_intNumberOfShape = 0; //Clear the counter of the Shape this.pnlBackground.Width = g_bmBackground.Width; this.pnlBackground.Height = g_bmBackground.Height; g_rtFillRectangle = new Rectangle(0, 0, g_bmBackground.Width, g_bmBackground.Height); this.picRubberBandLayer.Width = g_bmBackground.Width; //Set up the sizes of three picturebox this.picRubberBandLayer.Height = g_bmBackground.Height; g_bmDrawingPaper = g_bmBackground; //Save a copy as drawing one this.Text = m_strOpenFileName; this.toolStripFontFamily.SelectedIndex = 1; //Initializing the Font combobox this.toolStripFontSize.SelectedIndex = 6; this.toolStripFontSize.BackColor = Color.White; this.toolStripFontFamily.BackColor = Color.White; this.mnuItemAdjust.Checked = false; m_blAdjusting = false; //Reset the adjusting status m_abAdjustingBox = new AdjustingBox(); this.Invalidate(); }
private void MainForm_Load(object sender, EventArgs e) { frmToolBox = new ToolBoxForm(); frmInfoBox = new InfoBoxForm(); frmColorBox = new ColorBoxForm(); frmLayerBox = new LayerBoxForm(); frmColorBox.Show(); frmToolBox.Show(); frmInfoBox.Show(); frmLayerBox.Show(); frmLayerBox.frmMainForm = this; g_intPaperWidth = 600; g_intPaperHeight = 500; g_blFileIsNewed = false; g_blFileIsOpened = false; g_blFileHasBeenEdited = false; g_blColorBoxIsShow = true; g_blInfoBoxIsShow = true; g_blToolBoxIsShow = true; g_blLayerBoxIsShow = true; g_lstShapeList = new List<Shape>(); g_lstSelectedShapeList = new List<Shape>(); g_intNumberOfShape = 0; g_bmCache = new Bitmap(1, 1); m_blAdjusting = false; m_blOperating = false; m_lnNewLine = new Line(); m_cvNewCurve = new Curve(); m_elNewElli = new Elli(); m_rtNewRect = new Rect(); m_rrNewRdRect = new RoundedRect(); m_txtNewText = new Text(); m_abAdjustingBox = new AdjustingBox(); m_intAjustingState = 0; m_blShiftKeyDown = false; m_blBold = false; m_blItatic = false; m_blUnderline = false; m_dbScaleMatrix = new double[3, 3]; m_dbRotationMatrix = new double[3, 3]; foreach (FontFamily ff in FontFamily.Families) //Get ready for the list of FontFamily { toolStripFontFamily.Items.Add(ff.Name); } }
private void mnuItemAdjust_Click(object sender, EventArgs e) { if (this.mnuItemAdjust.Checked == false) { if (g_lstSelectedShapeList.Count > 0) { g_lstShapeList[g_lstShapeList.Count - 1].m_blShapeIsFormed = true; SetSelectionRect(); pnlBackground.Invalidate(); this.mnuItemAdjust.Checked = true; m_blAdjusting = true; this.Cursor = new Cursor(GetType(), "Cursors.MoveSelectionToolCursor.cur"); } } else { m_abAdjustingBox = new AdjustingBox(); this.mnuItemAdjust.Checked = false; m_blAdjusting = false; switch (ToolBoxForm.g_tmUsingToolMode) { case ToolBoxForm.ToolMode.Move: this.Cursor = new Cursor(GetType(), "Cursors.MoveToolCursor.cur"); break; case ToolBoxForm.ToolMode.Line: this.Cursor = new Cursor(GetType(), "Cursors.GenericToolCursor.cur"); break; case ToolBoxForm.ToolMode.Ellipse: this.Cursor = new Cursor(GetType(), "Cursors.EllipseToolCursor.cur"); break; case ToolBoxForm.ToolMode.Rectangle: this.Cursor = new Cursor(GetType(), "Cursors.RectangleToolCursor.cur"); break; case ToolBoxForm.ToolMode.Brush: this.Cursor = new Cursor(GetType(), "Cursors.PaintBrushToolCursor.cur"); break; case ToolBoxForm.ToolMode.ColorPicker: this.Cursor = new Cursor(GetType(), "Cursors.ColorPickerToolCursor.cur"); break; case ToolBoxForm.ToolMode.Eraser: this.Cursor = new Cursor(GetType(), "Cursors.EraserToolCursor.cur"); //* break; case ToolBoxForm.ToolMode.FillBorder: this.Cursor = new Cursor(GetType(), "Cursors.PaintBucketToolCursor.cur"); break; case ToolBoxForm.ToolMode.Text: this.Cursor = new Cursor(GetType(), "Cursors.GenericToolCursor.cur"); //Cursors.TextToolCursor.cur break; case ToolBoxForm.ToolMode.FreeFormShape: this.Cursor = new Cursor(GetType(), "Cursors.FreeformShapeToolCursor.cur"); break; case ToolBoxForm.ToolMode.PaintBucket: this.Cursor = new Cursor(GetType(), "Cursors.PaintBucketToolCursor.cur"); break; case ToolBoxForm.ToolMode.Pencil: this.Cursor = new Cursor(GetType(), "Cursors.PencilToolCursor.cur"); break; case ToolBoxForm.ToolMode.RoundedRectangle: this.Cursor = new Cursor(GetType(), "Cursors.RoundedRectangleToolCursor.cur"); break; case ToolBoxForm.ToolMode.Curve: this.Cursor = new Cursor(GetType(), "Cursors.GenericToolCursor.cur"); //* break; //Not open yet case ToolBoxForm.ToolMode.CloneStamp: this.Cursor = new Cursor(GetType(), "Cursors.CloneStampToolCursor.cur"); break; case ToolBoxForm.ToolMode.Adjust: this.Cursor = new Cursor(GetType(), "Cursors.MoveSelectionToolCursor.cur"); break; case ToolBoxForm.ToolMode.RectangleSelect: this.Cursor = new Cursor(GetType(), "Cursors.RectangleSelectToolCursor.cur"); break; case ToolBoxForm.ToolMode.LassoSelect: this.Cursor = new Cursor(GetType(), "Cursors.LassoSelectToolCursor.cur"); break; case ToolBoxForm.ToolMode.MagicWand: this.Cursor = new Cursor(GetType(), "Cursors.MagicWandToolCursor.cur"); break; case ToolBoxForm.ToolMode.EllipseSelect: this.Cursor = new Cursor(GetType(), "Cursors.EllipseSelectToolCursor.cur"); break; } pnlBackground.Invalidate(); } }
public void SetSelectionRect() { GraphicsPath one = new GraphicsPath(); one.AddPath(g_lstSelectedShapeList [g_lstSelectedShapeList.Count - 1].m_grpShapePath, false); g_rtAdjustingRect = Rectangle.Round(one.GetBounds()); m_abAdjustingBox = new AdjustingBox(g_rtAdjustingRect); one.Dispose(); }