Create a Property for TextBox in C#.net [Resolved]

Posted by Naraayanan under C# on 1/31/2012 | Points: 10 | Views : 4064 | Status : [Member] | Replies : 5
Hi guys,
I create a User control. I am using Text Box in that User Control. Now I want to add a Property.Property name is called Level(Low,Medium,High).So User could change the Level at runtime .How can i achieve this?

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/



Responses

Posted by: Blessyjees on: 1/31/2012 [Member] Bronze | Points: 50

Up
0
Down

Resolved
Hi,

you can try this same way

Define public property in usercontrol class
public string Color

{
get;
set{
SetColor(value);
}
}
private void SetColor(string level)
{
switch(level.ToLower())
{
case "high":
textbox1.BackColor = System.Drawing.Color.Red;
break;
case "medium":
textbox1.BackColor = System.Drawing.Color.Green;
break;
case "low":
textbox1.BackColor = System.Drawing.Color.Yellow;
break;
}
}



Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Blessyjees on: 1/31/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Define a property in usercontrol page like

public string Level
{
get;
set{
// write code to set this property to textbox textbox1.text=value;
}
}
you can set the value of this property from where you place this usercontrol like control1.Level="high";

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 1/31/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Blessy,
Thanks for your reply.But I want like this.
For Ex: My Property Name Colors.
text Box background color is red when user select a option "High"
text Box background color is green when user select a option "Medium"
text Box background color is Yellow when user select a option "Low"



Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 2/1/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Thanks

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Blessyjees on: 2/1/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,

You helps this do not forget to mark this as "Mark As Answer".

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response