拉伸画框 [英] Stretching a picturebox

查看:118
本文介绍了拉伸画框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在窗体中使用图片框,并且其sizemode属性设置为"StretchImage".我在此图片框内填充了动态创建的按钮,这些按钮的位置已经使用另一种格式进行了设置,并在数据库中进行了更新.我的问题是,当图片框中的图像被拉伸时,控件的位置保持不变(与数据库中的控件相同).我希望将它们相对于拉伸后的图像进行重定位.这可能吗?请帮帮我. ......

Sunitha

Hi,
I am using a picturebox in my form and it has its sizemode property set to ''StretchImage''.I am populating dynamically created buttons inside this picturebox ,the locations of which have already been set using another form and is updated in the database.My problem is that when the image in the picturebox gets stretched,the locations of the controls remain the same(as in the database).I want them to be relocated relative to the stretched image.Is this possible?Please help me out........

Sunitha

推荐答案

尝试一下.

Try this.

int originalPictureWidth = 50; //you should know the original size
int originalPictureHeight = 50;
double xScale = (double)pictureBox1.Width / (double)originalPictureWidth;
double yScale = (double)pictureBox1.Height / (double)originalPictureHeight;
using (DataSet ds = new LayoutDAL().GetLayoutDetails(_layoutId))
{
    Button bt = new Button(); bt.SetBounds(
        (int)(Convert.ToDouble(ds.Tables[0].Rows[i]["LocationX"]) * xScale),
        (int)(Convert.ToDouble(ds.Tables[0].Rows[i]["LocationY"]) * yScale), 60, 60);
}


这篇关于拉伸画框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