我在我的图片框中添加了图片缩放功能。我想显示图像的比例(如地图左下角)。我将如何实现这一目标?
答案 0 :(得分:0)
您可以使用Paint
事件在顶部绘制比例。
假设变焦在x和y方向上是对称的,这就是一个例子:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
float zoom =100f * pictureBox1.ClientSize.Width / pictureBox1.Image.Width;
// this may or may not be necessary, depending on how to have implemented zooming!
if (pictureBox1.SizeMode == PictureBoxSizeMode.Normal) zoom = 100f;
string s = zoom.ToString("#.#")+ "%";
StringFormat format = new StringFormat()
{ LineAlignment = StringAlignment.Far,
Alignment = StringAlignment.Far };
Rectangle bounds = pictureBox1.ClientRectangle;
Rectangle bounds1 = pictureBox1.ClientRectangle;
bounds1.Offset(1, 1);
using (Font font = new Font("Consolas", 14f))
{
e.Graphics.DrawString(s, font, Brushes.White, bounds , format);
e.Graphics.DrawString(s, font, Brushes.Black, bounds1 , format);
}
}
您可以根据自己的喜好选择对齐方式。
请注意,我将字符串绘制两次,一次为白色,一次为黑色,偏移1像素以允许任何背景..
另请注意Image
是oistrich;景观是(未缩放的BackgroundImage
!