午夜视频在线网站,日韩视频精品在线,中文字幕精品一区二区三区在线,在线播放精品,1024你懂我懂的旧版人,欧美日韩一级黄色片,一区二区三区在线观看视频

分享

C#開發(fā)的矢量圖形繪制(轉(zhuǎn))

 羊玉wngbx 2021-05-17
    using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.IO;                         //streamer io
using System.Runtime.Serialization;     // io
using System.Runtime.Serialization.Formatters.Binary; // io
using System.Drawing.Printing;
 
namespace EmrKB
{
    public partial class vectShapes : UserControl
    {
        private string Status;
        public string Option;
        private string redimStatus = "";
 
        private string msg = "";
        [CategoryAttribute("Debug"), DescriptionAttribute("ShowDebugInfo")]
        public bool ShowDebug { get; set; }
 
        private int startX;
        private int startY;
        private Shapes s;
 
        private float _Zoom = 1;
        private bool _A4 = true;
 
        private int _dx = 0;
        private int _dy = 0;
        private int startDX = 0;
        private int startDY = 0;
        private int truestartX = 0;
        private int truestartY = 0;
 
        //畫筆Pen工具 START
        private ArrayList VisPenPointList;
        private ArrayList PenPointList;
        private int PenPrecX;
        private int PenPrecY;
        //畫筆Pen工具 END
 
        private Bitmap offScreenBmp;
        private Bitmap offScreenBackBmp;
 
        // Grid
        public int _gridSize = 0;
        public bool fit2grid = true;
 
        //Graphic
        private System.Drawing.Drawing2D.CompositingQuality _CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.Default;
        private System.Drawing.Text.TextRenderingHint _TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
        private System.Drawing.Drawing2D.SmoothingMode _SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        private System.Drawing.Drawing2D.InterpolationMode _InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default;
 
        // Drawing Rect
        private bool MouseSx;
        private int tempX;
        private int tempY;
 
        // 預(yù)覽 & 打印
        private Anteprima AnteprimaFrm;
 
        // 編輯框
        private richForm2 editorFrm;
 
        public RichTextBox r;
 
        public Color CreationPenColor;
        public float CreationPenWidth;
        public Color CreationFillColor;
        public bool CreationFilled;
 
        //public PropertyGrid propGrid;
 
        //EVENT
        public event OptionChanged optionChanged;
        public event ObjectSelected objectSelected;
 
        //Image1.tif
        Cursor AddPointCur = getCursor("newPoint3.cur", Cursors.Cross);
        Cursor DelPointCur = getCursor("delPoint3.cur", Cursors.Default);
        // Gets he *.cur file in a.
        public static Cursor getCursor(string a, Cursor defCur)
        {
            try
            {
                return new Cursor(a);
            }
            catch
            {
                return defCur;
            }
        }
 
        public vectShapes()
        {
            InitializeComponent();
            myInit();
  
            //from Ilango.M
            this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true); // added line
        }
 
        //Graphic
        [CategoryAttribute("Graphics"), DescriptionAttribute("Interp.Mode")]
        public System.Drawing.Drawing2D.InterpolationMode InterpolationMode
        {
            get
            {
                return _InterpolationMode;
            }
            set
            {
                _InterpolationMode = value;
            }
        }
 
        [CategoryAttribute("Graphics"), DescriptionAttribute("Smooth.Mode")]
        public System.Drawing.Drawing2D.SmoothingMode SmoothingMode
        {
            get
            {
                return _SmoothingMode;
            }
            set
            {
                _SmoothingMode = value;
            }
        }
 
        [CategoryAttribute("Graphics"), DescriptionAttribute("Txt.Rend.Hint")]
        public System.Drawing.Text.TextRenderingHint TextRenderingHint
        {
            get
            {
                return _TextRenderingHint;
            }
            set
            {
                _TextRenderingHint = value;
            }
        }
 
        [CategoryAttribute("Graphics"), DescriptionAttribute("Comp.Quality")]
        public System.Drawing.Drawing2D.CompositingQuality CompositingQuality
        {
            get
            {
                return _CompositingQuality;
            }
            set
            {
                _CompositingQuality = value;
            }
        }
  
        [CategoryAttribute(" "), DescriptionAttribute("Canvas")]
        public string ObjectType
        {
            get
            {
                return "Canvas";
            }
        }
 
