最近在看些條形碼方面相關的資料,而如果只是看的話,效果似乎並不怎麼好,所以決定動手做點Demo,以增強對相關知識的記憶。
這裡是一個我編寫的使用WPF生成Code 39的例子,Code 39的編碼很簡單,故而第一次先用它做為嘗試。
標准的Code 39只支持43個字符,0~9,A~Z,-,.,$, /, +, %以及空格。除此之外,*用於起始和終止符號。而通過使用兩個編碼符的擴展,則可以支持所有的Acsii碼字符。相關知識可以在維基百科上找到。
由於是WPF,Demo分為兩個文件,xaml文件包含界面布局相關的代碼:
<Window x:Class="Code39Demo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBox Name="Textbox1" VerticalContentAlignment="Center" TextChanged="Textbox1_TextChanged"></TextBox>
<Canvas Name="Canvas1" Grid.Row="1"></Canvas>
</Grid>
</Window>
本欄目