找回密码
 立即注册

QQ登录

只需一步,快速开始

guojuanbo

高级会员

13

主题

45

帖子

1314

积分

高级会员

积分
1314

活字格认证

guojuanbo
高级会员   /  发表于:2015-2-9 11:15  /   查看:4343  /  回复:1
再请教一下,如果图片宽度过大,如何在插入图片时让图片自适应窗体的大小

1 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2015-2-9 14:11:00
沙发
回复 1楼guojuanbo的帖子

链接中提供了 TX WinForms 调整页面大小的解决方法:
http://www.textcontrol.com/en_US/blog/archive/20080508/

关键代码:

  1. private void textControl1_ImageCreated(object sender, TXTextControl.ImageEventArgs e)
  2. {
  3.     // get screen resolution to convert twips to pixel
  4.     int iTwipsPerPixel = (int)(1440 / textControl1.CreateGraphics().DpiX);

  5.     if (((float)(e.Image.Size.Width / iTwipsPerPixel)) >= (textControl1.Sections.GetItem().Format.PageSize.Width - textControl1.Sections.GetItem().Format.PageMargins.Left - textControl1.Sections.GetItem().Format.PageMargins.Right))
  6.     {
  7.         // resize the image
  8.         float fScaleFactor = ((textControl1.Sections.GetItem().Format.PageSize.Width - textControl1.Sections.GetItem().Format.PageMargins.Left - textControl1.Sections.GetItem().Format.PageMargins.Right) / ((float)(e.Image.Size.Width / iTwipsPerPixel))) * 100;
  9.         e.Image.VerticalScaling = Convert.ToInt32(fScaleFactor);
  10.         e.Image.HorizontalScaling = Convert.ToInt32(fScaleFactor);
  11.     }
  12. }
复制代码


TX ActiveX 版本中对应 textControl1_ImageCreated 事件的接口为 TXTextControl.ObjectCreated。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部