WinForms draw a non transparent string into a transparent form - c#

I'm building an app in which I have to show a semitransparent form. I need to draw some text on that form too, to let the user know some info.
However, the strings I draw are also semitransparent and are difficult to read. I was wondering if there is a way to draw a non transparent string into a semitransparent form.
I'm using .NET 4.0, C# and WinForms technology.
For the moment I use the DrawString method on the Graphics form, but using a Label had no effect at all tho.
Browsing StackOverflow I found this How do I make my form transparent, but what I draw on it not? but it refers to WPF, and I'm using plain old WinForms.
Cheers.

This might help you - it will give you a fully transparent form with non-transparent text:
in InitializeComponent:
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
TransparencyKey = BackColor;
ShowInTaskbar = false;
FormBorderStyle = FormBorderStyle.None;
in OnPaint override:
g.DrawString(...) // Use some SolidBrush.
However, if you don't want fully transparent form (this won't sound nice but should work), then you can use TWO forms: One with semi transparent background, no text. Other one (on top of the previous one) with fully transparent background and non-transparent text. You can bind location, size and visibility of one form to another to keep them in synch.

Related

Weird text in RichTextBox c#

I need to do something like paint, the only differ, you can draw on screen. When user click on a tool (pen, line, rect, text etc.) I take screenshot of the screen and put it as background image for a second full screen form. Then by handling mouse events draw on it. Im trying to follow MS Paint and draw text using third form with a RichTextBox inside it. This form must be transparent, and after I'll take new screenshot and load as background of second form.
This is code for third form which is transparent.
this.FormBorderStyle = FormBorderStyle.None;
this.TransparencyKey = Color.Turquoise;
this.BackColor = Color.Turquoise;
richTextBox1.BackColor = this.BackColor;
As you can see, text is being light blue. This is my problem.
I did not find a way how to fix that, and I decided to use label instead. By handling key press event and making label back color transparent I got expected result.
enter image description here

UI with Transparent Background doesn't show the Next Immediate Layer

If we set the background of any UI as transparent, it doesn't show what's beneath that, meaning any UI or containers. Instead, it shows the default background of the Form, the lowermost, that is.
How do I get around this transparency problem?
This is by design, unfortunately:
http://support.microsoft.com/kb/943454
Transparent controls in WinForms are transparent relative to their
parent, not to other controls. Transparency in WinForms is more akin
to camouflage than true transparency. A transparent control doesn’t
actually let you see the control behind it through the form. It asks
its parent to draw its own background on the "transparent" control.
This is why a transparent control shows the form behind it, but covers
up any other controls.
There is some code in the link that demonstrates a work around.
Windows Forms controls do not support true transparency. The background of a transparent Windows Forms control is painted by its parent.
To give your control a transparent backcolor
This will enable your control to support a transparent backcolor.
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = Color.Transparent;

Transparent controls in .NET

I have a problem with:
BackColor = Color.Transparent;
It's not working correctly. I have a form with a blue background, and a picturebox with a picture loaded in it. It's not actually taking what's in the picture, but rather - the form's background color. Please tell me there's a simple way to go around this?
What you see in the following screenshot is a custom usercontrol with it's backColor set to transparent, on top of a picture, in a form with a blue background.
I need the usercontrol to display what's UNDER it, as real transparency, it should be showing the gradient and part of the image.
Try setting the picture box to be the parent of the custom user control.
myControl.Parent = this.myPictureBox;
Try calling "SetStyle(ControlStyles.SupportsTransparentBackColor, true);" on your user control constructor.
more details at: http://msdn.microsoft.com/en-us/library/wk5b13s4(v=vs.90).aspx

Form background color or image stuck as white

I started teaching myself C# a week ago. I started by writing Tetris to get myself acquainted with the language. I got the main game mechanics working by painting onto presized bitmap and displaying it in a picturebox, which at the time was the same size of the window. Now I have expanded the windows size and started adding other controls to the side of the picture box.
The problem is, now that I have expanded the window, displaying the form background, the background color is permanently white or I get a weird white to black faded look in the bottom corner.
I have tried several things:
- set the form backcolor manually, but it is only reflected on the labels
- checked that the transparencykey is empty
- set transparencykey to an unused color, nothing changes - added a bmp as the form's background image, still stays white - checked my code to see if I was every writing directly to the form background
I can't fingure out how to fix this; does anyone have any ideas?
EDIT: I found the answer to my question. SetStyle(ControlStyles.Opaque, true) was called in my constructor. I'm not sure what exactly that does, but I commented it out and it fixed my problem.
Please list out the requirements means exactly what you need?
After I read your question. The following are my understandings.
If your problem is with changing window size, then
make use of Split container, which is
available in toolbox from
'Containers' group.
set its Dock property to fill to
fill entire window if
resized/maximized.
Then use the right pane to contain your picture box and left pane for other controls.
If you require, you may also set dock property of picture box to fill to its parent container means right pane.
If your problem is with background color of the window, then
Actually Background color issue comes, If the form is an Mdi Container.
Check whether IsMdiContainer property is set to false. If true it is an MdiContainer.
The following code block sets Mdi Forms' backcolor to the forms' backcolor.
foreach (Control c in this.Controls)
{
if (c is MdiClient)
{
c.BackColor = this.BackColor;
}
}
I found the answer to my question. SetStyle(ControlStyles.Opaque, true) was called in my initialization. I'm not sure what exactly that does, but it was the cause of my background color issue.

Shadow to windows form

I am working in C# Windows Forms Application
I want to make shadow of my form, so I have taken a image having shadow and set it as Form's Background image and also set TransparentKey to Form's BackColor i.e. Control Color, so that it will transparent the area which contains Control color and FormBorderStyle to None.
My problem is that I am not getting the shadow transparent, it is of Control Color.
Updated: I also want to change shape of my form
I would use this technique instead; it worked beautifully for me.
Drop shadow in Winforms Controls?
Update:
Changing the shape of a form is easier than you'd think.
Follow this tutorial: http://www.codegod.de/WebAppCodeGod/creating-custom-shapes-for-forms-in-windows-forms-AID377.aspx

Categories

Resources