        [CategoryAttribute("  "), DescriptionAttribute("Grid Size")]
        public int gridSize
        {
            get
            {
                return _gridSize;
            }
            set
            {
                if (value >= 0)
                {
                    _gridSize = value;
                }
                if (_gridSize > 0)
                {
                    this.dx = _gridSize * (int)(this.dx / _gridSize);
                    this.dy = _gridSize * (int)(this.dy / _gridSize);
                }
                this.redraw(true);
            }
        }
[CategoryAttribute("  "), DescriptionAttribute("Canvas Zoom")]
        public float Zoom
        {
            get
            {
                return _Zoom;
            }
            set
            {
                if (value > 0)
                {
                    _Zoom = value;
                    this.redraw(true);
                }
                else
                {
                    _Zoom = 1;
                    this.redraw(true);
                }
            }
        }
 
 
        [CategoryAttribute("  "), DescriptionAttribute("Show A4")]
        public bool A4
        {
            get
            {
                return _A4;
            }
            set
            {
                _A4 = value;
            }
        }
 
        [CategoryAttribute("  "), DescriptionAttribute("Canvas OriginX")]
        public int dx
        {
            get
            {
                return _dx;
            }
            set
            {
                _dx = value;
            }
        }
 
        [CategoryAttribute("  "), DescriptionAttribute("Canvas OriginY")]
        public int dy
        {
            get
            {
                return _dy;
            }
            set
            {
                _dy = value;
            }
        }
 
 
        public void zoomIn()
        {
            this.Zoom = (int)(this.Zoom + 1);
        }
 
        public void zoomOut()
        {
            if (this.Zoom > 1)
            {
                this.Zoom = (int)(this.Zoom - 1);
            }
        }
 
        public void mergePolygons()
        {
            s.mergePolygons();
            redraw(true);
        }
        public void delPoints()
        {
            this.s.delPoint();
            redraw(true);
        }
 
        public void linkNodes()
        {
            this.s.linkNodes();
            redraw(true);
        }
 
        public void delNodes()
        {
            this.s.delNodes();
            redraw(true);
        }
 
 
        public void extPoints()
        {
            this.s.extPoints();
            redraw(true);
        }
 
 
        public void XMirror()
        {
            this.s.XMirror();
            redraw(true);
        }
        public void YMirror()
        {
            this.s.YMirror();
            redraw(true);
        }
        public void Mirror()
        {
            this.s.Mirror();
            redraw(true);
        }
 
 
 
        private void myInit()
        {
            //Status = "";
            changeStatus("");
            Option = "select";
 
            Graphics g = this.CreateGraphics();
 
            //retrive printer resolution
            PrintDocument pd = new PrintDocument();
            //MessageBox.Show( pd.PrinterSettings.DefaultPageSettings.PrinterResolution.X.ToString() );
            //MessageBox.Show(pd.PrinterSettings.DefaultPageSettings.PrinterResolution.Y.ToString() );
            Graphics g_pr = pd.PrinterSettings.CreateMeasurementGraphics();
            SizeF sizef;
            float x_pr, y_pr = 0;
 
            sizef = g_pr.MeasureString("YourStringHere", Font);
            x_pr = sizef.Width;
            y_pr = sizef.Height;
            //y_pr = Font.Height;
 
            float x_vi, y_vi = 0;
 
            sizef = g.MeasureString("YourStringHere", Font);
            x_vi = sizef.Width;
            y_vi = sizef.Height;
   
            //s = new Shapes((pd.PrinterSettings.DefaultPageSettings.PrinterResolution.X / g.DpiX), pd.PrinterSettings.DefaultPageSettings.PrinterResolution.Y);
            s = new Shapes(g.DpiX * (x_pr / x_vi), g.DpiY * (y_pr / y_vi));
 
            //            undoB = new UndoBuffer(5);
            g.Dispose();
 
            editorFrm = new richForm2();
            this.r = editorFrm.richTextBox1;
 
            CreationPenColor = Color.Black;
            CreationPenWidth = 1f;
            CreationFillColor = Color.Black;
            CreationFilled = false;
 
            this.optionChanged += new OptionChanged(FakeOptionChange);
            this.objectSelected += new ObjectSelected(FakeObjectSelected);
 
            offScreenBackBmp = new Bitmap(this.Width, this.Height);
            offScreenBmp = new Bitmap(this.Width, this.Height);
        }
 
        private void FakeOptionChange(object sender, OptionEventArgs e)
        { }
 
        private void FakeObjectSelected(object sender, PropertyEventArgs e)
        { }
 
 
        private void changeStatus(string s)
        {
            this.Status = s;
        }
 
        private void changeOption(string s)
        {
            this.Option = s;
            // Notify Option change to "listening object" (i.e: toolBbox)
            OptionEventArgs e = new OptionEventArgs(this.Option);
            optionChanged(this, e);// raise event
        }
 
        public void anteprimaStampa(float zoom)
        {
            InitializePrintPreviewControl(zoom);
        }
 #region Print & Preview
 
