GDI+中启动双缓存后缩放失效的问题

在写一个小的C# Form测试程序时遇到一个奇怪的问题,情况是这样:在启动双缓存情况下,利用画布的PageScale属性实现缩放功能,发现并没有效果。

相关代码如下:

启动双缓存:

public Form1()
        {
            InitializeComponent();

            this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);

        }

实现缩放功能:

private void Form1_Paint(object sender, PaintEventArgs e)
        {

            // Create a rectangle.
            Rectangle rectangle1 = new Rectangle(20, 20, 50, 100);

            // Draw its outline.
            e.Graphics.DrawRectangle(Pens.SlateBlue, rectangle1);

            // Change the page scale. 
            e.Graphics.PageScale = 2.0F;

            // Call TranslateTransform to change the origin of the
            //  Graphics object.
            e.Graphics.TranslateTransform(10.0F, 10.0F);

            // Draw the rectangle again.
            e.Graphics.DrawRectangle(Pens.Tomato, rectangle1);

            // Set the page scale and origin back to their original values.
            e.Graphics.PageScale = 1.0F;
            e.Graphics.TranslateTransform(0.0F, 0.0F);

            SolidBrush transparentBrush = new SolidBrush(Color.FromArgb(50,
                Color.Yellow));

            // Create a new rectangle with the coordinates you expect
            // after setting PageScale and calling TranslateTransform:
            // x = 10 + (20 * 2)
            // y = 10 + (20 * 2)
            // Width = 50 * 2
            // Length = 100 * 2
            Rectangle newRectangle = new Rectangle(50, 50, 100, 200);

            // Fill in the rectangle with a semi-transparent color.
            e.Graphics.FillRectangle(transparentBrush, newRectangle);

        }

在网上搜索了相关问题,好像是这种使用方式存在问题,具体不详。

目前采用的解决方法是,将图形绘制的代码封装在相应的类中,至于之前的问题的原因尚不明白,有了解的大侠望指教!

转载于:https://www.cnblogs.com/lizichao/archive/2011/07/11/2103083.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值