vb.net 启用多线程_严格启用选项的VB.NET标签阵列变得容易

vb.net 启用多线程

在网上浏览时,很少有人能够使用对象数组来运行VB.net 2008/2010。

我觉得是时候把我从网络上获取的一切回馈给其他用户了。

VB6有一个简单的对象数组系统,该系统已在VB.net中丢失

作为C#/ C ++程序员,我喜欢dot.net,但认为“基本”应该是基本的!

我使用VB.net进行快速的Visual开发,并喜欢它的简便性,您可以回到代码中重新阅读它。

确定,您需要一个标签作为数组,且选项严格打开。

此演示在面板上放置了64个8x8标签,并在您单击它时改变了颜色。

打开一个新窗体,然后将Panel1放置在600x400的窗体上

将标签放在面板的左上角。 (位置15,12)

我称之为“ Lbl_Master”,设置为false,Autosize false,TextAlign MiddleCenter,

背景色石灰,文本01和大小40,30

这可以简化阵列开始位置和其他视觉属性。

在窗体上放置一个按钮(Button1)。

希望这对您所有的VB编码人员有所帮助。

问候戴夫

输入Form1的此代码为................。

Option Strict On
Imports System.Drawing 
Public Class Form1
Public Lbl_Array As Label() = New Label(64) {} ' Set the number you labels need 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Demo places 8 x 8 (64) lables on form
Dim CNT As Integer
Dim X As Integer
Dim Y As Integer
Dim H As Integer
Dim W As Integer
Dim r, c As Integer  
Y = Lbl_Master.Location.Y
H = Lbl_Master.Height
W = Lbl_Master.Width 
CNT = 1 
For c = 1 To 8
  X = Lbl_Master.Location.X
  For r = 1 To 8 
    Lbl_Array(CNT) = New Label
    Lbl_Array(CNT).Location = New System.Drawing.Point(X, Y)
    Lbl_Array(CNT).Size = New System.Drawing.Size(W, H)
    Lbl_Array(CNT).AutoSize = Lbl_Master.AutoSize
    Lbl_Array(CNT).BackColor = Lbl_Master.BackColor
    Lbl_Array(CNT).BorderStyle = Lbl_Master.BorderStyle
    Lbl_Array(CNT).TextAlign = Lbl_Master.TextAlign
    Lbl_Array(CNT).ForeColor = Lbl_Master.ForeColor
    Lbl_Array(CNT).Font = Lbl_Master.Font
    Lbl_Array(CNT).Text = CStr(CNT)
    Lbl_Array(CNT).Tag = CNT ' This is the clever bit so that we can find the index!
    Lbl_Array(CNT).Visible = True
    Lbl_Array(CNT).BringToFront()
    AddHandler Lbl_Array(CNT).Click, AddressOf lblArray_click
    Panel1.Controls.Add(Lbl_Array(CNT))
    X = (X + W) + 8 ' Note 8 is your offset in X
    CNT += 1
  Next
  Y = (Y + H) + 8 ' Note 8 is your offset in Y 
Next
End Sub 
'This is the Event handler for a click on the Array Label
Private Sub lblArray_click(ByVal sender As Object, ByVal e As EventArgs)
' fixed late binding with option strict on!! 
' Just trick the compiler with these two lines
Dim Lbl_tmp As Label = CType(sender, Label)
Dim i As Integer = CInt(Lbl_tmp.Tag)
  Lbl_Array(i).BackColor = Color.Aqua ' change back color to show we clicked on it 
End Sub:
End Class

翻译自: https://bytes.com/topic/visual-basic/insights/900984-vb-net-label-arrays-option-strict-made-easy

vb.net 启用多线程

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值