加入一个CommonDialog控件,一个TextBox控件,一个PictureBox控件,两个CommandButton控件。
代码如下:
'声明API函数BitBlt
Private Declare Function BitBlt Lib "gdi32" ()
(ByValhDestDC As Long,ByValx As Long,ByValy As Long,ByValnWidth As Long,ByVal nHeight As Long,ByVal hSrcDC As Long,ByVal xSrc As Long,ByValySrc As Long,ByValdwRop As Long)'As Long
'初始化
Private Sub Form_Load()
TextBox1.Top = 0 : TextBox1.Left = 0
TextBox1.MaxLength = 2 : TextBox1.BorderStyle = 0
End Sub
'修改字体
Private Sub Command1_Click()
'设置“取消”为True
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
'设置Flags属性
CommonDialog1.Flags = cdlCFEffects Or cdlCFBoth
'显示“字体”对话框
CommonDialog1.ShowFont()
TextBox1.Font.Name = CommonDialog1.FontName
TextBox1.Font.Size = CommonDialog1.FontSize
TextBox1.Font.Bold = CommonDialog1.FontBold
TextBox1.Font.Italic = CommonDialog1.FontItalic
PictureBox1.Font.Size = CommonDialog1.FontSize
TextBox1.Width=2*PictureBox1.TextWidth(TextBox1.Text)TextBox1.Height=PictureBox1.TextHeight(TextBox1.Text)
Exit Sub
ErrHandler:
'用户按了“取消”按钮
Exit SubEnd Sub
'生成字模
Private Sub Command2_Click()
Dim Wp() As Byte
ReDim Wp(PictureBox1.TextWidth(TextBox1.Text)*
PictureBox1.TextWidth(TextBox1.Text))As Byte
Dim Nbyte, Q(7) As Integer
Dim Cy, Cx As Integer
Dim Dot As Integer
Dim Z As Long
Dot = 0 : Nbyte = 0
BrightV = 16000000
Z=BitBlt(PictureBox1.hDC,0,0,300,300,Form1.hDC,1,1,&HCC0020)PictureBox1.Refresh
For Cy=PictureBox1.TextHeight(TextBox1.Text)To 0 Step-1For Cx=PictureBox1.TextWidth(TextBox1.Text)To 0 Step-1
Z = PictureBox1.Point(Cx, Cy)
'得到该点的颜色信息
If Z < BrightV Then
Q(Dot) = 1 '该点为黑
Else
Q(Dot) = 0 '该点为白
End If
If Dot = 7 Then
'将8个点的信息存入一个字节中
Wp(Nbyte) = Q(7) * 128 + Q(6) * 64 + Q(5) * 32 + Q(4) * 16 + Q(3) * 8 + Q(2) * 4 + Q(1) * 2 + Q(0) * 1
Nbyte = Nbyte + 1
End If
Dot = Dot + 1
If Dot = 8 Then Dot = 0
Next Cx
Next CyEnd Sub
麻烦各位兄弟,我不太会VB.NET,帮我转换一下,谢谢!
[此贴子已经被作者于2006-9-1 9:18:34编辑过]