【发布时间】:2013-07-20 00:48:59
【问题描述】:
我正在开发这个自定义控件。 (我对这部分编程非常陌生。)我正在开发一个应用程序,当用户在我自己的自定义控件中输入输入时,它必须能够格式化数学表达式。这就是我希望控件的外观(此图像是在 Photoshop 中制作的):
我不会解释我希望它具有的行为,因为这对你没有帮助,但我的想法是它不基于任何 Windows 控件。
这是我已有的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Support.Components
{
public partial class PartialExpressionEditor : Control
{
public PartialExpressionEditor()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
Brush background = Brushes.White;
pe.Graphics.FillRectangle(background, ClientRectangle);
background.Dispose();
}
}
}
当我尝试将它放入我的表单时,我得到了这个错误对话框:
问题出在哪里?或者为什么会出现这个错误?
【问题讨论】:
-
你的类显示你的控件继承自
Control,但你为什么说it's not based on any Windows control? -
顺便说一句,您的代码对我来说似乎不错,除了我会使用
using(Brush background = Brushes.White){....}而不是像您那样直接调用Dispose()。您可以尝试删除Dispose()或至少尝试使用using样式吗? -
“它不基于任何 Windows 控件”,我的意思是它不是按钮、文本框或复选框等...
标签: c# winforms custom-controls