以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 怎么判断选中的是哪个lbl控件? (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=188645) |
-- 作者:xxfoxtable -- 发布时间:2023/10/8 20:31:00 -- 怎么判断选中的是哪个lbl控件? 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)
|
-- 作者:有点蓝 -- 发布时间:2023/10/8 20:34:00 -- panel、Label这些控件没有输入焦点,是无法选中的,也就无法判断是否选中 |
-- 作者: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编辑过]
|
-- 作者: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怎么居中显示?
|
-- 作者:有点蓝 -- 发布时间: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
|
-- 作者:xxfoxtable -- 发布时间:2023/10/8 21:21:00 -- msgbox(controlname)现在的问题是出现全是panel1,非常疑惑 |
-- 作者:有点蓝 -- 发布时间:2023/10/8 21:44:00 -- 说明点击的控件都是放到panel1里 |
-- 作者:xxfoxtable -- 发布时间:2023/10/8 21:46:00 -- 示列是能显示具体新增的 lbl 的name |
-- 作者:有点蓝 -- 发布时间:2023/10/8 21:48:00 -- 把p添加到lbl里,不要添加到panel1里 |
-- 作者: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编辑过]
|