我自己做了一个自定义控件,功能基本实现了,但无法自动刷新,比如我对m_LeftUpText 赋了新值,但它不会自动刷新,要等鼠标停在按钮上面的时候,才会刷新。有没有办法解决。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Keyboard
{
public partial class KeyButton : Button
{
#region Fileds
public string m_LeftUpText = “”;//左上角文本
public string m_LeftDownText = “”;//左下角文本
public string m_RightUpText = “”;//右上角文本
public string m_RightDownText = “”;//右下角文本
#endregion
#region Properties
[Category(“Appearance”)]
[Description(“左上角文本”)]
public string LeftUpText
{
get { return m_LeftUpText; }
set { m_LeftUpText = value;}
}
[Category(“Appearance”)]
[Description(“左下角文本”)]
public string LeftDownText
{
get { return m_LeftDownText; }
set { m_LeftDownText = value; }
}
[Category(“Appearance”)]
[Description(“右上角文本”)]
public string RightUpText
{
get { return m_RightUpText; }
set { m_RightUpText = value; }
}
[Category(“Appearance”)]
[Description(“右下角文本”)]
public string RightDownText
{
get { return m_RightDownText; }
set { m_RightDownText = value; }
}
#endregion
public KeyButton()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
using (SolidBrush drawBrush = new SolidBrush(base.ForeColor))
{
e.Graphics.DrawString(LeftUpText, base.Font, drawBrush, 2, 2);
e.Graphics.DrawString(LeftDownText, base.Font, drawBrush, 2, base.Height / 2);
}
using (SolidBrush drawBrush = new SolidBrush(Color.Blue))
{
e.Graphics.DrawString(RightUpText, base.Font, drawBrush, base.Width / 2, 2);
e.Graphics.DrawString(RightDownText, base.Font, drawBrush, base.Width / 2, base.Height / 2);
}
}
}
}