none
How to make the backColor in ToolStrip transparent RRS feed

  • Question

  • I tried but did not succeed

    Please help me

    I want a transparent backColor like in Label


    • Edited by jamilaid Thursday, May 31, 2018 9:08 PM
    Thursday, May 31, 2018 9:06 PM

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
    Friday, June 1, 2018 12:38 AM

All replies

  • Or without background only text
    Thursday, May 31, 2018 9:14 PM
  • I suppose make a custom ToolStrip that supports transparent backcolor.

    ToolStrip.BackColor Property

    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

    Thursday, May 31, 2018 10:01 PM

  • If you say it can`t be done then i`ll try it

    Thursday, May 31, 2018 11:52 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
    Friday, June 1, 2018 12:38 AM
  •  Yes exactly but

    I tried it with the Media player and it did not work





    • Edited by jamilaid Friday, June 1, 2018 4:48 AM
    Friday, June 1, 2018 3:59 AM
  • I want it to work on the same code but not on the image I want to work on  Mediaplayer
    • Edited by jamilaid Friday, June 1, 2018 5:07 AM
    Friday, June 1, 2018 5:06 AM
  • is there a solution
    Friday, June 1, 2018 6:16 PM
  • 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

    Friday, June 1, 2018 7:39 PM
  • 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

    Saturday, June 2, 2018 12:11 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

    Saturday, June 2, 2018 1:11 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
    In a way or another

    • Edited by jamilaid Saturday, June 2, 2018 1:25 AM
    Saturday, June 2, 2018 1:23 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
    In a way or another

    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.


    Saturday, June 2, 2018 1:34 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
    In a way or another

    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

    Saturday, June 2, 2018 3:35 AM
  • 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 :

    Saturday, June 2, 2018 2:08 PM