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
Joe Wilson
NA
7.8k
437.3k
How can I solve the problem in my code in C#?
Oct 8 2016 1:44 PM
Hi,
I mean I want to make a windows form in C# like below:
this is my form
color:
color number (0 - 255)
(for example if all of the color number get 0 except green the text will be green and the contrast color (red) will be background color)
Note: the green and blue and red that were shown below are labels and the numbers in front of labels are text box which can be changed and the text which is green is a text box which must have contrast color with the background color .
For example:
green
255
blue
0
Text
red
0
this is the code below:
private void Red_TextChanged(object sender, EventArgs e)
{
int red, green, blue = 0;
if (Red.Text == string.Empty) red = 0; else red = Int32.Parse(Red.Text);
if (Green.Text == string.Empty) green = 0; else green = Int32.Parse(Green.Text);
if (Blue.Text == string.Empty) blue = 0; else blue = Int32.Parse(Blue.Text);
System.Drawing.Color fontColor= Color.FromArgb(red, green, blue);
Message.ForeColor = Color.FromArgb(red, green, blue);
System.Drawing.Color bgColor = Color.FromArgb(fontColor.ToArgb() ^ 0xffffff);
this.BackColor= bgColor;
}
private void Blue_TextChanged(object sender, EventArgs e)
{
int red, green, blue = 0;
if (Red.Text == string.Empty) red = 0; else red = Int32.Parse(Red.Text);
if (Green.Text == string.Empty) green = 0; else green = Int32.Parse(Green.Text);
if (Blue.Text == string.Empty) blue = 0; else blue = Int32.Parse(Blue.Text);
System.Drawing.Color fontColor = Color.FromArgb(red, green, blue);
Message.ForeColor = Color.FromArgb(red, green, blue);
System.Drawing.Color bgColor = Color.FromArgb(fontColor.ToArgb() ^ 0xffffff);
this.BackColor = bgColor;
}
private void Green_TextChanged(object sender, EventArgs e)
{
int red, green, blue = 0;
if (Red.Text == string.Empty) red = 0; else red = Int32.Parse(Red.Text);
if (Green.Text == string.Empty) green = 0; else green = Int32.Parse(Green.Text);
if (Blue.Text == string.Empty) blue = 0; else blue = Int32.Parse(Blue.Text);
System.Drawing.Color fontColor = Color.FromArgb(red, green, blue);
Message.ForeColor = Color.FromArgb(red, green, blue);
System.Drawing.Color bgColor = Color.FromArgb(fontColor.ToArgb() ^ 0xffffff);
this.BackColor = bgColor;
}
green,blue and red are 3 text boxes with respective names and there is a 4th text box named 'randomText' which contains some particular text whose color should change based on other 3 text boxes .
If(green.Text != "0" && blue.Text=="0" && red.Text=="0")
{
randomText.ForeColor=Color.Green; //make sure you have System.Drawing assembly reference
Form1.BackColor=Color.Red; // Form1 is your form's name
}
The problem is this:
the codes which I mentioned by red gives me errors and I don't know how to solve them.
Reply
Answers (
3
)
how to change date format?
How to Encrypt scanning images inside folder?