예제 #1
0
 private void renderToolStripButton_Click(object sender, EventArgs e)
 {
     saveFileDialog1.Title  = "Choose render output path...";
     saveFileDialog1.Filter = "PNG Image (*.png)|*.png";
     if (saveFileDialog1.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
     {
         try
         {
             using (Bitmap bmp = new Bitmap(ClientSize.Width, ClientSize.Height - toolStrip1.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
             {
                 using (Graphics g = Graphics.FromImage(bmp))
                 {
                     IGraphics gg = new GdiGraphics(g);
                     renderer.RenderingParameters.ClearBackground = false;
                     if (renderer.Antialias)
                     {
                         g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                     }
                     vec.Draw(gg, renderer.RenderingParameters, renderer.FigureScale, renderer.FigureX, renderer.FigureY);
                 }
                 bmp.Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Png);
             }
             MessageBox.Show(this, "Render saved.", titleText, MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         catch (Exception ex)
         {
             MessageBox.Show(this, "Failed to render to file: " + ex.Message, titleText, MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         finally
         {
             renderer.RenderingParameters.ClearBackground = true;
         }
     }
 }
예제 #2
0
        FormMain_Paint(object sender, PaintEventArgs e)
        {
            // Fetch a Win32 DC.
            IntPtr hdc = GdiGraphics.GetDC(m_hwndForm);

            // Create a Win32 font.
            IntPtr hfont = GdiFont.Create(hdc, "Tahoma", 12, m_degRotate);

            // Select font into DC.
            IntPtr hfontOld = GdiGraphics.SelectObject(hdc, hfont);

            // Draw using Win32 text drawing function.
            GdiGraphics.ExtTextOut(hdc, m_xText, m_yText, 0,
                                   IntPtr.Zero, "Rotated Text", 12, IntPtr.Zero);

            // Disconnect font from DC -- *Critical* because....
            GdiGraphics.SelectObject(hdc, hfontOld);

            // ... clean up of Win32 font object requires font to
            // be disconnected from any and all DCs.
            GdiGraphics.DeleteObject(hfont);

            // Disconnect from Win32 DC.
            GdiGraphics.ReleaseDC(m_hwndForm, hdc);
        }
예제 #3
0
        public void PaintNavigationMap(MindMap map, float zoom, PaintEventArgs e)
        {
            if (map == null)
            {
                throw new ArgumentNullException();
            }

            var graphics = new GdiGraphics(e.Graphics);

            ResetObjects(graphics, map);

            if (!map.BackColor.IsEmpty)
            {
                e.Graphics.Clear(map.BackColor);
            }

            if (map.Root != null)
            {
                Liner = LayoutManage.GetLiner(map.LayoutType);

                Font font  = ChartBox.DefaultChartFont;
                var  font2 = new GdiFont(font.FontFamily, font.Size * zoom);

                //GenerateFoldingButtonImage(map, zoom);
                PaintNavigationMap(graphics, map.Root, zoom, font2);

                PaintNavigationMapLinkLines(graphics, map.Root, zoom, font2);
            }
        }
예제 #4
0
        } // SetHorizontalAlignment

        //
        // Calculate font baseline for baseline alignment.
        //
        private int GetFontBaseline(string strFont, int cptHeight)
        {
            int cyReturn;

            // Fetch a Win32 DC.
            IntPtr hdc = GdiGraphics.GetDC(m_hwndForm);

            // Create a Win32 font.
            IntPtr hfont = GdiFont.Create(hdc, strFont, cptHeight, 0);

            // Select font into DC.
            IntPtr hfontOld = GdiGraphics.SelectObject(hdc, hfont);

            // Allocate font metric structure.
            GdiFont.TEXTMETRIC tm =
                new GdiFont.TEXTMETRIC();

            // Fetch font metrics.
            GdiFont.GetTextMetrics(hdc, ref tm);

            // Fetch return value.
            cyReturn = tm.tmAscent;

            // Disconnect font from DC -- *Critical* because....
            GdiGraphics.SelectObject(hdc, hfontOld);

            // ... clean up of Win32 font object requires font to
            // be disconnected from any and all DCs.
            GdiGraphics.DeleteObject(hfont);

            // Disconnect from Win32 DC.
            GdiGraphics.ReleaseDC(m_hwndForm, hdc);

            return(cyReturn);
        } // GetFontBaseline
예제 #5
0
        /*public override void PaintValue(PaintValueEventArgs e)
         * {
         *  e.Graphics.FillRectangle(Brushes.White, e.Bounds);
         *  if (e.Value is LineAnchor && ((LineCap)e.Value) != LineCap.Flat)
         *  {
         *      Pen pen = new Pen(Color.Black, 5);
         *      Point pt = PaintHelper.CenterPoint(e.Bounds);
         *      if (IsEndCap)
         *      {
         *          pen.EndCap = (LineCap)e.Value;
         *          e.Graphics.DrawLine(pen, e.Bounds.Left + 2, pt.Y, e.Bounds.Right - pen.Width - 2, pt.Y);
         *      }
         *      else
         *      {
         *          pen.StartCap = (LineCap)e.Value;
         *          e.Graphics.DrawLine(pen, e.Bounds.Left + pen.Width + 2, pt.Y, e.Bounds.Right - 2, pt.Y);
         *      }
         *  }
         * }*/

        protected override void DrawListItem(DrawItemEventArgs e, Rectangle rect, ListItem <LineAnchor> listItem)
        {
            var value = listItem.Value;

            //base.DrawItem(e, rect, value);
            if (value != LineAnchor.None)
            {
                Color foreColor = ((e.State & DrawItemState.Selected) == DrawItemState.Selected) ? SystemColors.HighlightText : SystemColors.WindowText;
                Point pt        = PaintHelper.CenterPoint(rect);
                rect.Inflate(-10, 0);
                rect.X     += 5;
                rect.Width -= 5;

                IGraphics grf = new GdiGraphics(e.Graphics);
                var       gs  = grf.Save();
                grf.SetHighQualityRender();
                var pen = grf.Pen(foreColor, 5);
                if (IsEndCap)
                {
                    grf.DrawLine(pen, rect.Left, pt.Y, rect.Right, pt.Y, LineAnchor.None, (LineAnchor)value);
                }
                else
                {
                    grf.DrawLine(pen, rect.Left, pt.Y, rect.Right, pt.Y, (LineAnchor)value, LineAnchor.None);
                }
                grf.Restore(gs);
            }
        }
예제 #6
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Size clientSize = ClientSize;

            e.Graphics.FillRectangle(SystemBrushes.Window, 0, 0, clientSize.Width, cancelButton.Top - 10);
            using (Pen pen = new Pen(Color.FromArgb(unchecked ((int)0xffdfdfdf)))) {
                e.Graphics.DrawLine(pen, 0, 39, clientSize.Width, 39);
                e.Graphics.DrawLine(pen, 0, cancelButton.Top - 10, clientSize.Width, cancelButton.Top - 10);
            }

            UI.PaintDirtGradient(e.Graphics, 1, 1, clientSize.Width - 1, 39 - 2, animationValue + 60, animationValue);

            using (GdiGraphics g = GdiGraphics.FromGraphics(e.Graphics)) {
                if (!string.IsNullOrEmpty(mainInstruction))
                {
                    g.DrawString(mainInstruction, mainInstructionFont, Color.Black, new Point(23, 9));
                }

                if (!string.IsNullOrEmpty(line1.Text))
                {
                    int height = line1.MeasureHeight(g);
                    line1.Draw(g, new Rectangle(22, 57 - (height / 2), clientSize.Width - 22 * 2, height));
                }

                if (!string.IsNullOrEmpty(line2.Text))
                {
                    int height = line2.MeasureHeight(g);
                    line2.Draw(g, new Rectangle(22, 72 - (height / 2), clientSize.Width - 22 * 2, height));
                }
            }
        }
예제 #7
0
 void IPainter.PaintImage(IndexedImage image, Point atPoint)
 {
     using (var bitmap = ToBitmap(image))
     {
         GdiGraphics.DrawImage(bitmap, new GdiPoint(atPoint.X + Shift.Width, atPoint.Y + Shift.Height));
     }
 }
예제 #8
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Size clientSize = ClientSize;

            UI.PaintDirtGradient(e.Graphics, 1, 1, clientSize.Width - 1, 360, 360, 255);

            int y = 9;

            Color back         = SystemColors.Window;
            Color fore         = SystemColors.WindowText;
            Color foreAnimated = Color.FromArgb(
                back.R + (fore.R - back.R) * animationValue / 255,
                back.G + (fore.G - back.G) * animationValue / 255,
                back.B + (fore.B - back.B) * animationValue / 255
                );

            using (GdiGraphics g = GdiGraphics.FromGraphics(e.Graphics)) {
                y += DrawString(g, App.AssemblyTitle, mainInstructionFont, foreAnimated, new Point(23, y)) + 4;

                y += DrawString(g, Tx.T("main.about.description"), subtitleFont, foreAnimated, new Point(23, y)) + 18;

                y += DrawString(g, App.AssemblyCopyright, Font, fore, new Point(23, y)) + 3;
                y += DrawString(g, "This project is licensed under the terms of the GNU General Public License v3.0.", Font, fore, new Point(23, y)) + 10;
            }

            Point linkPos = new Point(21, y);

            if (linkLabel.Location != linkPos)
            {
                linkLabel.Location = linkPos;
            }
        }
        //Revision: JCarpenter 10/06
        /// <summary>
        /// Find the object currently under the mouse cursor, and return its state.
        /// </summary>
        private ContextMenuObjectState GetObjectState()
        {
            ContextMenuObjectState objState = ContextMenuObjectState.Background;

            // Determine object state
            Point     mousePt = this.PointToClient(Control.MousePosition);
            int       iPt;
            GraphPane pane;
            object    nearestObj;

            IGraphics g = new GdiGraphics(this.CreateGraphics());

            {
                if (this.MasterPane.FindNearestPaneObject(mousePt, g, out pane,
                                                          out nearestObj, out iPt))
                {
                    CurveItem item = nearestObj as CurveItem;

                    if (item != null && iPt >= 0)
                    {
                        if (item.IsSelected)
                        {
                            objState = ContextMenuObjectState.ActiveSelection;
                        }
                        else
                        {
                            objState = ContextMenuObjectState.InactiveSelection;
                        }
                    }
                }
            }

            return(objState);
        }
예제 #10
0
        cmdFanBlade_Click(object sender, EventArgs e)
        {
            int cIncrement = degRotate;

            if (cIncrement == 0)
            {
                cIncrement = 45;
            }

            IntPtr hdc = GdiGraphics.GetDC(m_hwndForm);

            for (int i = 0; i < 360; i += cIncrement)
            {
                IntPtr hfont    = GdiFont.Create(hdc, "Tahoma", 12, i);
                IntPtr hfontOld = GdiGraphics.SelectObject(hdc, hfont);

                GdiGraphics.ExtTextOut(hdc, m_xText, m_yText, 0,
                                       IntPtr.Zero, "Rotated Text", 12, IntPtr.Zero);

                GdiGraphics.SelectObject(hdc, hfontOld);
                GdiGraphics.DeleteObject(hfont);
            }

            GdiGraphics.ReleaseDC(m_hwndForm, hdc);
        }
예제 #11
0
        mitemFilePrint_Click(object sender, EventArgs e)
        {
            // Display dialog to select printer & port.
            PAGESETUPDLGSTRUCT psd;

            psd = new PAGESETUPDLGSTRUCT();
            PrintSetupDlg.InitDlgStruct(ref psd, hwndForm);
            int iErr = PrintSetupDlg.ShowDialog(ref psd);

            if (iErr == 0)
            {
                // Either error...
                string strErr = PrintSetupDlg.GetErrorString();
                if (strErr != "Ok")
                {
                    MessageBox.Show(strErr, "PrintGdi");
                }
                // ...Or user clicked <Cancel>
                return;
            }

            IntPtr hdcPrinter = IntPtr.Zero;
            IntPtr hfont      = IntPtr.Zero;
            IntPtr hfontOld   = IntPtr.Zero;

            try
            {
                // Connect to printer by creating a DC.
                hdcPrinter = Printing.CreatePrinterDC(ref psd);
                if (hdcPrinter != IntPtr.Zero)
                {
                    // Select font.
                    hfont = GdiFont.Create(tboxInput.Font.Name,
                                           (int)tboxInput.Font.Size, 0, hdcPrinter);
                    hfontOld = GdiGraphics.SelectObject(hdcPrinter, hfont);

                    // Print
                    PrintJob_Gdi.PrintText(tboxInput, hdcPrinter);
                }
                else
                {
                    throw new System.Exception();
                }
            }
            catch
            {
                MessageBox.Show("Error connecting to printer.", "PrintGdi");
            }
            finally
            {
                // Cleanup
                GdiGraphics.SelectObject(hdcPrinter, hfontOld);
                GdiGraphics.DeleteObject(hfont);
                Printing.DeleteDC(hdcPrinter);

                // Clean up resources associated with print dialog.
                PrintSetupDlg.Close(ref psd);
            }
        }
예제 #12
0
        private static int DrawString(GdiGraphics g, string text, Font font, Color color, Point location)
        {
            g.DrawString(text, font, color, location);

            int charFit, charFitWidth;

            return(g.MeasureString(text, font, int.MaxValue, out charFit, out charFitWidth).Height);
        }
예제 #13
0
 public RenderArgs(RenderMode mode, Graphics graphics, MindMap chart, Font font)
     : this()
 {
     Mode     = mode;
     Graphics = new GdiGraphics(graphics);
     Chart    = chart;
     Font     = new GdiFont(font);
 }
예제 #14
0
        private void PanelPaint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            Graphics    g  = e.Graphics;
            GdiGraphics gg = new GdiGraphics(g);

            Render(gg);

            g.Flush();
        }
예제 #15
0
        void IPainter.FillRectangle(int x, int y, int width, int height, int argb)
        {
            if (SkipWhite && (argb & 0x00ffffff) == 0x00ffffff)
            {
                return;                 // Do not fill white paint onto white canvas
            }

            GdiGraphics.FillRectangle(GetBrush(argb), x + Shift.Width - 0.75f, y + Shift.Height - 0.75f, width + 1, height + 1);
        }
예제 #16
0
        private void PanelPaint(object sender, PaintEventArgs e)
        {
            Graphics    g  = e.Graphics;
            GdiGraphics gg = new GdiGraphics(g);

            Render(gg);

            g.Flush();
        }
        /// <summary>
        /// Rendering method used by the print context menu items
        /// </summary>
        /// <param name="sender">The applicable <see cref="PrintDocument" />.</param>
        /// <param name="e">A <see cref="PrintPageEventArgs" /> instance providing
        /// page bounds, margins, and a Graphics instance for this printed output.
        /// </param>
        private void Graph_PrintPage(object sender, PrintPageEventArgs e)
        {
            PrintDocument pd = sender as PrintDocument;

            MasterPane mPane = this.MasterPane;

            bool[] isPenSave  = new bool[mPane.PaneList.Count + 1];
            bool[] isFontSave = new bool[mPane.PaneList.Count + 1];
            isPenSave[0]  = mPane.IsPenWidthScaled;
            isFontSave[0] = mPane.IsFontsScaled;
            for (int i = 0; i < mPane.PaneList.Count; i++)
            {
                isPenSave[i + 1]  = mPane[i].IsPenWidthScaled;
                isFontSave[i + 1] = mPane[i].IsFontsScaled;
                if (_isPrintScaleAll)
                {
                    mPane[i].IsPenWidthScaled = true;
                    mPane[i].IsFontsScaled    = true;
                }
            }

            RectangleF saveRect = mPane.Rect;
            SizeF      newSize  = mPane.Rect.Size;

            if (_isPrintFillPage && _isPrintKeepAspectRatio)
            {
                float xRatio = (float)e.MarginBounds.Width / (float)newSize.Width;
                float yRatio = (float)e.MarginBounds.Height / (float)newSize.Height;
                float ratio  = Math.Min(xRatio, yRatio);

                newSize.Width  *= ratio;
                newSize.Height *= ratio;
            }
            else if (_isPrintFillPage)
            {
                newSize = e.MarginBounds.Size;
            }

            mPane.ReSize(new GdiGraphics(e.Graphics), new RectangleF(e.MarginBounds.Left,
                                                                     e.MarginBounds.Top, newSize.Width, newSize.Height));
            mPane.Draw(new GdiGraphics(e.Graphics));

            using (IGraphics g = new GdiGraphics(CreateGraphics()))
            {
                mPane.ReSize(g, saveRect);
                //g.Dispose();
            }

            mPane.IsPenWidthScaled = isPenSave[0];
            mPane.IsFontsScaled    = isFontSave[0];
            for (int i = 0; i < mPane.PaneList.Count; i++)
            {
                mPane[i].IsPenWidthScaled = isPenSave[i + 1];
                mPane[i].IsFontsScaled    = isFontSave[i + 1];
            }
        }
예제 #18
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                GdiGraphics.Dispose();
                metafile.Dispose();
            }

            base.Dispose(disposing);
        }
