将VB6 PictureBox代码转换为VB.Net

时间:2011-12-12 07:08:26

标签: vb.net vb6-migration

我在vb.net做的项目已在vb6中完成 我有文本框。我想将字体(样式,颜色,名称,大小)应用于所选文本。 我能做到这一点..&想要创建此文本框文本的位图,以便我可以创建0,1,2,3位的矩阵,如果文本颜色为红色,则为1位,绿色-2,橙色-3

以下代码是在vb6中完成的,但我没有在vb.net中获得某些属性 picture1.point 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

对于LONG字输出是这样的

000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000011111000000011111100001111101111000111110000000000
000001110000001111111110000111100111001111111100000000
000001110000001111000110000111100110011110001110000000
000001110000011111000011000111100110111110001000000000
000001110000011010000011000111100110110110000000000000
000001110000011010000011000111110110110111111110000000
000001110000011010000011000110110110110110001111000000
000001110000011010000011000110111110110111111110000000
000001110000011110000011000110011110111100001110000000
000001110000101110000111000110011110011100001110000000
000001110011100111001110000110001110011110001110000000
000011111111110011111100001111001110000111111110000000
000011111111110011111000011111001110000111111111000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000111111111111111111111111111111111111111111111110000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000

1 个答案:

答案 0 :(得分:0)

来自Graphics for Visual Basic 6.0 Users

  

在Visual Basic 2008中,Point方法不再存在。您可以使用System.Drawing.Bitmap.GetPixel(System.Int32,System.Int32)方法从位图中检索颜色值。对于不包含图片的表单或控件,您可以查询BackColor属性。

     

在Visual Basic 2008中,DrawString方法用于显示文本。字体由Font对象确定,颜色由Brush对象确定;两者都作为参数传递给DrawString方法。 DrawString方法还具有XY参数,用于确定文本的起始位置。还有一个可选的Format参数,它带有StringFormat个对象,允许您垂直显示文本。