locked
How to make Tool Strip have a glass effect? RRS feed

  • Question

  • How to make Tool Strip have a glass effect? Please Help Me As Fast As Possible . Thx . Note : Please write as details as Possible because I am new to vb.
    Sunday, January 4, 2015 7:02 AM

Answers

  • If by chance you are doing this on a form that has a background image and you want a transparent looking ToolStrip you can do this.

    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ToolStrip1.BackColor = Color.Transparent
        End Sub
    
        Private Sub ToolStrip1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles ToolStrip1.Paint
            Using sb As New SolidBrush(Color.FromArgb(100, Color.White))
                e.Graphics.FillRectangle(sb, 0, 0, ToolStrip1.Width, ToolStrip1.Height)
            End Using
        End Sub
    End Class

     

     You could also get a little fancy and draw a Gradient color in the Paint event to give it a better look.

    Imports System.Drawing.Drawing2D
    
    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ToolStrip1.BackColor = Color.Transparent
        End Sub
    
        Private Sub ToolStrip1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles ToolStrip1.Paint
            Dim sc As Color = Color.FromArgb(100, Color.White)
            Dim ec As Color = Color.FromArgb(100, Color.Blue)
            Using gb As New LinearGradientBrush(Point.Empty, New Point(0, Me.Height), sc, ec)
                Dim cb As New ColorBlend
                cb.Colors = New Color() {sc, ec, ec, sc}
                cb.Positions = New Single() {0.0F, 0.1F, 0.9F, 1.0F}
                gb.InterpolationColors = cb
    
                e.Graphics.FillRectangle(gb, 0, 0, ToolStrip1.Width, ToolStrip1.Height)
            End Using
        End Sub
    End Class


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

    • Edited by IronRazerz Sunday, January 4, 2015 2:34 PM
    • Proposed as answer by tommytwotrain Monday, January 5, 2015 4:05 AM
    • Marked as answer by Ryan Tan Tan Monday, January 5, 2015 4:48 AM
    Sunday, January 4, 2015 2:24 PM
  • Details are usually comments in code to explain how particular code works.

    Since you're new to VB you should search using the MSDN Library search engine to search for things you need to know or learn about them in other ways also The New Boston videos as I have no idea what you know or do not know therefore I would not know how in depth details would have to be for you to understand what is going on.

    People that assist in these forums do not work for Microsoft and are not required to provide details. The expectation is that someone asking a question would be programming at a level they are asking a question about. Which of course is invariably not true.

    If you want to draw your ToolStrip within the Forms TitleBar so that it appears to have the TitleBars glass effect that may be possible. I would guess the forms aero glass would have to be extended to provide room to draw the ToolStrip in perhaps. But since you're new I'm not certain what you really want. As you may not understand the difference between transparency and Aero Glass effect.

    Option Strict On
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2)))
            Me.BackgroundImageLayout = ImageLayout.Stretch
            Me.BackgroundImage = Image.FromFile("C:\Users\John\Documents\Visual Studio 2012\Drawing on Desktop - Like roll playing game\Worldmap2.png")
            ToolStrip1.BackColor = Color.Transparent
        End Sub
    
        Private Sub ToolStrip1_Paint(sender As Object, e As PaintEventArgs) Handles ToolStrip1.Paint
            Using Brush1 As New SolidBrush(Color.FromArgb(85, Color.Black))
                e.Graphics.FillRectangle(Brush1, ToolStrip1.ClientRectangle)
            End Using
        End Sub
    
    End Class


    La vida loca

    • Marked as answer by Ryan Tan Tan Monday, January 5, 2015 4:49 AM
    Sunday, January 4, 2015 8:48 PM
  • Wow the ToolStrip2.BackColor = Color.Transparent works for everything. Here I set the form transparent as well.

        
    • Marked as answer by Ryan Tan Tan Monday, January 5, 2015 4:49 AM
    Monday, January 5, 2015 4:05 AM

