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
Related
I am generating the graph at runtime using zedgraph control. The graph is generated but the line color of zedgraph control changes as the background color. I want to set the same color that was set at design time. How to set fix color to line? I am using the code to give color as :
refLine = gp.AddCurve("", null, null, Color.Green , SymbolType.None);
at the load event of form. But it gets changed automatically.
You have:
refLine = gp.AddCurve("", null, null, Color.Green , SymbolType.None);
Which returns a LineItem. There are at least two different color properties. Above you set the LineItem.Color property. Try after to set this :
refLine.Line.Fill.Color = Color.Green;
zgc.Refresh(); //not sure if needed
Can't remember what the LineItem.Color property is, but it may be a fill color for other views than line chart, for example bar or candlestick charts.
Also, due to the complexity of Zedgraph, be sure to use good documentation.
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
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);
}
}
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.
Is it possible to change the background color (white by default) of a zedgraph pane?
I tried changing the background color of the zedgraph element, but it doesn't give any visible result, background is still white:
ZedGraphControl.BackColor = System.Drawing.Color.Black;
And there doesn't seem to exist a Color or BackColor property on ZedGraphControl.GraphPane.
myChart.GraphPane.Chart.Fill.Color = System.Drawing.Color.Black;
You can use
zg.GraphPane.Chart.Fill.Color = SystemColors.ControlText;
to change the background [only] of the chart.
If you want to change the background color the zedgraph except the chart, use
zg.GraphPane.Fill.Color = SystemColors.ControlText;
If you want to change the background color of everything in the zedgraph, use both:
zg.GraphPane.Chart.Fill.Color = SystemColors.ControlText;
zg.GraphPane.Fill.Color = SystemColors.ControlText;
EDIT: I know that you already solved your problem but I made this so if someone searches it, he can solve his problem quickly :)
myChart.GraphPane.Fill.Color = System.Drawing.Color.Black; will create a gradient fill started with black color. If you don't want to use gradient you should use -
myChart.GraphPane.Chart.Fill.Brush = new System.Drawing.SolidBrush(Color.Black);
Hope this will solve your problem.