guojuanbo 发表于 2015-2-6 18:12:00

如果图片宽度过大,如何在插入图片时让图片自适应窗体的大小

再请教一下,如果图片宽度过大,如何在插入图片时让图片自适应窗体的大小

iceman 发表于 2015-2-9 14:11:00

回复 1楼guojuanbo的帖子

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

关键代码:

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

    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))
    {
      // resize the image
      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;
      e.Image.VerticalScaling = Convert.ToInt32(fScaleFactor);
      e.Image.HorizontalScaling = Convert.ToInt32(fScaleFactor);
    }
}


TX ActiveX 版本中对应 textControl1_ImageCreated 事件的接口为 TXTextControl.ObjectCreated。
页: [1]
查看完整版本: 如果图片宽度过大,如何在插入图片时让图片自适应窗体的大小