1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| <DllImport("gdi32")> _
Public Shared Function AddFontResource(ByVal lpFileName As String) As Integer
End Function
<DllImport("user32.dll")> _
Public Shared Function SendMessage(ByVal hWnd As Integer, ByVal Msg As UInteger, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function
<DllImport("kernel32.dll", SetLastError:=True)> _
Shared Function WriteProfileString(ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Integer
End Function
Private Sub txbCode_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txbCode.TextChanged
Dim codeBar, codeClair, ret
If txbCode.Text <> "" Then
'MsgBox("Bonjour")
codeClair = txbCode.Text & New String("0", EANLen - Len(txbCode.Text))
codeBar = IIf(EANLen = 7, EAN8(codeClair), EAN13(codeClair))
lblCodeBar.Text = codeBar
Const WM_FONTCHANGE As Integer = &H1D
Const HWND_BROADCAST As Integer = &HFFFF
If File.Exists("C:\Windows\Fonts\code128.ttf") Then
'MsgBox("police installée: OK !")
Else
'MsgBox("police doit être installée copiée dans " & Environment.GetFolderPath(Environment.SpecialFolder.System))
Try
FileCopy("C:\temp\code128.ttf", Environment.GetFolderPath(Environment.SpecialFolder.System) & "\code128.ttf")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
ret = AddFontResource(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\code128.ttf")
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0)
WriteProfileString("fonts", "code 128", Environment.GetFolderPath(Environment.SpecialFolder.System) & "\code128.ttf")
End If
lblDessinCode.Font = New Font("Code EAN13", 48, FontStyle.Regular)
lblDessinCode.Text = codeBar
End If
End Sub |
Partager