以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]锚定的内部函数 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=179513) |
-- 作者:2425004926 -- 发布时间:2022/8/27 13:40:00 -- [求助]锚定的内部函数 老师,我动态增加控件,如果是在下方,或者右方,是要锚定的,我想写一个锚定的内部函数 比如Args(1)的值是“left|Bottom",我写下面的内部函数不行,应该怎么写? Dim sz() As Object = Args(1).Split("|")
Dim e = Args(0) If sz.Length = 2 Then Args(0).Form.Controls("").Anchor = CType(System.Windows.Forms.AnchorStyles.sz(0) Or System.Windows.Forms.AnchorStyles.sz(1), System.Windows.Forms.AnchorStyles) ElseIf sz.Length = 3 Then Args(0).Form.Controls("").Anchor = CType(System.Windows.Forms.AnchorStyles.sz(0) Or System.Windows.Forms.AnchorStyles.sz(1) Or System.Windows.Forms.AnchorStyles.sz(2), System.Windows.Forms.AnchorStyles) ElseIf sz.Length = 4 Then Args(0).Form.Controls("").Anchor = CType(System.Windows.Forms.AnchorStyles.sz(0) Or System.Windows.Forms.AnchorStyles.sz(1) Or System.Windows.Forms.AnchorStyles.sz(2) Or System.Windows.Forms.AnchorStyles.sz(3), System.Windows.Forms.AnchorStyles) End if |
-- 作者:2425004926 -- 发布时间:2022/8/27 13:46:00 -- 因为总共是9种可能,还是把9种可能罗列一遍,如果罗列代码是多了一些 |
-- 作者:有点蓝 -- 发布时间:2022/8/27 14:00:00 -- Dim e = Args(0) dim s as string = Args(1) dim 控件名称 as string = Args(2) Dim a As System.Windows.Forms.AnchorStyles For Each ss As String In s.Split("|") a = a Or [Enum].Parse(GetType(System.Windows.Forms.AnchorStyles), ss) Next e.Form.Controls(控件名称).Anchor = a
[此贴子已经被作者于2022/8/27 16:05:39编辑过]
|
-- 作者:2425004926 -- 发布时间:2022/8/27 14:34:00 -- 调用出错了
Dim e = Args(0) dim s as string = Args(1) dim 控件名称 as string = Args(2) Dim a As System.Windows.Forms.AnchorStyles For Each ss As String In s.Split("|") a = a Or [Enum].Parse(GetType(System.Windows.Forms.AnchorStyles), s) Next Args(0).Form.Controls(控件名称).Anchor = a Functions.Execute("_Anchor", e, "Top|Bottom|Left|Right", "TextBox1") ‘调用出错
|
-- 作者:SbFox -- 发布时间:2022/8/27 15:32:00 -- a = a Or [Enum].Parse(GetType(System.Windows.Forms.AnchorStyles), ss) |
-- 作者:SbFox -- 发布时间:2022/8/27 15:34:00 -- For Each ss As String In s.Split("|") a = a Or [Enum].Parse(GetType(System.Windows.Forms.AnchorStyles), ss) Args(0).Form.Controls(控件名称).Anchor = a Next 应该要这样吧 |
-- 作者:2425004926 -- 发布时间:2022/8/27 16:04:00 -- 好了,谢谢老师! Dim e = Args(0) Dim s As String = Args(1) Dim 控件名称 As String = Args(2) Dim a As System.Windows.Forms.AnchorStyles For Each ss As String In s.Split("|") a = a Or [Enum].Parse(GetType(System.Windows.Forms.AnchorStyles), ss) Next Args(0).Form.Controls(控件名称).Anchor = a \'Functions.Execute("_Anchor2", e, "Top|Bottom|Left|Right", "TextBox1") 我还用另一种方法写了一版 Dim e = Args(0) Select Case Args(2) Case 1 Args(0).Form.Controls(Args(1)).Anchor = CType(System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left, System.Windows.Forms.AnchorStyles) \'上左 Case 2 Args(0).Form.Controls(Args(1)).Anchor = CType(System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right, System.Windows.Forms.AnchorStyles) \'上右 Case 3 Args(0).Form.Controls(Args(1)).Anchor = CType(System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right, System.Windows.Forms.AnchorStyles) \'下右 Case 4 Args(0).Form.Controls(Args(1)).Anchor = CType(System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left, System.Windows.Forms.AnchorStyles) \'下左 Case 5 Args(0).Form.Controls(Args(1)).Anchor = CType(System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left, System.Windows.Forms.AnchorStyles) \'上下左 Case 6 Args(0).Form.Controls(Args(1)).Anchor = CType(System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right, System.Windows.Forms.AnchorStyles) \'上左右 Case 7 Args(0).Form.Controls(Args(1)).Anchor = CType(System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right, System.Windows.Forms.AnchorStyles) \'上下右 Case 8 Args(0).Form.Controls(Args(1)).Anchor = CType(System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right, System.Windows.Forms.AnchorStyles) \'下左右 Case 9 Args(0).Form.Controls(Args(1)).Anchor = CType(System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right, System.Windows.Forms.AnchorStyles) \'上下左右 End Select \'数字顺序是由左到下顺时针旋转 \'Functions.Execute("_Anchor", e, 控件名称, 控件位置) \'Functions.Execute("_Anchor", e, "TextBox1", 3) |
-- 作者:有点蓝 -- 发布时间:2022/8/27 16:10:00 -- 啊,如果是数字,更简单了,一行代码搞定。不过话说回来,就这么一行代码还需要函数吗 Args(0).Form.Controls(Args(1)).Anchor = Args(2) |