|
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace WTest
{
/// <summary>
/// Summary description for Canvas.
/// </summary>
public class Canvas : System.Windows.Forms.UserControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private string _text = "Sample Text";
private int _angle = 0;
public Canvas()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.UserPaint, true);
UpdateStyles();
}
public override string Text
{
get
{
return _text;
}
set
{
_text = value;
Invalidate();
}
}
public int Angle
{
get
{
return _angle;
}
set
{
_angle = value;
Invalidate();
}
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Canvas
//
this.BackColor = System.Drawing.SystemColors.Window;
this.Name = "Canvas";
this.Size = new System.Drawing.Size(224, 128);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Canvas_Paint);
}
#endregion
private void Canvas_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Point ptCenter = new Point (ClientRectangle.Width / 2, ClientRectangle.Height / 2);
StringFormat format = new StringFormat(StringFormatFlags.NoClip);
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
e.Graphics.TranslateTransform (ptCenter.X, ptCenter.Y);
e.Graphics.RotateTransform (-_angle);
e.Graphics.DrawString(_text, this.Font, Brushes.Black, 0, 0, format);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.