예제 #19
0
        // Override the XRControl.PutStateToBrick method.
        protected override void PutStateToBrick(VisualBrick brick, PrintingSystemBase ps)
        {
            // Call the PutStateToBrick method of the base class.            
            base.PutStateToBrick(brick, ps);

            // Get the Panel brick which represents the current progress receiveBar control.
            PanelBrick panel = (PanelBrick)brick;
            panel.BackColor = Color.Transparent;
            int width = Convert.ToInt32(Math.Round(panel.Rect.Width));
            int height = Convert.ToInt32(Math.Round(panel.Rect.Height));

            Bitmap bitmap = new Bitmap(width, height);
            bitmap.SetResolution(300, 300);
            GdiGraphics gBmp = new GdiGraphics(Graphics.FromImage(bitmap), ps);

            //int colorWidth = Convert.ToInt32(Math.Round(width * (Position / MaxValue)));

            //int colorWid = Convert.ToInt32(Math.Round((MaxValue-width) * (Position / MaxValue)));

            gBmp.FillEllipse(new SolidBrush(panel.Style.ForeColor), new Rectangle(0, 0, width, height));
           

            //gBmp.FillRectangle(new SolidBrush(panel.Style.ForeColor), new Rectangle(0, 0, colorWidth, height));


            // gBmp.FillRectangle(new SolidBrush(panel.Style.BackColor), new Rectangle(0,colorWidth, colorWid, height));



            //String drawString = Position.ToString();
            ////
            //drawString += " %";
            //Font drawFont = new Font("Frutiger LT Arabic 55", 9);
            //SolidBrush drawBrush = new SolidBrush(Color.Black);

            //StringFormat drawFormat = new StringFormat();
            //drawFormat.Alignment = StringAlignment.Center;
            //drawFormat.LineAlignment = StringAlignment.Center;

            //gBmp.DrawString(drawString, drawFont, drawBrush, new Rectangle(0, 0, width, height), drawFormat);

            gBmp.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            ImageBrick image = new ImageBrick();
            image.Rect = new RectangleF(0, 0, panel.Rect.Width, panel.Rect.Height);
            image.SizeMode = ImageSizeMode.Squeeze;
            image.Image = bitmap;
            image.BackColor = Color.Transparent;

            image.Sides = BorderSide.None;
            

            panel.Bricks.Add(image);
            panel.BackColor = Color.Transparent;
        }