All replies

  • How to make Tool Strip have a glass effect? Please Help Me As Fast As Possible . Thx . Note : Please write as details as Possible because I am new to vb.

    Aero Glass Effect VB.NET

    Windows Forms - Aero Controls


    La vida loca


    Sunday, January 4, 2015 7:41 AM
  • Edit: Here are two ways.

    Public Class Form5
        Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.BackgroundImage = Image.FromFile("c:\bitmaps\rusty.jpg")
            Me.TransparencyKey = Color.Black
            Me.BackColor = Color.Black
            'Panel1.Dock = DockStyle.Top
    
            'background fill toolstrips
            Using bmp1 = New Bitmap(Panel1.ClientSize.Width, Panel1.ClientSize.Height)
                Using g1 = Graphics.FromImage(bmp1)
                    g1.FillRectangle(New SolidBrush(Color.Red), 0, 0, bmp1.Width, bmp1.Height)
    
                    bmp1.MakeTransparent(Color.Red)
    
                    Panel1.BackgroundImage = bmp1.Clone
                    ToolStrip1.BackgroundImage = bmp1.Clone
                    ToolStrip2.BackgroundImage = bmp1.Clone
                End Using
            End Using
        End Sub
    End Class


    Sunday, January 4, 2015 1:22 PM
  • If by chance you are doing this on a form that has a background image and you want a transparent looking ToolStrip you can do this.

    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ToolStrip1.BackColor = Color.Transparent
        End Sub
    
        Private Sub ToolStrip1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles ToolStrip1.Paint
            Using sb As New SolidBrush(Color.FromArgb(100, Color.White))
                e.Graphics.FillRectangle(sb, 0, 0, ToolStrip1.Width, ToolStrip1.Height)
            End Using
        End Sub
    End Class

     

     You could also get a little fancy and draw a Gradient color in the Paint event to give it a better look.

    Imports System.Drawing.Drawing2D
    
    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ToolStrip1.BackColor = Color.Transparent
        End Sub
    
        Private Sub ToolStrip1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles ToolStrip1.Paint
            Dim sc As Color = Color.FromArgb(100, Color.White)
            Dim ec As Color = Color.FromArgb(100, Color.Blue)
            Using gb As New LinearGradientBrush(Point.Empty, New Point(0, Me.Height), sc, ec)
                Dim cb As New ColorBlend
                cb.Colors = New Color() {sc, ec, ec, sc}
                cb.Positions = New Single() {0.0F, 0.1F, 0.9F, 1.0F}
                gb.InterpolationColors = cb
    
                e.Graphics.FillRectangle(gb, 0, 0, ToolStrip1.Width, ToolStrip1.Height)
            End Using
        End Sub
    End Class


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

    • Edited by IronRazerz Sunday, January 4, 2015 2:34 PM
    • Proposed as answer by tommytwotrain Monday, January 5, 2015 4:05 AM
    • Marked as answer by Ryan Tan Tan Monday, January 5, 2015 4:48 AM
    Sunday, January 4, 2015 2:24 PM
  • Ah ha, you said "Graidiant" fancy pants.

    :)

    Sunday, January 4, 2015 2:28 PM
  • Ah ha, you said "Graidiant" fancy pants.

    :)


     You got me again, dang-it!!  8)

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

    Sunday, January 4, 2015 2:35 PM
  • Please refrain from creating duplicate post, from now on all secondary post will be promptly removed leaving the original post. Since this is a warning I am going to delete the original this time and not this one,

    Also do not post in bold.

     

    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.

    Sunday, January 4, 2015 2:41 PM
  • Ah ha, you said "Graidiant" fancy pants.

    :)


     You got me again, dang-it!!  8)

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


    Well the ToolStrip1.BackColor = Color.Transparent is a new one for me, thanks.   

    Funny how it does not go through the form when form is transparent ie when used with my example without the transparent bitmap. but when the image bitmap has a transparent color assigned, again like my example, it does go through the form backgroundimage when the form is set to a transparent color. Hope that makes sense.

    Sunday, January 4, 2015 2:53 PM
  • Details are usually comments in code to explain how particular code works.

    Since you're new to VB you should search using the MSDN Library search engine to search for things you need to know or learn about them in other ways also The New Boston videos as I have no idea what you know or do not know therefore I would not know how in depth details would have to be for you to understand what is going on.

    People that assist in these forums do not work for Microsoft and are not required to provide details. The expectation is that someone asking a question would be programming at a level they are asking a question about. Which of course is invariably not true.

    If you want to draw your ToolStrip within the Forms TitleBar so that it appears to have the TitleBars glass effect that may be possible. I would guess the forms aero glass would have to be extended to provide room to draw the ToolStrip in perhaps. But since you're new I'm not certain what you really want. As you may not understand the difference between transparency and Aero Glass effect.

    Option Strict On
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2)))
            Me.BackgroundImageLayout = ImageLayout.Stretch
            Me.BackgroundImage = Image.FromFile("C:\Users\John\Documents\Visual Studio 2012\Drawing on Desktop - Like roll playing game\Worldmap2.png")
            ToolStrip1.BackColor = Color.Transparent
        End Sub
    
        Private Sub ToolStrip1_Paint(sender As Object, e As PaintEventArgs) Handles ToolStrip1.Paint
            Using Brush1 As New SolidBrush(Color.FromArgb(85, Color.Black))
                e.Graphics.FillRectangle(Brush1, ToolStrip1.ClientRectangle)
            End Using
        End Sub
    
    End Class


    La vida loca

    • Marked as answer by Ryan Tan Tan Monday, January 5, 2015 4:49 AM
    Sunday, January 4, 2015 8:48 PM
  • Ah ha, you said "Graidiant" fancy pants.

    :)

    LOL.

    "Well the ToolStrip1.BackColor = Color.Transparent is a new one for me, thanks."

    @IronRazerz - Me too!


    La vida loca

    Sunday, January 4, 2015 8:50 PM
  • Wow the ToolStrip2.BackColor = Color.Transparent works for everything. Here I set the form transparent as well.

        
    • Marked as answer by Ryan Tan Tan Monday, January 5, 2015 4:49 AM
    Monday, January 5, 2015 4:05 AM
  • Thx Bro, u are the hero
    Monday, January 5, 2015 4:47 AM
  • Another possibility extending the Aero Glass effect.

    ToolStrip backcolor has to be transparent.

    Option Strict On
    
    Imports System.Runtime.InteropServices
    
    Public Class Form1
    
        <StructLayout(LayoutKind.Sequential)> _
        Public Structure MARGINS
            Public cxLeftWidth As Integer
            ' width of left border that retains its size 
            Public cxRightWidth As Integer
            ' width of right border that retains its size 
            Public cyTopHeight As Integer
            ' height of top border that retains its size 
            Public cyBottomHeight As Integer
            ' height of bottom border that retains its size
        End Structure
    
    
        <DllImport("DwmApi.dll")> _
        Public Shared Function DwmExtendFrameIntoClientArea(hwnd As IntPtr, ByRef pMarInset As MARGINS) As Integer
        End Function
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2)))
            Me.TransparencyKey = Color.Silver
            Me.BackColor = Color.Silver
    
            Dim BordersWidth As Integer = CInt((Me.Width - Me.ClientRectangle.Width) / 2)
    
            ToolStrip1.BackColor = Color.Transparent
    
            Try
                Dim margins As New MARGINS()
                margins.cxLeftWidth = BordersWidth
                margins.cxRightWidth = BordersWidth
                margins.cyTopHeight = ToolStrip1.Height
                margins.cyBottomHeight = BordersWidth
    
                DwmExtendFrameIntoClientArea(Me.Handle, margins)
            Catch ex As Exception
            End Try
        End Sub
    
        Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
            Me.Refresh()
        End Sub
    
        Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
            Using Brush1 As New SolidBrush(SystemColors.Control)
                e.Graphics.FillRectangle(Brush1, Me.ClientRectangle.Left, Me.ClientRectangle.Top + ToolStrip1.Height, Me.ClientRectangle.Width, Me.ClientRectangle.Height)
            End Using
        End Sub
    
    End Class
    


    La vida loca

    Monday, January 12, 2015 12:51 AM
  • Another good one Monkey!

    Monday, January 12, 2015 9:39 AM