在 TX Text Control 中实现 “Fit to page” 和“Fit to width”

发布时间:2012/11/16 00:11 发布者:葡萄城产品团队

返回博客中心

随着电脑硬件配置的不断提升,现在主流的显示器已经达到21-24寸,甚至更大的显示器。

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

TX Text Control 提供了一个 ZoomFactor 属性用于设置页面的缩放比例,下面的代码演示了如何将当前页全部显示在可见范围内:

 
private void FitToWindow()
{
    textControl1.PageUnit = MeasuringUnit.Twips;
    int iVisibleGap = 65;

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

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

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

    if (widthZoom < heightZoom)
        textControl1.ZoomFactor = (int)widthZoom;
    else
        textControl1.ZoomFactor = (int)heightZoom;
}

以下方法演示了如何让页面宽度达到可使用的最大宽度:

 
private void FitToWidth()
{
    textControl1.PageUnit = MeasuringUnit.Twips;
    int iVisibleGap = 200;

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

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

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

    textControl1.ZoomFactor = (int)widthZoom;
}



源码下载:VS2010 + TX Text Control 17.0/X8

tx_view_modes.zip (12.12 K, 下载次数:5)

关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网