        public void Stampa()
        {
            this.s.deSelect();
 
            AnteprimaFrm = new Anteprima();
            AnteprimaFrm.PrintPreviewControl1.Name = "PrintPreviewControl1";
            AnteprimaFrm.PrintPreviewControl1.Document = AnteprimaFrm.docToPrint;
 
            AnteprimaFrm.PrintPreviewControl1.Zoom = 1;
 
            AnteprimaFrm.PrintPreviewControl1.Document.DocumentName = "Anteprima";
 
            AnteprimaFrm.PrintPreviewControl1.UseAntiAlias = true;
 
            AnteprimaFrm.docToPrint.PrintPage +=
                new System.Drawing.Printing.PrintPageEventHandler(
                docToPrint_PrintPage);
 
            // Per stampare
            AnteprimaFrm.docToPrint.Print();
 
            AnteprimaFrm.Dispose();
 
        }
 
        private void InitializePrintPreviewControl(float zoom)
        {
            this.s.deSelect();
 
            AnteprimaFrm = new Anteprima();
            // Construct the PrintPreviewControl.
            //AnteprimaFrm.PrintPreviewControl1 = new PrintPreviewControl();
 
            // Set location, name, and dock style for PrintPreviewControl1.
            //AnteprimaFrm.PrintPreviewControl1.Location = new Point(88, 80);
            AnteprimaFrm.PrintPreviewControl1.Name = "Preview";
            //AnteprimaFrm.PrintPreviewControl1.Dock = DockStyle.Fill;
 
            // da testare??
            //AnteprimaFrm.PrintPreviewControl1.BackColor = this.BackColor;
            //AnteprimaFrm.PrintPreviewControl1.BackgroundImage = this.BackgroundImage;
 
 
            // Set the Document property to the PrintDocument
            // for which the PrintPage event has been handled.
            AnteprimaFrm.PrintPreviewControl1.Document = AnteprimaFrm.docToPrint;
 
            // Set the zoom to 25 percent.
            AnteprimaFrm.PrintPreviewControl1.Zoom = zoom;
 
            // Set the document name. This will show be displayed when
            // the document is loading into the control.
            AnteprimaFrm.PrintPreviewControl1.Document.DocumentName = "Preview";
 
            // Set the UseAntiAlias property to true so fonts are smoothed
            // by the operating system.
            AnteprimaFrm.PrintPreviewControl1.UseAntiAlias = true;
 
            // Add the control to the form.
            //AnteprimaFrm.Controls.Add(AnteprimaFrm.PrintPreviewControl1);
 
            // Associate the event-handling method with the
            // document's PrintPage event.
            AnteprimaFrm.docToPrint.PrintPage +=
                new System.Drawing.Printing.PrintPageEventHandler(
                docToPrint_PrintPage);
 
            // Per stampare
            //AnteprimaFrm.docToPrint.Print();
            AnteprimaFrm.ShowDialog();
        }
 
        // 預(yù)覽圖顯示在界面上
        // by handling the documents PrintPage event
        private void docToPrint_PrintPage(
            object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            // Insert code to render the page here.
            // This code will be called when the control is drawn.
 
            // The following code will render a simple
            // message on the document in the control.
            //string text = "In docToPrint_PrintPage method.";
            //System.Drawing.Font printFont =
            //    new Font("Arial", 35, FontStyle.Regular);
            //  e.Graphics.DrawString(text, printFont,
            //      Brushes.Black, 10, 10);
 
            Graphics g = e.Graphics;
   
            //Do Double Buffering
            //Bitmap offScreenBmp;
            // Graphics offScreenDC;
            //offScreenBmp = new Bitmap(this.Width, this.Height);
            //
            //offScreenDC = Graphics.FromImage(offScreenBmp);
 
            //offScreenDC.Clear(this.BackColor);
 
            //background image
            //if ((this.loadImage) & (this.visibleImage))
            //    offScreenDC.DrawImage(this.loadImg, 0, 0);
            //
 
            //offScreenDC.SmoothingMode=SmoothingMode.AntiAlias;
 
            // test
            //MessageBox.Show("dipx : " + g.DpiX + " ; dipy : " + g.DpiY);
 
            //s.Draw(offScreenDC);
            if (this.BackgroundImage != null)
                g.DrawImage(this.BackgroundImage, 0, 0);
 
            //TEST !!!!!!!!!!!!!!!!!!!!!!!!!!!1
            //this.DrawMesure(g);
 
            s.Draw(g, 0, 0, 1);
 
 
            //if (this.MouseSx)
            //{
            //    System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
            //    offScreenDC.DrawRectangle(myPen, new Rectangle(this.startX, this.startY, tmpX - this.startX, tmpY - this.startY));
            //    myPen.Dispose();
            //}
 
            //g.DrawImageUnscaled(offScreenBmp, 0, 0);
 
            g.Dispose();
        }          

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多