Monday, April 22, 2013

how to create usercontrol with user defined properties in asp.net

In previous posts i have given examples on how to convert string to data table in asp.net,Gridview Examples,Add colums dynamically to gridview.Her i will show how to develop a scrolling label control with text,color,font  properties using csharp.The timers are used to get the time inteval of process
Place label control
Place Timer Control with enabled =true
Place one more timer with enabled =false

Code fro timer_TickEvent(--)
{
lblname.Top=lblname.Top-5;
if(lblname.Top<0)
{
Timer1.Enable=false;
Timer2.Enable=True;
}
}
Code for time2_tick event(...)
{
lblname.Top=lblname.Top+5;
if(lblname.Top>250)
{
Timer1.Enable=false;
Timer2.Enable=True;
}
}
//Code in General Declaration
//create properties
Publlic string Ltext
{
set {lblname.Text=value;}
get{return lblname.Texte;}
}

Publlic string Lbcolor
{
set {lblname.BackColor=value;}
get{return lblname.BackColor;}
}

Publlic string Lfont
{
set {lblname.Font=value;}
get{return lblname.Font;}

}
Publlic int Lspeed
{
set {timer1.interval=value;
timer1.interval=value;
}
get{return timer1.Interval;}

}
Build the project
note:Scrolling lable.dll is created under d:\myprojects\scrolling label \bin\debug folder
Open page and drag scrolling.dll into my controls tab of toolbox.Then user control slable has been added to tool box

No comments:

Bel