S
H
A
R
E

Sunday, May 29, 2011

Draw Text On Glass Window in VB.net

Text On Glass Window
When you make a glasses window, and you drop a label to the form designer, you will see that the label is not good. to fix this problem, you can use this way (sample code):



Imports System.Runtime.InteropServices
Imports System.Drawing.Drawing2D

Public Class Form1
    Private Sub Form1_Paint() Handles Me.Paint
        Dim g As Graphics = Me.CreateGraphics
        Dim tx As New GraphicsPath

        'Set black to get nice transparent
        Me.BackColor = Color.Black
        'Set this form transparent
        DwmExtendFrameIntoClientArea(Me.Handle, New MARGINS(-1, -1, -1, -1))

        'begin draw text
        tx.AddString("Klampok Child", New FontFamily("Tahoma"), FontStyle.Regular, 30,
                     New Point(12, 12), StringFormat.GenericDefault)
        ' Set Smoothing Mode to get smooth text
        g.SmoothingMode = SmoothingMode.AntiAlias
        'Fill form with text and color (brush)
        g.FillPath(New SolidBrush(Color.Black), tx)

    End Sub

    Private Sub Form1_ResizeEnd() Handles Me.ResizeEnd
        ' When form resize, re-draw the form and show it smooth again
        Me.Refresh()
    End Sub
    ' DwmApi To Call Glasses Window
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure MARGINS
        Public LeftWidth As Integer
        Public RightWidth As Integer
        Public TopHeight As Integer
        Public Buttomheight As Integer
        Public Sub New(ByVal left As Integer, ByVal right As Integer, ByVal top As Integer, ByVal bottom As Integer)
            LeftWidth = left
            RightWidth = right
            TopHeight = top
            Buttomheight = bottom
        End Sub
    End Structure
    <DllImport("dwmapi.dll")> _
    Shared Sub DwmExtendFrameIntoClientArea(ByVal hwnd As IntPtr, ByRef mrg As MARGINS)
    End Sub
End Class

1 comments:

Double Glazing Oxford said...

Impressive! If you prefer more light to pass through, choose clear textured glass or subtle designs made with lighter colors.

Post a Comment