WPF Application dotted effect to text in VB.NET

This tutorial shows you how you can give dotted effect to your text in WPF Application.
  • 2452

If you want to give dotted effect to your text then you can do so in WPF using the following code snippets.

Code for Dotted Effect

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:WpfApplication1.WpfApplication1.TextGeometryDemo" 
Title="TextGeometry Demo">
    <Window.Resources>
        <src:TextGeometry x:Key="txtASimpleText" Text="A Simple Text"
                 FontFamily="Times New Roman"
                 FontSize="100" FontWeight="Bold" />
        <src:TextGeometry x:Key="txtShadow" Text="Shadow"
                 FontFamily="Times New Roman"
                 FontSize="100" FontWeight="Bold" />
    </Window.Resources>
    <TabControl>
        <TabItem Header="Dotted Effect">
            <Path Stroke="blue" StrokeThickness="2.5"
                  StrokeDashArray="{Binding Source={x:Static DashStyles.Dot},Path=Dashes}"
                  StrokeDashCap="Round"
                  Data="{Binding Source={StaticResource txtASimpleText},Path=Geometry}" />
        </TabItem>
    </TabControl>
</
Window>

Code behind VB window

Imports System
Imports System.Globalization
Imports System.Windows
Imports System.Windows.Media
Namespace WpfApplication1.TextGeometryDemo
    Public Class TextGeometry
        Private txt As String = ""
        Private fntfam As New FontFamily()
        Private fntstyle As FontStyle = FontStyles.Normal
        Private fntwt As FontWeight = FontWeights.Normal
        Private fntstr As FontStretch = FontStretches.Normal
        Private emsize As Double = 24
        Private ptOrigin As New Point(0, 0)
         Public Property Text() As String
            Get
                Return txt
            End Get
            Set(ByVal value As String)
                txt = value
           End Set
        End Property
        Public Property FontFamily() As FontFamily
            Get
                Return fntfam
            End Get
            Set(ByVal value As FontFamily)
                fntfam = value
            End Set
       End Property
        Public Property FontStyle() As FontStyle
            Get
                Return fntstyle
            Set(ByVal value As FontStyle)
                fntstyle = value
            End Set
        End Property
        Public Property FontWeight() As FontWeight
            Get
                Return fntwt
            End Get
            Set(ByVal value As FontWeight)
                fntwt = value
            End Set
        End Property
        Public Property FontStretch() As FontStretch
            Get
                Return fntstr
            End Get
            Set(ByVal value As FontStretch)
                fntstr = value
            End Set
        End Property
        Public Property FontSize() As Double
            Get
                Return emsize
            End Get
            Set(ByVal value As Double)
                emsize = value
            End Set
        End Property
        Public Property Origin() As Point
            Get
                Return ptOrigin
            End Get
            Set(ByVal value As Point)
                ptOrigin = value
            End Set
        End Property
        Public ReadOnly Property Geometry() As Geometry
            Get
                Dim formtxt As New FormattedText(Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, New Typeface (FontFamily, FontStyle, FontWeight, FontStretch), FontSize, Brushes.Black)
                Return formtxt.BuildGeometry(Origin)
            End Get
        End Property
        Public ReadOnly Property PathGeometry() As PathGeometry
            Get
                Return PathGeometry.CreateFromGeometry(Geometry)
            End Get
        End Property
    End Class
End Namespace

Text with Dotted Effect

dottedtext.gif

I hope you will enjoy this.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.