找回密码
 立即注册

QQ登录

只需一步,快速开始

ZenosZeng 讲师达人认证 悬赏达人认证
超级版主   /  发表于:2012-10-31 19:34  /   查看:5208  /  回复:0
随着电脑硬件配置的不断提升,现在主流的显示器已经达到21-24寸,甚至更大的显示器。

在这种大尺寸显示器中,缩放页面至可用宽度或者将整页显示在课间范围内的功能需求就显得更加有意义。

TX Text Control 提供了一个 ZoomFactor 属性用于设置页面的缩放比例,下面的代码演示了如何将当前页全部显示在可见范围内:
  1. private void FitToWindow()
  2. {
  3.     textControl1.PageUnit = MeasuringUnit.Twips;
  4.     int iVisibleGap = 65;

  5.     Graphics g = textControl1.CreateGraphics();
  6.     int iTwipsPerPixel = (int)(1440 / g.DpiX);

  7.     SectionFormat currentSection = textControl1.Sections.GetItem().Format;

  8.     double widthZoom = 100 * textControl1.Width /
  9.         ((currentSection.PageSize.Width / iTwipsPerPixel)
  10.         + iVisibleGap);
  11.     double heightZoom = 100 * textControl1.Height /
  12.         ((currentSection.PageSize.Height / iTwipsPerPixel)
  13.         + iVisibleGap);

  14.     if (widthZoom < heightZoom)
  15.         textControl1.ZoomFactor = (int)widthZoom;
  16.     else
  17.         textControl1.ZoomFactor = (int)heightZoom;
  18. }
复制代码


以下方法演示了如何让页面宽度达到可使用的最大宽度:
  1. private void FitToWidth()
  2. {
  3.     textControl1.PageUnit = MeasuringUnit.Twips;
  4.     int iVisibleGap = 200;

  5.     // get resolution to calculate convert twips 1/100 inch
  6.     Graphics g = textControl1.CreateGraphics();
  7.     int iTwipsPerPixel = (int)(1440 / g.DpiX);

  8.     SectionFormat currentSection = textControl1.Sections.GetItem().Format;

  9.     double widthZoom = 100 * textControl1.Width /
  10.         ((currentSection.PageSize.Width / iTwipsPerPixel) + iVisibleGap);

  11.     textControl1.ZoomFactor = (int)widthZoom;
  12. }
复制代码


Fit to page:
42.png

Fit to width:
41.png

源码下载:VS2010 + TX Text Control 17.0/X8
tx_view_modes.zip (12.12 KB, 下载次数: 404)

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部