小编Luc*_*ggy的帖子

避免一次又一次地创建PictureBoxes

我有以下问题.我的目的是在Windows窗体中从右向左移动多个图像.下面的代码非常好用.令我困扰的是,每次创建PictureBox对象时,此过程都会占用大量内存.每个图像从右到左不间断地跟随前一图像.图像显示从一侧移动到另一侧的天空.它应该看起来像一架飞机在空中飞舞.

如何避免使用太多内存?我可以用PaintEvent和GDI做些什么吗?我对图形编程不太熟悉.

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;

public class Background : Form
    {

        private PictureBox sky, skyMove;
        private Timer moveSky;
        private int positionX = 0, positionY = 0, width, height;
        private List<PictureBox> consecutivePictures;


        public Background(int width, int height)
        {

            this.width = width;
            this.height = height;

            // Creating Windows Form
            this.Text = "THE FLIGHTER";
            this.Size = new Size(width, height);
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;


            // The movement of the sky becomes possible by the …
Run Code Online (Sandbox Code Playgroud)

c# memory picturebox winforms

5
推荐指数
0
解决办法
652
查看次数

标签 统计

c# ×1

memory ×1

picturebox ×1

winforms ×1