为什么运行时创建的pictureBox没有出现?

时间:2014-12-18 22:15:03

标签: c# winforms runtime picturebox

我正在尝试创建pictureBox运行时,但不能这样做。

我正在使用此代码:

            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.Controls.Add(this.pictureBox1);

            this.pictureBox1.Location = new System.Drawing.Point(109, 32);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(width * 10, height * 10);
            this.pictureBox1.TabIndex = 4;
            this.pictureBox1.TabStop = false;
            this.pictureBox1.Image = resizedImage;
            this.pictureBox1.Click += new System.EventHandler(this.pictureBox_Click);

            this.pictureBox1.SetControlZIndex(999);
            this.groupBox1.SetControlZIndex(10);
            this.SetControlZIndex(1);
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();

            this.Update();

此外,pictureBox被声明为Form1字段(this)。

代码工作没有任何错误(尝试catch没有捕获任何东西)。

我在109,32位置看不到任何内容。

我还假设它是z-index问题(如在html mb中...)并找到如何管理控件z-index,但它没有帮助我。

我如何解决我的问题?

1 个答案:

答案 0 :(得分:0)

不确定你在那里做什么。如果你想让它在前面,那么只需使用BringToFront():

        this.pictureBox1 = new System.Windows.Forms.PictureBox();
        this.pictureBox1.Location = new System.Drawing.Point(109, 32);
        this.pictureBox1.Name = "pictureBox1";
        this.pictureBox1.Size = new System.Drawing.Size(width * 10, height * 10);
        this.pictureBox1.TabIndex = 4;
        this.pictureBox1.TabStop = false;
        this.pictureBox1.Image = resizedImage;
        this.pictureBox1.Click += new System.EventHandler(this.pictureBox_Click);
        this.Controls.Add(this.pictureBox1);
        this.pictureBox1.BringToFront();

对我来说很好。我们需要有关您应用的更多详细信息......