gpt4 book ai didi

c# - 使用透明度时 Windows 应用程序非常慢

转载 作者:行者123 更新时间:2023-11-30 19:22:20 25 4
gpt4 key购买 nike

我正在 visual studio .net 2005 中使用 C# 编写 Windows 应用程序。

在窗体中,有一些背景透明的控件;表单以最大化和全屏背景打开。

应用程序运行速度非常慢,CPU 使用率很高。

这是为什么?

最佳答案

<强>1。使用属性 DoubleBuffered 的解决方案

旁注:只有当您有权访问控件时才有效,因为 DoubleBuffered 是 Control 的 protected 属性。与解决方案 2 类似(请参阅后面的代码)。

// from within the control class
this.DoubleBuffered = true;

// from the designer, in case you are utilizing images
control.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;

System.Windows.Forms.Control.DoubleBuffered System.Windows.Forms.Control.BackgroundImageLayout

<强>2。使用 SetStyle + OptimizedDoubleBuffer 的替代解决方案:

旁注:控件绘制自身,窗口消息 WM_ERASEBKGND 被忽略以减少闪烁,控件首先绘制到缓冲区而不是直接绘制到屏幕。

control.SetStyle(UserPaint | AllPaintingInWmPaint | OptimizedDoubleBuffer, true);

System.Windows.Forms.Control.SetStyle(ControlStyles, Boolean) System.Windows.Forms.Control.ControlStyles

<强>3。使用 SetStyle + DoubleBuffer 的替代解决方案:

旁注:与 OptimizedDoubleBuffer 类似,由于遗留原因,它保留在代码库中。

control.SetStyle(UserPaint | AllPaintingInWmPaint | OptimizedDoubleBuffer, true);

System.Windows.Forms.Control.SetStyle(ControlStyles, Boolean) System.Windows.Forms.Control.ControlStyles

关于c# - 使用透明度时 Windows 应用程序非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1366253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com