Answered by:
How to make the backColor in ToolStrip transparent

Question
-
Answers
-
My first post seems to be empty for some reason so, I will re-post it again...
The ToolStrip control supports Transparent BackColor already so, you can just set it's BackColor property to Color.Transparent. However that leaves the white colored Border still visible like the image Mr. Monkeyboy posted.
ToolStrip1.BackColor = Color.Transparent
If you want the whole ToolStrip to be Transparent, including the Border, you can create and use a ToolStripRenderer class to use for your ToolStrip. This will make the Border transparent too. However, you will then need to use the overidable methods of the renderer class to draw the highlight color of selected menu items. You may also need to handle drawing other parts of the menu/items depending on the types of items in your ToolTrip.
Here is a short example...
Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ToolStrip1.BackColor = Color.Transparent ToolStrip1.GripStyle = ToolStripGripStyle.Hidden ToolStrip1.Renderer = New MyRenderer End Sub End Class Public Class MyRenderer Inherits ToolStripRenderer Protected Overrides Sub OnRenderButtonBackground(e As ToolStripItemRenderEventArgs) MyBase.OnRenderButtonBackground(e) If e.Item.Selected Then e.Graphics.FillRectangle(Brushes.Red, 0, 0, e.Item.Bounds.Width, e.Item.Bounds.Height) End If End Sub Protected Overrides Sub OnRenderDropDownButtonBackground(e As ToolStripItemRenderEventArgs) MyBase.OnRenderDropDownButtonBackground(e) If e.Item.Selected Then e.Graphics.FillRectangle(Brushes.Red, 0, 0, e.Item.Bounds.Width, e.Item.Bounds.Height) End If End Sub Protected Overrides Sub OnRenderMenuItemBackground(e As ToolStripItemRenderEventArgs) MyBase.OnRenderMenuItemBackground(e) If e.Item.Selected Then e.Graphics.FillRectangle(Brushes.Red, 0, 0, e.Item.Bounds.Width, e.Item.Bounds.Height) End If End Sub End Class
Here is what the above example looks like...
If you say it can`t be done then i`ll try it
- Edited by IronRazerz Friday, June 1, 2018 12:43 AM
- Proposed as answer by Mr. Monkeyboy Friday, June 1, 2018 2:30 AM
- Marked as answer by jamilaid Saturday, June 2, 2018 1:20 AM
All replies
-
-
I suppose make a custom ToolStrip that supports transparent backcolor.
Remarks
The BackColor property does not support transparent colors unless the SupportsTransparentBackColor value of System.Windows.Forms.ControlStyles is set to true.
The BackColor property is an ambient property. An ambient property is a control property that, if not set, is retrieved from the parent control. For example, a Button will have the same BackColor as its parent Form by default. For more information about ambient properties, see the AmbientProperties class or the Control class overview.
Public Class ToolStripEX Inherits ToolStrip Public Sub New() MyBase.New() Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True) End Sub End Class
Below the Form has a background Image stretched and the ToolStripEX1 has its backcolor set to transparent. So create a Test project and add the class ToolStripEX to it. Build the project and the ToolStripEX control should appear at the top of the ToolBox and can be dragged onto the Form. Then use it like any ToolStrip. I don't know what "without background only text" means which may be different than a ToolStrip that supports transparent backcolor.
La vida loca
- Edited by Mr. Monkeyboy Thursday, May 31, 2018 10:39 PM
-
-
My first post seems to be empty for some reason so, I will re-post it again...
The ToolStrip control supports Transparent BackColor already so, you can just set it's BackColor property to Color.Transparent. However that leaves the white colored Border still visible like the image Mr. Monkeyboy posted.
ToolStrip1.BackColor = Color.Transparent
If you want the whole ToolStrip to be Transparent, including the Border, you can create and use a ToolStripRenderer class to use for your ToolStrip. This will make the Border transparent too. However, you will then need to use the overidable methods of the renderer class to draw the highlight color of selected menu items. You may also need to handle drawing other parts of the menu/items depending on the types of items in your ToolTrip.
Here is a short example...
Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ToolStrip1.BackColor = Color.Transparent ToolStrip1.GripStyle = ToolStripGripStyle.Hidden ToolStrip1.Renderer = New MyRenderer End Sub End Class Public Class MyRenderer Inherits ToolStripRenderer Protected Overrides Sub OnRenderButtonBackground(e As ToolStripItemRenderEventArgs) MyBase.OnRenderButtonBackground(e) If e.Item.Selected Then e.Graphics.FillRectangle(Brushes.Red, 0, 0, e.Item.Bounds.Width, e.Item.Bounds.Height) End If End Sub Protected Overrides Sub OnRenderDropDownButtonBackground(e As ToolStripItemRenderEventArgs) MyBase.OnRenderDropDownButtonBackground(e) If e.Item.Selected Then e.Graphics.FillRectangle(Brushes.Red, 0, 0, e.Item.Bounds.Width, e.Item.Bounds.Height) End If End Sub Protected Overrides Sub OnRenderMenuItemBackground(e As ToolStripItemRenderEventArgs) MyBase.OnRenderMenuItemBackground(e) If e.Item.Selected Then e.Graphics.FillRectangle(Brushes.Red, 0, 0, e.Item.Bounds.Width, e.Item.Bounds.Height) End If End Sub End Class
Here is what the above example looks like...
If you say it can`t be done then i`ll try it
- Edited by IronRazerz Friday, June 1, 2018 12:43 AM
- Proposed as answer by Mr. Monkeyboy Friday, June 1, 2018 2:30 AM
- Marked as answer by jamilaid Saturday, June 2, 2018 1:20 AM
-
-
-
-
-
-
I want it to work on the same code but not on the image I want to work on Mediaplayer
You should've asked the entire question originally rather than having people waste time on the original question which isn't what you wanted.
La vida loca
No I have benefited from the first answers
But that's another question
-
is there a solution
I am just guessing you want a ToolStrip over top of an AxWindowsMediaPlayer. If so, the answer is No, not that I am aware of without doing some crazy hack job.
If you say it can`t be done then i`ll try it
I do not think he can not ..but I think he can
- Edited by jamilaid Saturday, June 2, 2018 1:25 AM
-
is there a solution
I am just guessing you want a ToolStrip over top of an AxWindowsMediaPlayer. If so, the answer is No, not that I am aware of without doing some crazy hack job.
If you say it can`t be done then i`ll try it
I do not think he can not ..but I think he can
Jami,
Please show an image of what it is you want to achieve. Describe exactly what you mean.
Do you mean you want to make a transparent media player control tool strip? Or just put a background on a media player control?
You can most likely make your own media player control exactly how you like.
But we cant easily guess what it is you want.
- Edited by tommytwotrain Saturday, June 2, 2018 1:47 AM
-
is there a solution
I am just guessing you want a ToolStrip over top of an AxWindowsMediaPlayer. If so, the answer is No, not that I am aware of without doing some crazy hack job.
If you say it can`t be done then i`ll try it
I do not think he can not ..but I think he can
Jami,
Please show an image of what it is you want to achieve. Describe exactly what you mean.
Do you mean you want to make a transparent media player control tool strip? Or just put a background on a media player control?
You can most likely make your own media player control exactly how you like.
But we cant easily guess what it is you want.
Do you see this picture?
If you replaced it with the AxWindowsMediaPlayer
I want the code to work the same way with AxWindowsMediaPlayer
-
I want the code to work the same way with AxWindowsMediaPlayer
For OS >= Windows 8, you can create layered child controls (WS_EX_LAYERED), but it is not very standard to do that on WMP...
For example, a layered "Play/Stop" Button as child of WMP on Windows 10 :