GDI+双缓冲

        private void Draw(Graphics g, Point[] point, int Linex = -1, int Liney = -1)
        {
            Image bjImg = Image.FromFile("beijing.png");
            Image mapImg = Image.FromFile("map.png");

            int imageHeight = 23;
            int imageWidth = 15;

            g.DrawImage(bjImg, new Point(0, 0));

            foreach (Point item in point)
            {
                g.DrawImage(mapImg, new Rectangle(item.X - imageWidth / 2, item.Y - imageHeight, imageWidth, imageHeight));
            }

            g.DrawLine(p, new Point(Linex, 0), new Point(Linex, this.Height));

            g.DrawLine(p, new Point(0, Liney), new Point(this.Width, Liney));

            g.DrawEllipse(p, Linex - 15, Liney - 15, 30, 30);

            g.DrawEllipse(p, Linex - 10, Liney - 10, 20, 20);

            g.DrawString("X:" + Linex + " Y:" + Liney, new Font("SimHei", 8), new SolidBrush(Color.Red), Linex+50, Liney-5, sf);

            bjImg.Dispose();
            mapImg.Dispose();

            g.Dispose();
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            Bitmap map = new Bitmap(this.panel1.Width, this.panel1.Height);


            LoadData();


            Graphics g = Graphics.FromImage(map);


            g.Clear(this.panel1.BackColor);


            Draw(g, point, e.X, e.Y);


            Graphics gg = this.panel1.CreateGraphics();
            gg.DrawImage(map, 0, 0);
            gg.Dispose();
            map.Dispose();


            lbXY.Text = "坐标: X:" + e.X + " Y:" + e.Y;
        }

你可能感兴趣的:(C#)