using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace WindowsControlLibrary1
{
public class UserControl1 : System.Windows.Forms.UserControl
{
private System.ComponentModel.Container components = null;
private string MyText;
private EventHandler OnMyTextChanged;
public UserControl1()
{
InitializeComponent();
MyText = "Static Control";
OnMyTextChanged = null;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
private void InitializeComponent()
{
this.Name = "UserControl1";
this.Size = new System.Drawing.Size(248, 128);
this.Load += new System.EventHandler(this.UserControl1_Load);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.UserControl1_Paint);
}
#endregion
private void UserControl1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
SizeF textSize = e.Graphics.MeasureString(MyText, Font);
float xPos = (ClientRectangle.Width / 2) - (textSize.Width / 2);
float yPos = (ClientRectangle.Height / 2) - (textSize.Height / 2);
e.Graphics.DrawString(MyText, Font, new SolidBrush(Color.Black), xPos, yPos);
}
private void UserControl1_Load(object sender, System.EventArgs e)
{
}
public String ControlText
{
get
{
return MyText;
}
set
{
MyText = value;
Invalidate();
if (OnMyTextChanged != null)
{
OnMyTextChanged.Invoke(this, EventArgs.Empty);
}
}
}
public event EventHandler MyTextChanged
{
add
{
OnMyTextChanged += value;
}
remove
{
OnMyTextChanged = value;
}
}
}
}