TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Gustavo
NA
1.3k
454k
How do I: remove/replace redundant code
Mar 10 2010 2:03 PM
Hello:
I have many forms that have the same code that I would like to put in one place and access it from all the forms. An example of the code is listed below:
public
void
textBox_Enter(
object
sender,
EventArgs
e)
{
((
TextBox
)sender).BackColor =
Color
.Ivory;
toolStripStatusLabelHint.Text =
"Hint: "
+ ((
TextBox
)sender).Name;
//... and more code here
}
How can I put this in one place and then have a one line code to have it include the statements?
Also I have this code that I would need to put in one place.
InitializeComponent();
//------------------------------------------------------------
string
d =
""
;
string
e =
""
;
Control
c = GetNextControl(
null
,
true
);
while
(c !=
null
)
{
if
(c.GetType().Name ==
"TextBox"
)
{
c.Enter +=
new
EventHandler
(textBox_Enter);
c.Leave +=
new
EventHandler
(textBox_Leave);
}
c = GetNextControl(c,
true
);
}
//------------------------------------------------------------
.....
Reply
Answers (
3
)
C# treeview and Text
Inserting datetime in a rich text box