在设计视图中迭代窗体上的控件... [英] Iterate through controls on form in design view...

查看:54
本文介绍了在设计视图中迭代窗体上的控件...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在Microsoft Access中可以编写这样的代码


子测试()

DoCmd.OpenForm " TestForm",acDesign

Dim a As Control

For each a In Forms(TestForm)。控件

做东西

下一页

结束子


在DESIGN时迭代表单上的所有控件。这将是

在运行时对表单生效。


VB.Net中是否可以这样做?

祝你好运


Jan

Hi
In Microsoft Access it is possible to write code like this

Sub test()
DoCmd.OpenForm "TestForm", acDesign
Dim a As Control
For Each a In Forms("TestForm").Controls
Do stuff
Next
End Sub

To iterate through all controls on a form at DESIGN time. This will then
take effect for the form at runtime.

Is this possible in VB.Net?
Best regards

Jan

推荐答案

你好Jan,


我'你在设计时做什么意味着在运行时采取

效果让你感到困惑所以以下是更多的信息,而不是回答你的

查询。


在.NET中,Control的构造函数在设计时和(运行时的
课程)都被调用。有一个标志,Control.DesignMode告诉你

哪个。


如果你想为字面意思做一些事情< all>表单上的控件,

你必须有一个递归方法,它将一个Control作为参数

并为每个包含的控件做一些事情,所以他们的。 (A

表单是一个控件,所以没有问题,所有开始)。


类Foo作为表格

Public Sub New ()

MyBase.New()

InitializeComponent()

如果Me.DesignMode那么

DoStuffToControls(我)

结束如果

结束Sub


Sub DoStuffToTheControlsOf(oControl As Control)

For Each oControl.Controls中的oChildControl

做oChildControl的东西

DoStuffToTheControlsOf(oChildControl)

下一页

End Sub


问候,

Fergus
Hi Jan,

I''m a bit confused by what you mean by doing stuff at design-time to take
effect at run-time so the following is more for info than to answer your
query.

In .NET a Control''s constructor is called both at design-time and (of
course) at run-time. There is a flag, Control.DesignMode which tells you
which.

If you want to do something for literally <all> the Controls on the Form,
you''ll have to have a recursive method which takes a Control as a parameter
and does something for each of its contained Controls and so on for theirs. (A
Form is a Control so no problem getting it all started).

Class Foo As Form
Public Sub New()
MyBase.New()
InitializeComponent()
If Me.DesignMode Then
DoStuffToControls (Me)
End If
End Sub

Sub DoStuffToTheControlsOf (oControl As Control)
For Each oChildControl in oControl.Controls
Do stuff to oChildControl
DoStuffToTheControlsOf (oChildControl)
Next
End Sub

Regards,
Fergus


嗨Fergus

感谢您的回答。

我的意思是你可以移动创建一个表单并在

上设置一些控件。然后正常在运行时,控件将放置在设计时的同一位置

。但你可以通过代码移动控件,然后

设计视图和运行时视图是不同的。


我想要做的是编辑属性在设计时通过代码(即

所有文本框的大小)

因此在设计视图中永久性地改变表格的外观。


您的代码让我感到困惑:

您似乎有两种不同的功能

DoStuffToControls



DoStuffToTheControlsOf

这应该是相同的功能吗?

还在

Sub DoStuffToTheControlsOf(oControl As Control)
Hi Fergus
Thanks for your answer.
What I meant was that you can move create a form and place some controls on
it. Then "normally" af runtime the controls will be placed at the same place
as at design time. But you can move the controls via code and then the
design view and the runtime view are different.

What I would like to do was to edit properties in design time via code (ie
size of all textboxes)
Thus permanently changing the look of the form in design view.

Your code confuses me a bit:
You seem to have two different functions
DoStuffToControls
and
DoStuffToTheControlsOf
Should this be the same function?
Also in
Sub DoStuffToTheControlsOf (oControl As Control)
For oControl.Controls中的每个oChildControl
oChildControl的东西
DoStuffToTheControlsOf(oChildControl)
下一个
结束Sub


你在哪里定义oChildControl?

最好的问候


Jan


" Fergus Cooney" <音响****** @ tesco.net> skrev i en meddelelse

新闻:uG ************** @ TK2MSFTNGP11.phx.gbl ...嗨Jan,

我你觉得在设计时做什么你的意思有点困惑,因为
在运行时生效,所以以下内容更多的是信息而不是回答你的
查询。
哪个。