예제 #20
0
        public RenderArgs(RenderMode mode, Graphics graphics, MindMapView view, Font font)
            : this()
        {
            Mode     = mode;
            Graphics = new GdiGraphics(graphics);
            View     = view;
            Font     = new GdiFont(font);

            if (view != null)
            {
                Chart = view.Map;
            }
        }
예제 #21
0
        private void RunScriptToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PictureBox  picBox = imagePreview.PicBox;
            frmDocument doc    = GetActiveDocument();

            svgContents.Clear();
            imagePreview.Clear();
            outputWindow.Clear();

            saveImageToolStripMenuItem.Enabled = false;

            Cursor = Cursors.WaitCursor;

            SvgGraphics ig       = new SvgGraphics();
            Bitmap      bitmap   = new Bitmap(picBox.Width, picBox.Height, PixelFormat.Format32bppArgb);
            GdiGraphics graphics = new GdiGraphics(Graphics.FromImage(bitmap));

            if (dpmmX <= 0 || dpmmY <= 0)
            {
                dpmmX = graphics.DpiX / 25.4F;
                dpmmY = graphics.DpiY / 25.4F;
            }

            try
            {
                RunScript(ig, doc.ScriptText);
                RunScript(graphics, doc.ScriptText);

                if (bitmap == null)
                {
                    return;
                }

                svgContents.ReadOnlyText = ig.WriteSVGString();
                picBox.Image             = bitmap;

                saveImageToolStripMenuItem.Enabled = true;

                Cursor = Cursors.Default;
            }
            catch (Exception exp)
            {
                Cursor = Cursors.Default;
                outputWindow.ReadOnlyText = exp.Message;
                outputWindow.Activate();
                MessageBox.Show(this, "There were script errors. Unable to draw image.", "Script Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #22
0
        void IPainter.PaintSymbol(char symbol, Point atPoint, int symbolSize, int symbolBoxSize, int fontRgb, int backgroundRgb)
        {
            ((IPainter)this).FillRectangle(atPoint.X, atPoint.Y, symbolBoxSize, symbolBoxSize, backgroundRgb);

            if (fontRgb != backgroundRgb)
            {
                symbolSize = symbolSize * 9 / 10;

                var symbolShift = GetSymbolShift(symbol, symbolSize, symbolBoxSize);

                GdiGraphics.DrawString(
                    symbol.ToString(),
                    GetGdiFont(symbolSize),
                    GetBrush(fontRgb),
                    atPoint.X + Shift.Width + symbolShift.Width,
                    atPoint.Y + Shift.Height + symbolShift.Height);
            }
        }
예제 #23
0
//		Thread t = null;
        //DrawingThread dt = null;

/*
 *              /// <summary>
 *              ///
 *              /// </summary>
 *              /// <param name="dtdobj"></param>
 *              public void DoDrawingThread( object dtdobj )
 *              {
 *                      try
 *                      {
 *                              DrawingThreadData dtd = (DrawingThreadData) dtdobj;
 *
 *                              if ( dtd._g != null && dtd._masterPane != null )
 *                                      dtd._masterPane.Draw( dtd._g );
 *
 *                              //				else
 *                              //				{
 *                              //					using ( Graphics g2 = CreateGraphics() )
 *                              //						_masterPane.Draw( g2 );
 *                              //				}
 *                      }
 *                      catch
 *                      {
 *
 *                      }
 *              }
 */

        /// <summary>
        /// Called when the control has been resized.
        /// </summary>
        /// <param name="sender">
        /// A reference to the control that has been resized.
        /// </param>
        /// <param name="e">
        /// An EventArgs object.
        /// </param>
        protected void ZedGraphControl_ReSize(object sender, System.EventArgs e)
        {
            lock (this)
            {
                if (BeenDisposed || _masterPane == null)
                {
                    return;
                }

                Size newSize = this.Size;

                if (_isShowHScrollBar)
                {
                    hScrollBar1.Visible  = true;
                    newSize.Height      -= this.hScrollBar1.Size.Height;
                    hScrollBar1.Location = new Point(0, newSize.Height);
                    hScrollBar1.Size     = new Size(newSize.Width, hScrollBar1.Height);
                }
                else
                {
                    hScrollBar1.Visible = false;
                }

                if (_isShowVScrollBar)
                {
                    vScrollBar1.Visible  = true;
                    newSize.Width       -= this.vScrollBar1.Size.Width;
                    vScrollBar1.Location = new Point(newSize.Width, 0);
                    vScrollBar1.Size     = new Size(vScrollBar1.Width, newSize.Height);
                }
                else
                {
                    vScrollBar1.Visible = false;
                }

                using (IGraphics g = new GdiGraphics(CreateGraphics()))
                {
                    _masterPane.ReSize(g, new RectangleF(0, 0, newSize.Width, newSize.Height));
                    //g.Dispose();
                }
                this.Invalidate();
            }
        }
        /// <summary>
        /// A threaded version of the copy method to avoid crash with MTA
        /// </summary>
        private void ClipboardCopyThreadEmf()
        {
            using (Graphics g = this.CreateGraphics())
            {
                IntPtr   hdc      = g.GetHdc();
                Metafile metaFile = new Metafile(hdc, EmfType.EmfPlusOnly);
                g.ReleaseHdc(hdc);

                IGraphics gMeta = new GdiGraphics(Graphics.FromImage(metaFile));
                {
                    this._masterPane.Draw(gMeta);
                }

                //IntPtr hMeta = metaFile.GetHenhmetafile();
                ClipboardMetafileHelper.PutEnhMetafileOnClipboard(this.Handle, metaFile);
                //System.Windows.Forms.Clipboard.SetDataObject(hMeta, true);

                //g.Dispose();
            }
        }
예제 #25
0
        public Image DrawDiagramAlpha()
        {
            Bitmap img = new Bitmap(dlginstance.VisibleRect.Size.Width - 1, dlginstance.VisibleRect.Size.Height - 1,
                                    System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            Graphics gr = Graphics.FromImage(img);

            gr.Clear(Color.FromArgb(0, 255, 255, 255));
            gr.Clip              = new Region(new Rectangle(0, 0, img.Width, img.Height));
            gr.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            gr.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

            GdiGraphics gg = new GdiGraphics(gr);

            dlginstance.Draw(gg, 1.0f, -1, -1,
                             new Point(-(dlginstance.VisibleRect.Location.X + 1), -(dlginstance.VisibleRect.Location.Y + 1))
                             , DrawClips, dlginstance.VisibleRect.Width);

            return(img);
        }
예제 #26
0
        void IPainter.PaintText(string text, Point atPoint, int pixelHeight, int argb, int spaceBetweenCharacters, FontBasePainter.TextDirection direction)
        {
            var font = GetGdiFont(pixelHeight);

            var stringFormat = new StringFormat();

            if (direction == FontBasePainter.TextDirection.VerticalDownward || direction == FontBasePainter.TextDirection.VerticalUpward)
            {
                stringFormat.FormatFlags = StringFormatFlags.DirectionVertical;
            }

            var verticalShift = 0;

            if (direction == FontBasePainter.TextDirection.VerticalUpward)
            {
                var textSize = GetTextSize(text, font);
                verticalShift = textSize.Width;
            }

            GdiGraphics.DrawString(text, font, GetBrush(argb), atPoint.X + Shift.Width, atPoint.Y + Shift.Height - verticalShift + 1f, stringFormat);
        }
예제 #27
0
        /// <summary>This performs an axis change command on the graphPane.
        /// </summary>
        /// <remarks>
        /// This is the same as
        /// <c>ZedGraphControl.GraphPane.AxisChange( ZedGraphControl.CreateGraphics() )</c>, however,
        /// this method also calls <see cref="SetScrollRangeFromData" /> if <see cref="IsAutoScrollRange" />
        /// is true.
        /// </remarks>
        public virtual void AxisChange()
        {
            lock (this)
            {
                if (BeenDisposed || _masterPane == null)
                {
                    return;
                }

                using (IGraphics g = new GdiGraphics(CreateGraphics()))
                {
                    _masterPane.AxisChange(g);
                    //g.Dispose();
                }

                if (_isAutoScrollRange)
                {
                    SetScrollRangeFromData();
                }
            }
        }
예제 #28
0
        mitemFilePrint_Click(object sender, EventArgs e)
        {
            IntPtr hdcPrinter = IntPtr.Zero;
            IntPtr hfont      = IntPtr.Zero;
            IntPtr hfontOld   = IntPtr.Zero;

            try
            {
                // Connect to printer by creating a DC.
                hdcPrinter = mPrint.mPrintRenderWrapper.CreatePrinterContext();
                if (hdcPrinter != IntPtr.Zero)
                {
                    // Select font.
                    hfont = GdiFont.Create(tboxInput.Font.Name,
                                           (int)tboxInput.Font.Size, 0, hdcPrinter);
                    hfontOld = GdiGraphics.SelectObject(hdcPrinter, hfont);

                    // Print
                    PrintJob_Gdi.PrintText(tboxInput, hdcPrinter);
                }
                else
                {
                    throw new System.Exception();
                }
            }
            catch
            {
                MessageBox.Show("Error connecting to printer.",
                                "PrintHPMobile");
            }
            finally
            {
                // Cleanup
                GdiGraphics.SelectObject(hdcPrinter, hfontOld);
                GdiGraphics.DeleteObject(hfont);
                mPrint.mPrintRenderWrapper.DeletePrinterContext(hdcPrinter);
            }
        }
예제 #29
0
 private void DrawLine(Pen pen, System.Drawing.Point a, System.Drawing.Point b) => GdiGraphics.DrawLine(pen, a, b);
예제 #30
0
 private void DrawRectangle(System.Drawing.Pen pen, System.Drawing.RectangleF rect) => GdiGraphics.DrawRectangle(pen, System.Drawing.Rectangle.Round(rect));
예제 #31
0
		private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
		{
			// Scale the page to match sizes of the screen
			e.Graphics.PageUnit = GraphicsUnit.Inch;
			e.Graphics.PageScale = 1 / Graphics.DpiX;

			// Get the phisical page margins
			float marginScale = Graphics.DpiX / 100;
			RectangleF marginBounds = e.MarginBounds;
			if (!printDocument.PrintController.IsPreview)
				marginBounds.Offset(-e.PageSettings.HardMarginX, -e.PageSettings.HardMarginY);
			marginBounds = new RectangleF(
				marginBounds.X * marginScale, marginBounds.Y * marginScale,
				marginBounds.Width * marginScale, marginBounds.Height * marginScale);

			// Get logical area information
			RectangleF drawingArea = document.GetPrintingArea(selectedOnly);
			int column = pageIndex % columns;
			int row = pageIndex / columns;

			// Get zooming information if diagram is too big
			float scaleX = columns * marginBounds.Width / drawingArea.Width;
			float scaleY = rows * marginBounds.Height / drawingArea.Height;
			float scale = Math.Min(scaleX, scaleY);
			if (scale > 1) scale = 1; // No need for zooming in

			// Set the printing clip region
			RectangleF clipBounds = marginBounds;
			if (column == 0)
			{
				clipBounds.X = 0;
				clipBounds.Width += marginBounds.Left;
			}
			if (row == 0)
			{
				clipBounds.Y = 0;
				clipBounds.Height += marginBounds.Top;
			}
			if (column == columns - 1)
			{
				clipBounds.Width += marginBounds.Left;
			}
			if (row == rows - 1)
			{
				clipBounds.Height += marginBounds.Top;
			}
			e.Graphics.SetClip(clipBounds);

			// Moving the image to it's right position
			e.Graphics.TranslateTransform(-column * marginBounds.Width, -row * marginBounds.Height);
			e.Graphics.TranslateTransform(marginBounds.Left, marginBounds.Top);
			e.Graphics.ScaleTransform(scale, scale);
			e.Graphics.TranslateTransform(-drawingArea.Left, -drawingArea.Top);
			
			// Printing
			IGraphics graphics = new GdiGraphics(e.Graphics);
			document.Print(graphics, selectedOnly, printingStyle);
			e.HasMorePages = (++pageIndex < PageCount);
		}
예제 #32
0
 void IDocumentVisualizer.DrawDocument(Graphics g)
 {
     if (HasDocument)
     {
         IGraphics graphics = new GdiGraphics(g);
         Diagram.Print(graphics, false, Style.CurrentStyle);
     }
 }