Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共29 条记录, 每页显示 10 条, 页签: [1] [2][3]
[浏览完整版]

标题:怎么判断选中的是哪个lbl控件?

1楼
xxfoxtable 发表于:2023/10/8 20:31:00
Dim pb As WinForm.Panel = Forms("菜单").Controls("Panel1")
Dim width As Integer = pb.width
Dim height As Integer = pb.height
Dim wh As Integer = width \ 105

Dim n As Integer = Tables("桌台信息").Rows.Count

Dim lbl As WinForm.panel
Dim lbl1 As WinForm.Label
Dim p As WinForm.PictureBox
Dim s, t As Integer


For i As Integer = 0 To n - 1
    If i <> 0 Then
        If i Mod wh = 0 Then
            s = 0
            t = t + lbl.Height + 10
        Else
            s = s +115
        End If
    End If
    
    Dim r As Row = Tables("桌台信息").Rows(i)
    Dim nm As String = r("序号")
    Dim nm0 As String = r("桌台号")

    
    lbl = Forms("菜单").CreateControl(nm, ControlTypeEnum.Panel)
    lbl.name = nm
    lbl.BackColor = Color.lightgray
    lbl.Left = s
    lbl.Top = t
    lbl.Width = 105
    lbl.Height = 90
    Forms("菜单").Controls("panel1").AddControl(lbl)
    
    lbl1 = Forms("菜单").CreateControl(nm0, ControlTypeEnum.Label)
    lbl1.BackColor = Color.green
    lbl1.ForeColor = Color.White
    lbl1.Left = 0
    lbl1.Top = 0
    lbl1.Width = 105
    lbl1.Height = 20
    lbl1.Text = space(4) & nm0
    lbl.AddControl(lbl1)
    
    p = Forms("菜单").CreateControl(nm0, ControlTypeEnum.PictureBox)
    p.name = nm0
    p.Left = s
    p.Top = t + 20
    p.Width = 105
    p.Height = 70
    Forms("菜单").Controls("panel1").AddControl(p)
2楼
有点蓝 发表于:2023/10/8 20:34:00
panel、Label这些控件没有输入焦点,是无法选中的,也就无法判断是否选中
3楼
xxfoxtable 发表于:2023/10/8 20:38:00
If TypeOf e.sender Is WinForm.SplitContainer Then
Else
    Dim controlname As String
    If TypeOf e.sender Is WinForm.Panel Then
        controlname = e.sender.name
    ElseIf e.sender.parent IsNot Nothing Then
        If TypeOf e.sender.Parent Is WinForm.Panel Then
            controlname = e.sender.parent.name
        End If
    End If
    msgbox(controlname)
    Vars("序号") = controlname
    Dim n As Integer = Tables("桌台信息").Rows.Count
    For i As Integer = 0 To n - 1
        Dim r As Row = Tables("桌台信息").Rows(i)
        Forms("菜单").Controls(r("序号")).BorderStyle = BorderStyle.None
        Forms("菜单").Controls(r("序号")).BackColor = Color.Lightgray 
    Next
    
    Forms("菜单").Controls(controlname).BorderStyle = BorderStyle.FixedSingle
    Forms("菜单").Controls(controlname).BackColor = Color.Azure
    
End If


[此贴子已经被作者于2023/10/8 22:11:34编辑过]
4楼
xxfoxtable 发表于:2023/10/8 21:20:00
 lbl1 = Forms("菜单").CreateControl(nm0, ControlTypeEnum.Label)
    lbl1.BackColor = Color.green
    lbl1.ForeColor = Color.White
    lbl1.Left = 0
    lbl1.Top = 0
    lbl1.Width = 105
    lbl1.Height = 20
    lbl1.Text = space(4) & nm0
    lbl.AddControl(lbl1)
nm0怎么居中显示?
5楼
有点蓝 发表于:2023/10/8 21:20:00
If TypeOf e.sender Is WinForm.SplitContainer Then 如果是分区控件
Else
    Dim controlname As String
    If TypeOf e.sender Is WinForm.Panel Then 如果点击是panel
        controlname = e.sender.name 获取panel名称
    ElseIf e.sender.parent IsNot Nothing Then 如果当前点击的控件有父控件
        If TypeOf e.sender.Parent Is WinForm.Panel Then 如果父控件是panel
            controlname = e.sender.parent.name获取父控件名称
        End If
    End If
    msgbox(controlname)
    Vars("序号") = controlname
    Dim n As Integer = Tables("桌台信息").Rows.Count
    For i As Integer = 0 To n - 1遍历所有行设置对应控件的边框和颜色
        Dim r As Row = Tables("桌台信息").Rows(i)
        Forms("菜单").Controls(r("序号")).BorderStyle = BorderStyle.None
        Forms("菜单").Controls(r("序号")).BackColor = Color.Lightgray 
    Next
    设置对应panel控件的边框和颜色
    Forms("菜单").Controls(controlname).BorderStyle = BorderStyle.FixedSingle
    Forms("菜单").Controls(controlname).BackColor = Color.Azure
    
End If
6楼
xxfoxtable 发表于:2023/10/8 21:21:00
msgbox(controlname)现在的问题是出现全是panel1,非常疑惑
7楼
有点蓝 发表于:2023/10/8 21:44:00
说明点击的控件都是放到panel1里
8楼
xxfoxtable 发表于:2023/10/8 21:46:00
示列是能显示具体新增的 lbl 的name
9楼
有点蓝 发表于:2023/10/8 21:48:00
把p添加到lbl里,不要添加到panel1里
10楼
xxfoxtable 发表于:2023/10/8 21:50:00

 lbl1 = Forms("菜单").CreateControl(nm0, ControlTypeEnum.Label)
    lbl1.BackColor = Color.green
    lbl1.ForeColor = Color.White
    lbl1.Left = 0
    lbl1.Top = 0
    lbl1.Width = 105
    lbl1.Height = 20
    lbl1.Text = space(4) & nm0
    lbl.AddControl(lbl1)
nm0怎么居中显示? 好象with和字符length不一致,加四个空格比较接近中间,但名称有可能有长有短,加空格就不通用了

[此贴子已经被作者于2023/10/8 21:54:15编辑过]
共29 条记录, 每页显示 10 条, 页签: [1] [2][3]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .07031 s, 2 queries.