private const int YTextPixelOffset = 30;//80; //这里是创建一个画布 private void ReDrawAll() { Bitmap bmp = new Bitmap(this.panel2.Width, this.panel2.Height); Graphics g = Graphics.FromImage(bmp); g.Clear(this.panel2.BackColor); //Graphics g = this.CreateGraphics(); //Graphics g = this.panel2.CreateGraphics(); g.SmoothingMode = SmoothingMode.AntiAlias; //使绘图质量最高,即消除锯齿 g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingQuality = CompositingQuality.HighQuality; 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++) //urinatedong 只显示需要显示的 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); AdjustableArrowCap lineCap = new AdjustableArrowCap(5, 6, true); Pen p; string[] MyRelationInfo = CurrObj.AddInfo.Split("\n".ToCharArray()); if (MyRelationInfo[6].IndexOf("2") > 0) { p = new Pen(Color.Blue, 3); } else { p = new Pen(Color.Orange, 3); p.DashStyle = DashStyle.Custom; p.DashPattern = new float[] { 6, 3 }; } p.CustomEndCap = lineCap; p.CustomStartCap = lineCap; 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,g); int x1 = (CurrObj.x1 + xm) / 2; int y1 = (CurrObj.y1 + ym) / 2; int x2 = (CurrObj.x2 + xm) / 2; int y2 = (CurrObj.y2 + ym) / 2; AddText(x1, y1, MyRelationInfo[0] + "\n" + MyRelationInfo[1] + "\n" + MyRelationInfo[2], false, g); AddText(x2, y2, MyRelationInfo[3] + "\n" + MyRelationInfo[4] + "\n" + MyRelationInfo[5], false, g); p.Dispose(); break; case "N": string[] MyNodeInfo = CurrObj.AddInfo.Split("\n".ToCharArray()); 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) { if (double.Parse(MyNodeInfo[4].Replace("Battery", "")) > 0) { ObjImg = FindGObjectTypeImage("Router"); } else { ObjImg = FindGObjectTypeImage("NotOnline"); } g.DrawImage(ObjImg, Rct); //使用IP地址显示 //AddText(CurrObj.x1, CurrObj.y1, CurrObj.Name, true,g); AddText(CurrObj.x1, CurrObj.y1, MyNodeInfo[0], true, g); GNetwork.AdjustLinkedTo(CurrObj.Name); } break; } } //g1.DrawEllipse(new Pen(System.Drawing.Color.Red), 10, 10, 100, 100); //g1.DrawImage(Image.FromFile("E:/down.png"), x, 10);//这是在画布上绘制图形 this.panel2.CreateGraphics().DrawImage(bmp, 0, 0);//这句是将图形显示到窗口上 bmp.Dispose(); g.Dispose(); }