繁体   English   中英

将鼠标悬停时,C#将图片框的数组中的图片框上移

[英]c# move picturebox from an array of picturebox up when you hover mouse

我正在使用C#Windows窗体。 我有一个显示在窗体上的图片框数组。 数组的大小为13,它们并排放置。 我该如何做,以便当我单击一个图片框时,将其上移+ y +20。 我的代码使图片框。 在上面声明了pb1和p1

void print_Deck(int x, int y, double[] a){
        double n;
        for (int i = 0; i < 13; i++)
        {

            pb1[i] = new PictureBox();
            // pb1[1].Image = Properties.Resources.img1;
            pb1[i].Visible = true;
            pb1[i].Location = new Point(0, 0);
            this.Size = new Size(800, 600);
            pb1[i].Size = new Size(46, 65);
            pb1[i].SizeMode = PictureBoxSizeMode.StretchImage;
            pb1[i].Location = new Point(x, y);
            n= a[i];
            im = face(n);
            pb1[i].Image = im;
            this.Controls.Add(pb1[i]);
            x = x + 20;
        }
    }

您可以尝试在Picturebox上添加Click事件,然后可以在Click函数上尝试此代码。

您可以使用“顶部”属性来操纵位置。

Picturebox.Top -= 20; // move the picture box upward

要么

Picturebox.Top += 20; // move the picture box downward

或使用.Location = New Point(X,Y)

Picturebox.Location = new Point(Picturebox.Location.X, Picturebox.Location.Y + 20);

这是将EventHandler添加到图片框的方法。

Picturebox.Click += new System.EventHandler(this.Picturebox_ClickFunction);

然后创建一个名为Picturebox_ClickFunction的功能

private void Picturebox_ClickFunction(object sender, EventArgs e)
{
     PictureBox pb1 = (PictureBox)sender; // you need to cast(convert) the sende to a picturebox object so you can access the picturebox properties
}

那么您可以使用我上面提供的代码。

您可以尝试PictureBox.Top财产属性或使用PictureBox.Location

您可以注册PictureBox的 “点击”事件,以将“保证金”属性调整为所需的数量

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM