// 虚拟控件使用
private void Init()
{
UIButton button = new UIButton();
button.Size = new Size(70, 30);
button.Location = new Point(5, 15);
button.Text = “测试按钮”;
button.Click += (sender, e) => MessageBox.Show("按钮单击");
this.UIControls.Add(button);
}
// 虚拟控件重绘
protected override void RenderSelf(PaintEventArgs e)
{
Graphics g = e.Graphics;
Rectangle rect = RectangleEx.Subtract(this.ClientRectangle, this.Padding);
this.Sprite.BackColor = this.BackColor;
this.Sprite.Text = this.Text;
this.Sprite.TextRenderingHint = this.TextRenderingHint;
this.Sprite.TextAlign = this.TextAlign;
this.Sprite.BorderVisibleStyle = BorderVisibleStyle.None;
this.Sprite.State = this.State;
this.Sprite.BeginRender(g);
this.Sprite.RenderText(rect);
this.Sprite.EndRender();
}