draw string in user control


hi dears . make user control code . button want draw string on under text of button . don't know how implement . please me .

public partial class pbutton : system.windows.forms.button { /// <summary> /// summary description cutebutton. /// </summary> private string m_text = ""; private color m_color1 = color.lightgreen; // first color private color m_color2 = color.darkblue; // second color private int m_color1transparent = 64; // transparency degree // (applies 1st color) private int m_color2transparent = 64; // transparency degree // (applies 2nd color) public color cutecolor1 { { return m_color1; } set { m_color1 = value; invalidate(); } } public color cutecolor2 { { return m_color2; } set { m_color2 = value; invalidate(); } } public int cutetransparent1 { { return m_color1transparent; } set { m_color1transparent = value; invalidate(); } } public int cutetransparent2 { { return m_color2transparent; } set { m_color2transparent = value; invalidate(); } } public string commenttext { { return m_text; } set { m_text = value; invalidate(); } } public pbutton() { initializecomponent(); } protected override void onpaint(painteventargs pe) { string = this.text; base.onpaint(pe); // this.text = ""; this.font=new font(this.font,fontstyle.bold); color c1 = color.fromargb (m_color1transparent, m_color1); color c2 = color.fromargb (m_color2transparent, m_color2); brush b = new system.drawing.drawing2d.lineargradientbrush (clientrectangle, c1, c2, 10); pe.graphics.fillrectangle(b, clientrectangle); stringformat format = new stringformat(); format.alignment = stringalignment.center; format.linealignment = stringalignment.center; rectangle rect = new rectangle(0, 0, this.width/16, this.height+15); pe.graphics.drawstring(m_text,new font("tahoma",8,fontstyle.regular), new solidbrush(this.forecolor),rect, format); } }


 

hi,

assing m_text value like:

m_text = "123"

and change second last line of code :

rectangle

rect = new rectangle(0, 0, this.width -1, this.height -1);try now!


please mark answer/helpful if find useful. thanks, satya prakash jugran



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'