永远不会调用OnPaint覆盖

编程入门 行业动态 更新时间:2024-10-19 21:34:45
本文介绍了永远不会调用OnPaint覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经待了几天,这让我发疯了.我有一个继承自System.Windows.Forms.Panel的控件,并且我试图覆盖OnPaint.只是简单而直接地忽略它.

I have been at this for a few days and it is driving me mad. I have a control that inherits from System.Windows.Forms.Panel and I'm trying to override OnPaint. It just plain, outright IGNORES it.

public class CollapsiblePanel : System.Windows.Forms.Panel { public CollapsiblePanel() { // // Required for the Windows Form Designer // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // SetStyle ( ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.Selectable , true ); } protected override void OnPaint(PaintEventArgs e) { // This never runs no matter what I try! base.OnPaint(e); } }

推荐答案

当我尝试覆盖OnPaint时,我只遇到一个ProgressBar的问题.它从未被调用.

I have the same problem just with a ProgressBar, when i try to override the OnPaint.. It's never called.

我在这里找到了解决方案: web.archive/web/20140214234801/osix/modules/article/?id=826

I found the solution here: web.archive/web/20140214234801/osix/modules/article/?id=826

您必须创建一个构造函数并启用用户绘画,如下所示:

You must create a constructor and enable user-painting like this:

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

默认值可能会因框架版本和操作系统而异.

Default values, probably vary depending on framework version and OS.

更多推荐

永远不会调用OnPaint覆盖

本文发布于:2023-11-26 20:53:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635153.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:永远不会   OnPaint

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!