Ejemplo n.º 1
0
        private void ReDrawAll()
        {
            Graphics  g       = this.CreateGraphics();
            GObject   CurrObj = new GObject();
            Rectangle Rct     = new Rectangle();
            Pen       p       = new Pen(Color.Blue);
            Image     ObjImg;
            int       xm     = 0;
            int       ym     = 0;
            string    IsLine = "";

            for (int i = 0; i < GNetwork.Nobj; i++)
            {
                CurrObj = GNetwork.GObjects[i];
                //
                if (CurrObj.Type == "")
                {
                    IsLine = "N/D";
                }
                if (CurrObj.Type == "Line")
                {
                    IsLine = "Y";
                }
                if ((CurrObj.Type != "Line") && (CurrObj.Type != ""))
                {
                    IsLine = "N";
                }
                //
                switch (IsLine)
                {
                case "Y":
                    g.DrawLine(p, CurrObj.x1, CurrObj.y1, CurrObj.x2, CurrObj.y2);
                    xm = (CurrObj.x1 + CurrObj.x2) / 2;
                    ym = (CurrObj.y1 + CurrObj.y2) / 2;
                    AddText(xm, ym, CurrObj.Name, false);
                    break;

                case "N":
                    Rct.X      = CurrObj.x1;
                    Rct.Y      = CurrObj.y1;
                    Rct.Width  = CurrObj.x2 - CurrObj.x1;
                    Rct.Height = CurrObj.y2 - CurrObj.y1;
                    if (CurrObj.Type != String.Empty)
                    {
                        ObjImg = FindGObjectTypeImage(CurrObj.Type);
                        g.DrawImage(ObjImg, Rct);
                        AddText(CurrObj.x1, CurrObj.y1, CurrObj.Name, true);
                        GNetwork.AdjustLinkedTo(CurrObj.Name);
                    }
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private void ReDrawAll(PaintEventArgs e)//重會所有元件
        {
            //--
            //表單繪圖不閃爍_step02
            BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
            BufferedGraphics        myBuffer       = currentContext.Allocate(e.Graphics, e.ClipRectangle);
            Graphics g = myBuffer.Graphics;

            g.SmoothingMode   = SmoothingMode.HighQuality;
            g.PixelOffsetMode = PixelOffsetMode.HighSpeed;
            g.Clear(this.BackColor);
            //--

            //Graphics g = this.CreateGraphics();//直接是在表單建立畫布
            GObject   CurrObj = new GObject();       //建立元件
            Rectangle Rct     = new Rectangle();     //建立矩形元件
            Pen       p       = new Pen(Color.Blue); //建立畫筆
            Image     ObjImg;
            int       xm     = 0;
            int       ym     = 0;
            string    IsLine = "";

            for (int i = 0; i < GNetwork.Nobj; i++)//依序取出元件
            {
                CurrObj = GNetwork.GObjects[i];
                //
                if (CurrObj.Type == "")
                {
                    IsLine = "N/D";
                }
                if (CurrObj.Type == "Line")
                {
                    IsLine = "Y";
                }
                if ((CurrObj.Type != "Line") && (CurrObj.Type != ""))
                {
                    IsLine = "N";
                }
                //
                switch (IsLine)
                {
                case "Y":
                    g.DrawLine(p, CurrObj.x1, CurrObj.y1, CurrObj.x2, CurrObj.y2);
                    xm = (CurrObj.x1 + CurrObj.x2) / 2;
                    ym = (CurrObj.y1 + CurrObj.y2) / 2;
                    AddText(g, xm, ym, CurrObj.Name, false);
                    break;

                case "N":
                    Rct.X      = CurrObj.x1;
                    Rct.Y      = CurrObj.y1;
                    Rct.Width  = CurrObj.x2 - CurrObj.x1;
                    Rct.Height = CurrObj.y2 - CurrObj.y1;
                    if (CurrObj.Type != String.Empty)
                    {
                        ObjImg = FindGObjectTypeImage(CurrObj.Type);
                        g.DrawImage(ObjImg, Rct);
                        AddText(g, CurrObj.x1, CurrObj.y1, CurrObj.Name, true);
                        GNetwork.AdjustLinkedTo(CurrObj.Name);
                    }
                    break;
                }
            }

            //--
            //表單繪圖不閃爍_step03
            myBuffer.Render(e.Graphics);
            g.Dispose();
            myBuffer.Dispose();//释放资源
            //--
        }