【发布时间】:2017-03-13 10:34:11
【问题描述】:
我有一个程序大小,如果我在角落增加它,就是自动增加 ImageBox。不幸的是,这还不起作用,因为发生错误。如果我改变表单大小,有没有人解决这个问题,这也会自动增加 ImageBox。如果我更改表单的大小,我希望 ImageBox 的大小也更大。
private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
{
imgPreview.Source = zoom(imgPreview, new System.Drawing.Size(Convert.ToInt32(this.Width), Convert.ToInt32(this.Height))); // Mistake is here
}
System.Drawing.Image zoom(System.Drawing.Image img, System.Drawing.Size size)
{
Bitmap bmp = new Bitmap(img, img.Width + (img.Width * size.Width / 100), img.Height + (img.Height * size.Height / 100));
Graphics g = Graphics.FromImage(bmp);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
return bmp;
}
<UserControl x:Class="Vorschau.UCOxyplotPreview"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Vorschau"
mc:Ignorable="d" Height="379.573" Width="539.634" SizeChanged="UserControl_SizeChanged">
<Image x:Name="imgPreview" HorizontalAlignment="Left" Height="350" Margin="109,20,0,0" VerticalAlignment="Top" Width="350"/>
</UserControl>
【问题讨论】:
-
你也可以显示你的 xaml 吗?
-
谢谢。完成。
-
以下属性是否有原因:HorizontalAlignment、Height、Margin、VerticalAlignment 和 Width?
-
没有。这是自动生成的。
-
好的,看看我的回答。