|
-
Sep 19th, 2012, 08:00 AM
#12
New Member
Re: Add text to shapes !
I've achieved !!!
HEre is the code !
On RectangleShapes.Cs :
public override void Draw(System.Drawing.Graphics g)
{
using (var b = new SolidBrush(this.BackColor))
{
g.FillRectangle(b, this.Bounds);
g.DrawRectangle(Pens.Black, this.Bounds);
AfegirText(g,Texto );
}
}
private void AfegirText(System.Drawing.Graphics g,string s)
{
Font font2 = new Font("Calibri", 18, FontStyle.Bold, GraphicsUnit.Point);
g.DrawString(s, font2, Brushes.Black, this.Bounds);
}
On Shape.cs (add this property)
private string _Texto = String.Empty;
public string Texto
{
get { return _Texto; }
set
{
if (value.Trim() == String.Empty)
throw new ArgumentException("Texto cannot be empty.");
_Texto = value;
}
}
How to call it ?? Example, on the sample project :
private void AddShape(Shape s)
{
s.Texto = " sdf sd fsd fsdf sd fsfsdf";
canvas1.Shapes.Add(s);
canvas1.Invalidate();
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|