Winform 移动窗口背景图片位置
要移动Winform窗口的背景图片位置,您可以使用以下方法:
- 在窗体的构造函数中,将窗体的背景图片布局设置为Tile。
this.BackgroundImageLayout = ImageLayout.Tile;
- 在窗体的MouseMove事件中,获取鼠标的位置,并重新设置背景图片的偏移量。
private void Form1_MouseMove(object sender, MouseEventArgs e) { int x = e.X; int y = e.Y; this.BackgroundImage = Properties.Resources.background; //设置背景图片 this.BackgroundImagePosition = new Point(x, y); //设置背景图片的偏移量 }
这样,当鼠标移动时,背景图片的位置也会跟随移动。
注意:如果您使用的是带有透明度的背景图片,您需要将窗体的双缓冲设置为true,以避免背景图片的重绘出现闪烁。
原文地址: https://www.cveoy.top/t/topic/fTnI 著作权归作者所有。请勿转载和采集!