- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在网站上看到了一些类似的问题,但没有一个真正对我有帮助。
我有一个函数,可以在单击按钮时在表单上绘制几条线,这些线的形状会根据用户在某些文本框中输入的值而变化。
我的问题是,当我最小化表单时,线条消失了,我知道这可以通过使用 OnPaint 事件来解决,但我真的不明白如何解决。
任何人都可以给我一个简单的示例,说明使用函数在使用 OnPaint 事件按下按钮时绘制内容吗?
最佳答案
Here you go , 简单的用户绘制控件的 MSDN 教程
您必须继承Button
类并重写OnPaint 方法。
代码示例:
protected override void OnPaint(PaintEventArgs pe)
{
// Call the OnPaint method of the base class.
base.OnPaint(pe);
// Declare and instantiate a new pen.
System.Drawing.Pen myPen = new System.Drawing.Pen(Color.Aqua);
// Draw an aqua rectangle in the rectangle represented by the control.
pe.Graphics.DrawRectangle(myPen, new Rectangle(this.Location,
this.Size));
}
编辑:
将属性添加到您的类中并喜欢 public Color MyFancyTextColor {get;set;}
并在您的 OnPaint
方法中使用它。并且它会出现在 visual studio 窗体设计器的控件属性编辑器中。
关于c# - 如何在 C# 中使用 OnPaint 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10076116/
我想知道在windows窗体程序中覆盖OnPaint时应该什么时候调用base.OnPaint? 我正在做的是: private void Form1_Paint(object sender, P
我有一个包含用户控件的 Windows 窗体。此用户控件具有以下代码: protected override void OnPaint(PaintEventArgs pe) { base.OnPa
我有一个包含用户控件的 Windows 窗体。此用户控件具有以下代码: protected override void OnPaint(PaintEventArgs pe) { base.OnPa
我正在尝试使用 FillPath 覆盖我自己的自定义控件中标签的 OnPaint 方法。 这是我的控件代码: public partial class GlassLabel : Label {
如果我重写 OnPaint 并在控件上绘制一个正方形,当我在设计器中预览它时,如何让 e.graphics.draw... 显示出来? 最佳答案 http://msdn.microsoft.com/e
我正在创建一个带有自定义边框的表单。我想使用 onPaint 重写来绘制自己的边框。不幸的是,当我只使用下面的代码时,我得到了图像的踪迹。 有人知道怎么解决吗?是的,我已将 DoubleBuffere
我在对话框中有一个图片控制框(CStatic)。当用户按下对话框中的按钮时,我需要 onPaint() 在其中绘制图像。问题是,图像是在对话框加载时绘制的。如何防止这种情况并仅在按下按钮时调用它。 我
我对 CFrameWnd 的 OnPaint 方法有问题,我似乎无法弄清楚发生了什么。 OnPaint 大约每 10 毫秒调用一次,这会导致计算机死机。检查 CPU 使用率,此应用占用 50%! 该应
我有一个 CWind 类的 child ,我在其中订阅 OnPaint 事件: BEGIN_MESSAGE_MAP(MyListBox, CWnd) ON_WM_PAINT() END_MES
我有一个 CWind 类的 child ,我在其中订阅 OnPaint 事件: BEGIN_MESSAGE_MAP(MyListBox, CWnd) ON_WM_PAINT() END_MES
我们有一个通常在 Windows XP 下运行的 .NET 2.0 软件(在 Windows“经典”模式下配置,没有附加功能)。现在,我在 Windows 7 上运行它的全部功能。我在 Windows
我正在尝试使命令模式适应具有撤消功能的简单绘图应用程序。我一直坚持使用 OnPaint 撤消操作事件。这是代码: [已解决] 帖子末尾的详细信息 interface ICommand { vo
大家好,我在编写自定义控件时遇到了问题。我的控件继承自 Windows.Forms.Control,我试图重写 OnPaint 方法。这个问题有点奇怪,因为只有当我在我的表单中包含一个控件时它才有效,
我有一个自定义绘画的用户控件。据我所知,构造函数正确设置样式。基本代码: public partial class LineChart2 : UserControl { public Line
我有以下自定义 Control: public class Line : Control { protected override void OnPaint(PaintEventArgs e)
我有一个 UserControl(WinForms,.net 2.0),我有这个: protected override void OnPaint(PaintEventArgs e) { ba
我正在尝试使用 winforms 和 gdi+ 实现一些动画,但我在控件中发现了很多撕裂的移动 Sprite 。 在托管 .net 中有没有办法让重写的 Control.OnPaint 方法等待监视器
在 WinForm 应用程序中,当订阅 OnPaint() 事件时,PaintEventArgs 提供一个 ClipRectangle 属性定义要绘制的区域。 当表单垂直或水平调整大小时,它会给出要绘
我有以下wx.Window: class SketchWindow(wx.Window): def __init__(self, parent): wx.Window.__init__(s
我有一个用 C++ 和 MFC 编写的基于对话框的应用程序。该对话框有一个 CStatic 图片控件。我在 PictureCtrl 的 OnPaint() 函数中绘制 BITMAP。相关代码如下: v
我是一名优秀的程序员,十分优秀!