weixin_58317284 2021-07-12 12:58 采纳率: 0%
浏览 73

System.Windows.Forms.Control.Tag.get 返回 Nothing‘’

加任何一个控件都显示
System.Windows.Forms.Control.Tag.get 返回 Nothing。。请问该如何处理。
代码如下
Public Class Form1
Dim x As Single = 0
Dim y As Single = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    '获取当前窗体尺寸
    x = Me.Width
    y = Me.Height
    SetTag(Me)
    Dim s As Screen
    s = Screen.PrimaryScreen
    Me.Size = New Size(s.Bounds.Width, s.Bounds.Height)
    Me.Top = s.Bounds.Height / 2 - Me.Height / 2
    Me.Left = s.Bounds.Width / 2 - Me.Width / 2

End Sub

#Region "窗体"
Private Sub SetTag(ByVal obj As Object)
For Each con As Control In obj.Controls
con.Tag = con.Width & ":" & con.Height & ":" & con.Left & ":" & con.Top & ":" & con.Font.Size
If con.Controls.Count > 0 Then
SetTag(con)
End If
Next
End Sub
Private Sub SetControls(ByVal newx As Single, ByVal newy As Single, ByVal obj As Object)
For Each con As Control In obj.Controls
con.AutoSize = False
Dim mytag() As String = con.Tag.ToString.Split(":")
con.Width = mytag(0) * newx
con.Height = mytag(1) * newy
con.Left = mytag(2) * newx
con.Top = mytag(3) * newy
Dim currentSize As Single = (mytag(1) * newy * mytag(4)) / mytag(1)
con.Font = New Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit)
If con.Controls.Count > 0 Then
SetControls(newx, newy, con)
End If
Next
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
Dim newx As Single = Me.Width / x
Dim newy As Single = Me.Height / y
SetControls(newx, newy, Me)
End Sub
#End Region

End Class

  • 写回答

1条回答 默认 最新

  • 浪客 2024-01-31 16:21
    关注

    先判断下con.Tag.是否为空,然后再Split

    评论

报告相同问题?

问题事件

  • 创建了问题 7月12日

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。