Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, February 1, 2016 9:17 PM
Hi,
I have to modify a Work Item control buttons and text field so the background colors of those elements (buttons, textfield, textbox) automatically change as the Visual Studio theme is modified. For that i wanted to set the button background to ''Transparent''
I tried adding the following line in the control constructor:
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.Opaque, true);
I set the useVisualStypeBackColor property of the button to true and then false. FlatStype portety to standard and then system
Unfortunately wathever option a try to play with. the button background color is still always Grey.
Any help wull be greatly appreciated.
PS: I'm using visual studio 2013.
All replies (5)
Monday, February 1, 2016 10:45 PM âś…Answered
Hello,
Set FlatStyle = Popup and background color transparent. Also, from Microsoft.
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.Stack over flow profile. VB Forums - moderator
Tuesday, February 2, 2016 3:10 PM
Exactly what i wanted. Can't beleive i was that close. Thanks a lot. Please is there a similar workarround for the textboxes too?
Tuesday, February 2, 2016 3:18 PM
I would consider creating a custom TextBox e.g.
using System.Drawing;
using System.Windows.Forms;
namespace ForumQuestions
{
public class CustomTextBox : TextBox
{
public CustomTextBox()
{
SetStyle(ControlStyles.SupportsTransparentBackColor |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.ResizeRedraw |
ControlStyles.UserPaint, true);
BackColor = Color.Transparent;
}
}
}
Add the above to your project, build then look at the toolbox, it will reside at the top. Add it to your form.
If the above works for you I would create a class project, add the new text box into it. Build then add the compiled dll to the IDE toolbox for other projects to be able to use it.
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.Stack over flow profile. VB Forums - moderator
Tuesday, February 2, 2016 10:38 PM
Thanks Karen.
I tried your advice and i was indeed able to have a Transparent background for my custom textBox, but then I seems like I can`t change the foreColor. The customtextBox border and its content are truly invisible (not in password format).
I can see the textbox content only if I try to edit it and whatever color I select for the forecolor, the content will appear always in black
I can view the textbox border only if I select Fixed3D. FixedSingle show nothing.
PS: Native textboxes do not have this behaviour.
Thanks again for your availibility.
Tuesday, February 2, 2016 11:09 PM
I would suggest creating a new thread/question for more visibility on the TextBox question.
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.Stack over flow profile. VB Forums - moderator