奇怪? DesignMode行为 [英] Strange? DesignMode Behaviour

查看:61
本文介绍了奇怪? DesignMode行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了我关于用户控件的问题,我还遇到了DesignMode的问题。

这是项目层次结构:


MainApp

| _ Project1

| _ SubProject(UserControl)


SubProject有一个默认构造函数(New),用于处理MyBase.New()事物

然后是InitializeComponent()。


当我在IDE(设计时)中打开Project1表格时,在其上的子项目

放置,New方法执行,DesignMode为False。如果我那么

在属性网格中更改SubProject的属性(仍然在Project1中)

然后将DesignMode(在SubProject中)报告为True。


SubProject_Load事件发生同样的事情,就是在设计模式下打开Project1表单时报告

DesignMode False。


我在哪里可以放置必须仅在MainApp运行时运行的代码?这一切是否有意义?


TIA


Charles

解决方案

你好,


" Charles Law" < BL ** @ thingummy.com> schrieb:

除了我关于用户控件的问题,我在使用DesignMode时遇到了问题。这是项目层次结构:

MainApp
| _ Project1
| _ SubProject(UserControl)

SubProject有一个默认的构造函数(New)
MyBase.New()的东西,然后是InitializeComponent()。

当我在IDE中打开Project1表单(设计时),在放置SubProject的时候,执行新方法,
和DesignMode为假。




如果您在窗体上放置一个控件,它就不再在设计模式下运行了。我现在无法访问VS.NET,你可能想要尝试的bug:


\\\ >
#If Debug Then

Console.WriteLine(Debug mode。)

#Else

Console.WriteLine (发布模式。)

#End如果

///


您可以检查调试器是否是通过电话附上

''System.Diagnostics.Debugger.IsAttached''。


-

Herfried K. Wagner

MVP·VB Classic,VB.NET
http:/ /www.mvps.org/dotnet


" Charles Law" < BL ** @ thingummy.com> schrieb

除了我关于用户控件的问题之外,我还有一个问题是
DesignMode。这是项目层次结构:

MainApp
| _ Project1
| _ SubProject(UserControl)

SubProject有一个默认的构造函数(New)
MyBase.New()的东西,然后是InitializeComponent()。

当我在IDE(设计时)中打开Project1表单时,在其上放置了SubProject,执行新方法,DesignMode为False。如果我然后在属性网格中更改了SubProject的属性
(仍然在Project1中),那么DesignMode(在SubProject中)被报告为
True。

同样的事情发生在SubProject_Load事件,就是它在设计
模式下打开Project1表单时报告DesignMode False。

我在哪里可以放置必须仅在MainApp运行时运行的代码?这是否有意义?




我不确定我是否理解你。 DesignMode属性尚未在

构造函数中设置。

-

Armin


嗨Charles,

你在谈论谁的DesignMode,即。什么是对象引用?


如果是UserControl,你可以检查其Container的DesignMode,以及

的容器''父母等,或其他什么。


换句话说,检查链条以查看设计中是否有人

模式。


我自己没有使用任何这个,但当你有< its>时,有一点意思是

UserControl在DesignMode中。项目打开是因为你添加了

对它的控制,移动它们等等 - 但它不是在设计模式下,当它在表格上的时候是
另一个项目 - 你不能玩它 - 除非它的

属性被设置。所以Project1将处于设计模式,但是UserControl

不会。


然后,也许我正在咆哮错误的树:-)。值得深思。


问候,

Fergus

MVP [Windows键盘,PC电源开关]

Further to my issue about user controls, I have a problem with DesignMode.
Here is the project hierarchy:

MainApp
|_ Project1
|_ SubProject (UserControl)

SubProject has a default constructor (New) which does the MyBase.New() thing
and then InitializeComponent().

When I open the Project1 form in the IDE (design time), on which SubProject
is placed, the New method executes, and DesignMode is False. If I then
change a property of SubProject in the property grid (still in Project1)
then DesignMode (in SubProject) is reported as True.

The same thing happens with the SubProject_Load event, that is it reports
DesignMode False when opening the Project1 form in design mode.

Where can I put code that must only run when MainApp runs? Does that all
make sense?

TIA

Charles

解决方案

Hello,

"Charles Law" <bl**@thingummy.com> schrieb:

Further to my issue about user controls, I have a problem
with DesignMode. Here is the project hierarchy:

MainApp
|_ Project1
|_ SubProject (UserControl)

SubProject has a default constructor (New) which does the
MyBase.New() thing and then InitializeComponent().

When I open the Project1 form in the IDE (design time), on
which SubProject is placed, the New method executes,
and DesignMode is False.



If you place a control on a form, it doesn''t run in design mode any more. I
currently don''t have access to VS.NET, bug you may want to experiment with:

\\\
#If Debug Then
Console.WriteLine("Debug mode.")
#Else
Console.WriteLine("Release mode.")
#End If
///

You can check if a debugger is attached by calling
''System.Diagnostics.Debugger.IsAttached''.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet


"Charles Law" <bl**@thingummy.com> schrieb

Further to my issue about user controls, I have a problem with
DesignMode. Here is the project hierarchy:

MainApp
|_ Project1
|_ SubProject (UserControl)

SubProject has a default constructor (New) which does the
MyBase.New() thing and then InitializeComponent().

When I open the Project1 form in the IDE (design time), on which
SubProject is placed, the New method executes, and DesignMode is
False. If I then change a property of SubProject in the property grid
(still in Project1) then DesignMode (in SubProject) is reported as
True.

The same thing happens with the SubProject_Load event, that is it
reports DesignMode False when opening the Project1 form in design
mode.

Where can I put code that must only run when MainApp runs? Does that
all make sense?



I''m not sure if I understand you. The DesignMode property is not set in the
constructor yet.
--
Armin


Hi Charles,

Whose DesignMode are you talking about, ie. what''s the object reference?

If it''s the UserControl can you check the DesignMode of its Container, and
of the Container''s Parent, etc, or whatever.

In other words, check up the chain to see if anyone there is in Design
Mode.

I haven''t used any of this myself, but it sort of makes sense that a
UserControl is in DesignMode when you have <its> project open because you add
Controls to it, move them around, etc, - but it''s not in Design Mode when it''s
on a Form in another project - you can''t play with it - except when its
properties are being set. So Project1 would be in Design Mode but UserControl
would not.

Then again, maybe I''m barking up the wrong tree :-). Food for thought.

Regards,
Fergus
MVP [Windows Keyboard, PC Power Switch]


这篇关于奇怪? DesignMode行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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