以文本方式查看主题
- Foxtable(狐表) (http://foxtable.net/bbs/index.asp)
-- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2)
---- [求助]用代码实现的SplitContainer中,其他控件为什么看不见 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=11391)
|
-- 作者:涛声依旧5666
-- 发布时间:2011/7/20 14:53:00
-- [求助]用代码实现的SplitContainer中,其他控件为什么看不见
想用代码创建SplitContainer,并在panel1,panel2中分别放其他的控件,代码执行后,添加进去的控件看不见,不知为什么?
Dim split As WinForm.SplitContainer Dim pnl As WinForm.Panel Dim tbl As WinForm.Table Dim but As WinForm.Button
With e.form \' 创建split分隔 split = e.Form.CreateControl("split1", ControlTypeEnum.splitcontainer) split.Dock = Windows.Forms.DockStyle.Fill split.Orientation = windows.Forms.Orientation.horizontal split.splitterdistance =900 split.splitterwidth = 4 e.form.addcontrol(split)
\'创建panel工具栏 pnl = e.Form.CreateControl("pnl1", ControlTypeEnum.panel) pnl.SetBounds(200, 0, 400,40) pnl.Topmost = True pnl.backcolor= Color.FromARGB(187,0,10,203) split.panel1.AddControl(pnl)
\'创建按钮 but = e.Form.CreateControl("butadd", ControlTypeEnum.button) split.Panel1.AddControl(but)
End With
|
-- 作者:涛声依旧5666
-- 发布时间:2011/7/20 14:55:00
--
并且, split.splitterdistance =900好像不起作用,初始分隔条处在100个像素的位置。?
|
-- 作者:擎天柱
-- 发布时间:2011/7/20 16:13:00
--
说句实在话,我一开始就在学习和研究这个SplitContainer,我觉得这个还是有点小小的问题。我在学习中发现2个问题:
当在SplitContainer中嵌入多个SplitContainer或其他容器类控件,将内置控件锚定设置为top,bottom,left,right,保存后,再打开设计窗口,控件的尺寸发生变化,不是最初设计的尺寸,每次进入窗口设计都要重新设置控件尺寸,很烦,这个好像以前有提过。还有,当窗体被拉伸时,个别控件的移动距离比例好像也是不是期望的,导致控件间的距离发生变化。
还有,有时候,在窗体设计下拉菜单中选中某个控件,但实际上这个控件并没有呈现出被选中的状态:没有框线。
记得以前有版主提过并提供一个其他软件的例子,窗体设计下,控件管理采用树形菜单,这样可以很方便控件管理,至少容易看出哪个控件在哪个容器里。目前通过下拉菜单来查看管理控件感觉有点弱。
|
-- 作者:狐狸爸爸
-- 发布时间:2011/7/20 16:25:00
--
解决两个问题,panel还是看不见,原因待查:
Dim split As WinForm.SplitContainer Dim pnl As WinForm.Panel Dim tbl As WinForm.Table Dim but As WinForm.Button
With e.form \' 创建split分隔 split = e.Form.CreateControl("split1", ControlTypeEnum.splitcontainer) split.Dock = Windows.Forms.DockStyle.Fill split.Orientation = windows.Forms.Orientation.horizontal split.splitterwidth = 4 e.form.addcontrol(split) split.SplitterDistance = 500
\'创建panel工具栏 pnl = e.Form.CreateControl("pnl1", ControlTypeEnum.panel) pnl.SetBounds(200, 0, 400,40) pnl.Topmost = True pnl.backcolor= Color.FromARGB(187,0,10,203) split.panel1.AddControl(pnl)
\'创建按钮 but = e.Form.CreateControl("butadd", ControlTypeEnum.button) split.Panel1.AddControl(but) but.TopMost = True End With
|
-- 作者:涛声依旧5666
-- 发布时间:2011/7/21 9:29:00
--
上述问题存在普遍性,即用代码动态创建一个容器类控件,再用代码动态创建其他控件并将这些控件添加到容器控件,就出现容器内的控件s不可见。非常郁闷
|
-- 作者:程兴刚
-- 发布时间:2011/7/21 9:56:00
--
Dim split As WinForm.SplitContainer Dim pnl As WinForm.Panel Dim tbl As WinForm.Table Dim but As WinForm.Button
With e.form \' 创建split分隔 split = e.Form.CreateControl("split1", ControlTypeEnum.splitcontainer) split.Dock = Windows.Forms.DockStyle.Fill split.Orientation = windows.Forms.Orientation.horizontal split.splitterwidth = 4 e.form.addcontrol(split) split.SplitterDistance = 500
\'创建panel工具栏 pnl = e.Form.CreateControl("pnl1", ControlTypeEnum.panel) pnl.SetBounds(200, 0, 400,40) pnl.Topmost = True pnl.backcolor= Color.FromARGB(187,0,10,203) split.Panel1.AddControl(pnl)
\'创建按钮 but = e.Form.CreateControl("butadd", ControlTypeEnum.button) split.Panel1.AddControl(but) but.TopMost = True End With
我理解错了!
[此贴子已经被作者于2011-7-21 10:17:55编辑过]
|
-- 作者:狐狸爸爸
-- 发布时间:2011/7/21 10:14:00
--
搞定:
Dim split As WinForm.SplitContainer Dim pnl As WinForm.Panel Dim tbl As WinForm.Table Dim but As WinForm.Button
With e.form \' 创建split分隔 split = e.Form.CreateControl("split1", ControlTypeEnum.splitcontainer) split.Dock = Windows.Forms.DockStyle.Fill split.Orientation = windows.Forms.Orientation.horizontal split.splitterwidth = 4 e.form.addcontrol(split) split.splitterdistance =900 \'创建panel工具栏 pnl = e.Form.CreateControl("pnl1", ControlTypeEnum.panel) pnl.SetBounds(0, 0, 400,400) split.panel1.AddControl(pnl) pnl.Topmost = True pnl.backcolor= Color.FromARGB(187,0,10,203) but = e.Form.CreateControl("butadd", ControlTypeEnum.button) split.Panel1.AddControl(but) but.TopMost = True End With
|
-- 作者:程兴刚
-- 发布时间:2011/7/21 10:22:00
--
明白了,先添加控件后指定置顶和可见属性,可我记得原来是可以先指定相关属性的!
|
-- 作者:涛声依旧5666
-- 发布时间:2011/7/21 12:48:00
--
但是,狐狸爸爸的做法,是将button添加到了panel1中啦,而原本是要添加到panel1中的panel里的。
|
-- 作者:狐狸爸爸
-- 发布时间:2011/7/21 14:59:00
--
这样一样可以的:
Dim split As WinForm.SplitContainer Dim pnl As WinForm.Panel Dim tbl As WinForm.Table Dim but As WinForm.Button
With e.form \' 创建split分隔 split = e.Form.CreateControl("split1", ControlTypeEnum.splitcontainer) split.Dock = Windows.Forms.DockStyle.Fill split.Orientation = windows.Forms.Orientation.horizontal split.splitterwidth = 4 e.form.addcontrol(split) split.splitterdistance =900 \'创建panel工具栏 pnl = e.Form.CreateControl("pnl1", ControlTypeEnum.panel) pnl.SetBounds(0, 0, 400,400) split.panel1.AddControl(pnl) pnl.Topmost = True pnl.backcolor= Color.FromARGB(187,0,10,203) but = e.Form.CreateControl("butadd", ControlTypeEnum.button) pnl.AddControl(but) but.TopMost = True End With
|