将 VB6 PictureBox 代码转换为 VB.Net
我正在 vb.net 中做项目,该项目已经在 vb6 中完成 我有文本框。我想将字体(样式、颜色、名称、大小)应用于选定的文本。 我能够做到这一点..&想要创建此文本框文本的位图,以便我可以创建 0,1,2,3 位数字的矩阵(如果文本颜色为红色,则为 1 位数字,green-2,orange-3)
以下代码是在 vb6 中完成的,但我没有得到vb.net 中的一些属性,例如 图片1.点 picture1.print(这里picture1是图片框) 这里 Led 是数组(数字 0 或 1 或 2 或 3 ) Converttodis 是将每个字母转换为数组的函数 代码如下
Private Sub CmdPreview_Click()
On Error Resume Next
Dim i
Picture1.Cls
lRow = 0
Lcol = 0
ReDim Led(Picture1.TextHeight(TxtMsg.Text), Picture1.TextWidth(TxtMsg.Text))
For i = 1 To Len(TxtMsg.Text)
TxtMsg.SelStart = i - 1
TxtMsg.SelLength = 1
Picture1.Font = TxtMsg.SelFontName
Picture1.FontSize = TxtMsg.SelFontSize
Picture1.FontBold = TxtMsg.SelBold
Picture1.FontItalic = TxtMsg.SelItalic
If Mid(TxtMsg.Text, i, 1) <> vbCr Then
Picture1.Print Mid(TxtMsg.Text, i, 1)
ConvertToDis i, TxtMsg.selcolor
ElseIf Mid(TxtMsg.Text, i, 2) = vbCrLf Then
i = i + 1
lRow = lRow + Picture1.TextHeight(Mid(TxtMsg.Text, i - 2, 1))
Lcol = 0
Else
Picture1.Print Mid(TxtMsg.Text, i, 1)
ConvertToDis i, TxtMsg.selcolor
End If
Next
End Sub
Public Function ConvertToDis(ByVal i As Long, ByVal col)
Dim CX, CY, f, f1, F2
Dim lsubrow, Lsubcol As Integer
lsubrow = lRow
Lsubcol = Lcol
For CY = 0 To Picture1.TextHeight(Mid(TxtMsg.Text, i, 1))
For CX = 0 To Picture1.TextWidth(Mid(TxtMsg.Text, i, 1))
If Picture1.Point(CX, CY) < vbWhite - 4300000 Then
If col = 255 Then
LedCol(lsubrow, Lsubcol) = 1
ElseIf col = 65280 Then
LedCol(lsubrow, Lsubcol) = 2
ElseIf col = 33023 Then
LedCol(lsubrow, Lsubcol) = 3
Else
LedCol(lsubrow, Lsubcol) = 0
End If
DoEvents
Lsubcol = Lsubcol + 1
Next
lsubrow = lsubrow + 1
Lsubcol = Lcol
Next
Picture1.Cls
Lcol = Lcol + Picture1.TextWidth(Mid(TxtMsg.Text, i, 1))
End Function
长字输出的
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000011111000000011111100001111101111000111110000000000
000001110000001111111110000111100111001111111100000000
000001110000001111000110000111100110011110001110000000
000001110000011111000011000111100110111110001000000000
000001110000011010000011000111100110110110000000000000
000001110000011010000011000111110110110111111110000000
000001110000011010000011000110110110110110001111000000
000001110000011010000011000110111110110111111110000000
000001110000011110000011000110011110111100001110000000
000001110000101110000111000110011110011100001110000000
000001110011100111001110000110001110011110001110000000
000011111111110011111100001111001110000111111110000000
000011111111110011111000011111001110000111111111000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000111111111111111111111111111111111111111111111110000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
I am doing project in vb.net which is already done in vb6
I am having text box .I want to apply font (style,color,name,size) to selected text.
I am able to do this ..& want to create bitmap of this textbox text so that i can create matrix of 0,1,2,3 digits if text color is red then 1 digit,green-2,orange-3
Following code is done in vb6 but i am not getting some properties in vb.net like
picture1.point
picture1.print (here picture1 is picture box)
here Led is array of (digits 0 or 1 or 2 or 3 )
converttodis is functiont that converts each letter into array
Code is here
Private Sub CmdPreview_Click()
On Error Resume Next
Dim i
Picture1.Cls
lRow = 0
Lcol = 0
ReDim Led(Picture1.TextHeight(TxtMsg.Text), Picture1.TextWidth(TxtMsg.Text))
For i = 1 To Len(TxtMsg.Text)
TxtMsg.SelStart = i - 1
TxtMsg.SelLength = 1
Picture1.Font = TxtMsg.SelFontName
Picture1.FontSize = TxtMsg.SelFontSize
Picture1.FontBold = TxtMsg.SelBold
Picture1.FontItalic = TxtMsg.SelItalic
If Mid(TxtMsg.Text, i, 1) <> vbCr Then
Picture1.Print Mid(TxtMsg.Text, i, 1)
ConvertToDis i, TxtMsg.selcolor
ElseIf Mid(TxtMsg.Text, i, 2) = vbCrLf Then
i = i + 1
lRow = lRow + Picture1.TextHeight(Mid(TxtMsg.Text, i - 2, 1))
Lcol = 0
Else
Picture1.Print Mid(TxtMsg.Text, i, 1)
ConvertToDis i, TxtMsg.selcolor
End If
Next
End Sub
Public Function ConvertToDis(ByVal i As Long, ByVal col)
Dim CX, CY, f, f1, F2
Dim lsubrow, Lsubcol As Integer
lsubrow = lRow
Lsubcol = Lcol
For CY = 0 To Picture1.TextHeight(Mid(TxtMsg.Text, i, 1))
For CX = 0 To Picture1.TextWidth(Mid(TxtMsg.Text, i, 1))
If Picture1.Point(CX, CY) < vbWhite - 4300000 Then
If col = 255 Then
LedCol(lsubrow, Lsubcol) = 1
ElseIf col = 65280 Then
LedCol(lsubrow, Lsubcol) = 2
ElseIf col = 33023 Then
LedCol(lsubrow, Lsubcol) = 3
Else
LedCol(lsubrow, Lsubcol) = 0
End If
DoEvents
Lsubcol = Lsubcol + 1
Next
lsubrow = lsubrow + 1
Lsubcol = Lcol
Next
Picture1.Cls
Lcol = Lcol + Picture1.TextWidth(Mid(TxtMsg.Text, i, 1))
End Function
for LONG word output is like this
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000011111000000011111100001111101111000111110000000000
000001110000001111111110000111100111001111111100000000
000001110000001111000110000111100110011110001110000000
000001110000011111000011000111100110111110001000000000
000001110000011010000011000111100110110110000000000000
000001110000011010000011000111110110110111111110000000
000001110000011010000011000110110110110110001111000000
000001110000011010000011000110111110110111111110000000
000001110000011110000011000110011110111100001110000000
000001110000101110000111000110011110011100001110000000
000001110011100111001110000110001110011110001110000000
000011111111110011111100001111001110000111111110000000
000011111111110011111000011111001110000111111111000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000111111111111111111111111111111111111111111111110000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自适用于 Visual Basic 6.0 用户的图形:
From Graphics for Visual Basic 6.0 Users: