将 VB6 PictureBox 代码转换为 VB.Net

发布于 2024-12-21 02:21:30 字数 3191 浏览 1 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叶落知秋 2024-12-28 02:21:30

来自适用于 Visual Basic 6.0 用户的图形

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

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

From Graphics for Visual Basic 6.0 Users:

In Visual Basic 2008, the Point method no longer exists. You can use the System.Drawing.Bitmap.GetPixel(System.Int32,System.Int32) method to retrieve a color value from a bitmap. For forms or controls that do not contain a picture, you can query the BackColor property.

In Visual Basic 2008, the DrawString method is used to display text. The font is determined by a Font object, and the color is determined by a Brush object; both are passed as parameters to the DrawString method. The DrawString method also has X and Y parameters that determine the starting location for the text. There is also an optional Format parameter that takes a StringFormat object, allowing you to display text vertically.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文