Visual Studio应用程序中的图像未对齐

时间:2020-03-05 18:54:22  来源:igfitidea点击:

我有一个Visual Studio应用程序,其初始屏幕图像被切成"切片"。这些位置在"表单设计器"中指定,因此它们在屏幕上正确对齐。但是,当应用程序在中文版本的Windows XP上运行时,图像不正确。看起来好像图像片段被"炸开"了。

这里发生了什么? Windows的国际版本对图片的"左上"坐标是否具有不同的含义?如何强制将图像精确显示在我想要的位置?

解决方案

回答

在窗体的OnLoad事件中,我们始终可以显式设置每个节的位置。如果从第一个左上角开始,并假设图像按顺序排列:

images[0].Location = new Point(0,0);
for (int i = 1; i < images.Length; i++)
{
  images[i].Location = new Point(images[i - 1].Location.X + images[i - 1].Width, 0);
}

这样会将第一个图像设置在左上角,并将所有后续图像设置在最后一个图像之后。

回答

我们找到了解决方案!显然,图片框在中文XP PC上伸展了,但其中包含的图像却没有。解决方法是添加如下代码:

Me.PictureBoxIcon.Width = Me.PictureBoxIcon.Image.Width
Me.PictureBoxIcon.Height = Me.PictureBoxIcon.Image.Height

Dim loc As New Point
loc.X = Me.PictureBoxIcon.Location.X
loc.Y = Me.PictureBoxIcon.Location.Y + Me.PictureBoxIcon.Height
Me.PictureBoxAbout.Location = loc
Me.PictureBoxAbout.Width = Me.PictureBoxAbout.Image.Width
Me.PictureBoxAbout.Height = Me.PictureBoxAbout.Image.Height

希望这对其他人有帮助!