Changing form color depending on answer - c#

I have searched, and tried answers. I have the code, but I'm unsure why it isn't working. I am trying to change the backcolor of the form from green back to white. I believe I have it correct, but it doesn't show the first color, only the last.
if (PassBox1.Text == PassBox2.Text)
{
this.BackColor = Color.FromArgb(0, 255, 0);
// voice.Speak("Correct ", SpeechVoiceSpeakFlags.SVSFDefault);
this.BackColor = Color.FromArgb(192,192,192);
}

When this code runs and backcolor is set to (0,255,0) which is followed by a blocking operation voice.speak, this does not give chance to the ui to refresh and soon as voice speak is done, the backcolor changes to (192...) before ui gets changes to show the other color.
in this case you would be much happier if you created a subclassed text box which allows you to flash colors. you can use some ideas from this post
https://stackoverflow.com/a/4147406/2903863

Related

Weird grey background on checkbox

I am creating an application for a new RPG that I am creating. The application has a specific theme and I want to change the checkboxes and buttons to black and the cyan color I chose. On loading the form I use the following code to change the color of the boxes.
coloredCheckBoxes.Add(checkBox1);
coloredCheckBoxes.Add(checkBox2);
foreach (CheckBox checkBox in coloredCheckBoxes)
{
checkBox.FlatStyle = FlatStyle.Flat;
checkBox.FlatAppearance.BorderSize = 1;
checkBox.FlatAppearance.BorderColor = Color.FromArgb(0, 211, 211);
checkBox.FlatAppearance.CheckedBackColor = Color.Black;
checkBox.FlatAppearance.MouseOverBackColor = Color.Black;
checkBox.FlatAppearance.CheckedBackColor = Color.Black;
checkBox.BackColor = Color.Black;
}
No matter how many colors I change the back color of the check boxes still remain this weird grey color.
The check boxes also become lighter if I move my cursor over the boxes as if checkBox.FlatAppearance.MouseOverBackColor = Color.Black; was not used. Is there a way to fix this issue hopefuly without creating a custom checkbox class?
I understand what you need finally.(I remove any old answer)
Try this,
- MetroFramework UI - Original by Peter.
- MetroFramework UI - Forked, dennismagno(Recommand).
- MetroFramework UI - Forked, thielj.
Also provided source code, so you can modify it.

Unexpected transparency instead of white

I am working on a GUI , and it is showing Transparency for no reason in place of white color of the image itself , what might be the cause of this ?
Original GUI before executing application:
Upon Executing the Application:
To solve this issue, reset the TransparencyKey back to its default value, or remove the assignment:
this.TransparencyKey = Color.Empty;
instead of
this.TransparencyKey = Color.Transparent;
References: https://stackoverflow.com/a/13426429/1132334, and documentation:
When the TransparencyKey property is assigned a Color, the areas of the form that have the same BackColor will be displayed transparently

C# NET - Draw opaque brush on form with opacity level set

What I want to achieve is a semi-transparent background that covers the screen.
And then be able to draw non-transparent brushes on top of it.
What I have tried is to have a form with the size of the screen, then setting it's color and setting this.opacity = 0.5. However this affects all brushes in the form.
Ive also tried setting the background color to Color.Transparent, and then drawing an additional brush that covers the screen with opacity 0.5 before I then draw the opaque brushes... However the background becomes opaque as well.
Even though the style flag is set (ControlStyles.SupportsTransparentBackColor, true)
I know I can achieve this by having an additional form.
One form for the transparent background and one for the opaque foreground, but isn't that overkill?
Is there a better way?
Update 1:
Trying what is suggested in the comments.
Current state:
Form1: the main program, calls for the 'overlay' to show, which is:
Form2: Overlay background (semi-transparent black) and,
Form3: Overlay foreground, this is where the user draws.
Form 1 and 2 works as indended, however Form3 refuses to work with transparency.
If I set
this.BackColor = Color.Lime;
this.TransparencyKey = Color.Lime;
then the performance drops and the program lags heavily (although it does become transparent).
Ideally I would want to use this.BackColor = Color.Transparent; however that doesn't have any effect (solid background, no alpha).
Note that the form covers the screen and the background is usually the desktop. Maybe that's why it doesn't work?
You can override the OnPaintBackground of the form, without calling it's base.
This will enable you to specify whatever color you want for the background.
Try this:
protected override void OnPaintBackground(PaintEventArgs e)
{
using (var brush = new SolidBrush(Color.FromAgrb(50, 0, 0, 0))
{
e.Graphics.FillRectangle(brush, e.ClipRectangle);
}
}

WP8 Change the color behind the application bar

I am writing a WP8 app that overrides the color theme on the phone to always be white. Now before people discredit me for this decision, the app itself is supposed to be a messenger like application and the white background simply makes everything easier to read. In the future I do want to allow people to be able to choose between black or white in case battery life is important but I need to get over this hurdle first.
Currently the problem is that even after overriding the theme colors the color BEHIND the application bar still refuses to change. I'm not talking about the background color of the application bar but the rectangle drawn behind the application bar as it is animated to pop upwards from the bottom of the screen. It is very visible and it is quiet annoying even if it only appears for about a second.
I know there must be a way to do this as applications like Office, Google Mail and Skype all override the color theme and implement the white theme instead and they do not have this same problem.
If anyone could help that would be great!
I've found a solution but it's not a very nice one. If anyone finds a better solution please let me know.
I solved this problem by setting the application bar opacity to be near 1 but not 1 (I set it to 0.99). This will tell windows to not rescale the window (which is the cause of the black background).
I then set the bottom margin of that page to be the height of the application bar.
Here's the code for anyone interested:
private void panoramaMain_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Panorama p = (Panorama) sender;
if(p.SelectedIndex == 1) {
messageList.Margin = new Thickness(0, 0, 0, ApplicationBar.DefaultSize);
ApplicationBar.IsVisible = true;
} else {
messageList.Margin = new Thickness(0, 0, 0, 0);
ApplicationBar.IsVisible = false;
}
}

TransparencyKey Property on Forms

I would like to swith my form background transparency with Visual C# in a Windows Forms Application.
I used
BackColor = Color.White;
TransparencyKey = Color.White;
Now I want to switch back to "not transparent". How can I accomplish that? Just switching the BackColor makes the elements on the form look strange and it feels ugly.
I guess there is a way to reset the property.
this is the original value:
this.TransparencyKey = Color.Empty;
You could set this, and then nothing will be transparent.
How about storing the previous values of BackColor and TransparencyKey in local variables, and restoring them when you want to revert to non-transparent? For instance:
private Color _oldBG;
private Color _oldTPKey;
private void MakeTransparent() {
_oldBG = BackColor;
_oldTPKey = TransparencyKey;
BackColor = Color.White;
TransparencyKey = Color.White;
}
private void MakeNonTransparent() {
BackColor = _oldBG;
TransparencyKey = _oldTPKey;
}
It's eleven years later, but I ran into this problem. So for any other readers: I set the transparency key mistakenly. A post from another forum said you could right click it, at design, and then reset it, but reset was disabled (grayed out). So I simply backspaced out the 'White' (in design) that was set. (I am confident it set it to 'Color.Empty' as one of the guys here noted.) Problem solved. I should say that I was using an ancient version of .net. Hopefully this will also work in more up to date versions.

Categories

Resources