如果你想为字面意思做一些事情< all>在
表单上的控件,你必须有一个递归方法,它将一个Control作为一个
参数,并为每个包含的控件执行某些操作,以及
他们的控件。 (一个表单是一个控件,所以没有问题,所有开始)。

类Foo作为表单
Public Sub New()
MyBase.New()
InitializeComponent ()
如果Me.DesignMode那么
DoStuffToControls(Me)
结束如果
结束Sub

Sub DoStuffToTheControlsOf(oControl As Control)
对于oControl.Controls中的每个oChildControl
对oChildControl做的事情
DoStuffToTheControlsOf(oChildControl)
下一页

对此,
Fergus
For Each oChildControl in oControl.Controls
Do stuff to oChildControl
DoStuffToTheControlsOf (oChildControl)
Next
End Sub
Where do you define the oChildControl?
Best regards

Jan

"Fergus Cooney" <fi******@tesco.net> skrev i en meddelelse
news:uG**************@TK2MSFTNGP11.phx.gbl... Hi Jan,

I''m a bit confused by what you mean by doing stuff at design-time to take effect at run-time so the following is more for info than to answer your
query.

In .NET a Control''s constructor is called both at design-time and (of
course) at run-time. There is a flag, Control.DesignMode which tells you
which.

If you want to do something for literally <all> the Controls on the Form, you''ll have to have a recursive method which takes a Control as a parameter and does something for each of its contained Controls and so on for theirs. (A Form is a Control so no problem getting it all started).

Class Foo As Form
Public Sub New()
MyBase.New()
InitializeComponent()
If Me.DesignMode Then
DoStuffToControls (Me)
End If
End Sub

Sub DoStuffToTheControlsOf (oControl As Control)
For Each oChildControl in oControl.Controls
Do stuff to oChildControl
DoStuffToTheControlsOf (oChildControl)
Next
End Sub

Regards,
Fergus



嗨再次Fergus

我也看不到你如何调用这个函数。

如果我点击F5表格不再处于设计模式。


祝你好运


Jan



" Fergus Cooney" <音响****** @ tesco.net> skrev i en meddelelse

新闻:uG ************** @ TK2MSFTNGP11.phx.gbl ...
Hi again Fergus
I also do not see how you call the function.
If I hit F5 the form is not in design mode anylonger.

Best regards

Jan


"Fergus Cooney" <fi******@tesco.net> skrev i en meddelelse
news:uG**************@TK2MSFTNGP11.phx.gbl...
嗨Jan,

我有点困惑你在设计时做什么意思到
在运行时生效所以以下是更多的信息而不是回答你的
查询。

在.NET中,Control的构造函数在设计时和(当然)在运行时调用。有一个标志,Control.DesignMode告诉你
哪个。

如果你想为字面意思做一些事情< all>在
表单上的控件,你必须有一个递归方法,它将一个Control作为一个
参数,并为每个包含的控件执行某些操作,以及
他们的控件。 (一个表单是一个控件,所以没有问题,所有开始)。

类Foo作为表单
Public Sub New()
MyBase.New()
InitializeComponent ()
如果Me.DesignMode那么
DoStuffToControls(Me)
结束如果
结束Sub

Sub DoStuffToTheControlsOf(oControl As Control)
对于oControl.Controls中的每个oChildControl
对oChildControl做的事情
DoStuffToTheControlsOf(oChildControl)
下一页

对此,
Fergus
Hi Jan,

I''m a bit confused by what you mean by doing stuff at design-time to take effect at run-time so the following is more for info than to answer your
query.

In .NET a Control''s constructor is called both at design-time and (of
course) at run-time. There is a flag, Control.DesignMode which tells you
which.

If you want to do something for literally <all> the Controls on the Form, you''ll have to have a recursive method which takes a Control as a parameter and does something for each of its contained Controls and so on for theirs. (A Form is a Control so no problem getting it all started).

Class Foo As Form
Public Sub New()
MyBase.New()
InitializeComponent()
If Me.DesignMode Then
DoStuffToControls (Me)
End If
End Sub

Sub DoStuffToTheControlsOf (oControl As Control)
For Each oChildControl in oControl.Controls
Do stuff to oChildControl
DoStuffToTheControlsOf (oChildControl)
Next
End Sub

Regards,
Fergus



这篇关于在设计视图中迭代窗体上的控件...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