定制控制设计模式问题 [英] Custom Control Design Mode Problem

查看:61
本文介绍了定制控制设计模式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个在我的应用程序中使用的自定义控件。我的

应用程序包含一个表单设计器,因此控件可以托管,而

控件的设计模式是真还是假,取决于它们是否为
正在使用表单设计器,或者处于运行模式。自定义控件包含一个

滑块控件,该控件应该在我们的表单设计器中处于活动状态
(designmode = true)并且在我们的运行模式下处于非活动状态(designmode = false)。

的问题是我正在反过来。


我已将此代码放入一个Intialize方法,该方法在自定义时触发/>
控件被实例化。


Private Sub Initialize()

如果Me.DesignMode = True那么

Splitter1.Enabled = True

否则

Splitter1.Enabled = False

结束如果

End Sub


如果控件

designmode = False,则可以禁用拆分器,但如果反向为真,则不启用拆分器。


我在VB.Net 2003工作。

I have developed a custom control to be used in my application. My
application includes a form designer, so the control can be hosted while
designmode for the control is either true or false, depending on whether they
are using the form designer, or in "run mode". The custom control includes a
slider control that is supposed to be active in our form designer
(designmode=true) and inactive in our run mode (designmode=false). The
problem is that I''m getting the reverse.

I''ve put this code into an Intialize method that fires when the custom
control is instantiated.

Private Sub Initialize()
If Me.DesignMode = True Then
Splitter1.Enabled = True
Else
Splitter1.Enabled = False
End If
End Sub

This works in order to disable the splitter if the controls
designmode=False, but does not enable the splitter if the reverse is true.

I am working in VB.Net 2003.

推荐答案




感谢您的帖子。


根据我的理解,您的应用程序实现了IDesignHost和

其他界面,以便为托管自定义提供设计时支持

控制。


目前,我不确定我是否理解你的问题。看来

你的程序逻辑是正确的:


Private Sub Initialize()

如果Me.DesignMode = True那么

Splitter1.Enabled = True

否则

Splitter1.Enabled = False

结束如果

结束子


你的意思是Me.DesignMode有时会报错状态吗?更多

特别是,有时Me.DesignMode在设计时报告错误,是吗?


如果我们使用Reflector查看Component.DesignMode,我们将看到:

[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Hidden),

可浏览(false)]

protected bool DesignMode

{

get

{

ISite site1 = this.site;

if(site1!= null)

{

返回site1.DesignMode;

}

返回false;

} <
}


因此,Component.DesignMode只查询内部ISite并返回其

DesignMode属性。但是,如果未创建网站,则只会报告

false。有关详细信息,请参阅以下链接:

错误详细信息:DesignMode变量似乎无法按预期工作
http://lab.msdn.microsoft.com/Produc...x?feedbackid=d

6ad5162-9693-49cc-abc0-659111823582

希望这会有所帮助。


祝你好运,

Jeffrey Tan

Microsoft在线合作伙伴支持

安全! - www.microsoft.com/security

此帖子按原样提供没有保证,也没有授予任何权利。

Hi,

Thanks for your post.

Based on my understanding, your application implemented the IDesignHost and
other interfaces to introduce design-time support for hosting custom
controls.

Currently, I am not sure I understand your problem very well. It seems that
your program logic below is correct:

Private Sub Initialize()
If Me.DesignMode = True Then
Splitter1.Enabled = True
Else
Splitter1.Enabled = False
End If
End Sub

Do you mean that Me.DesignMode sometimes reports the wrong state? More
specificly, sometimes Me.DesignMode reports false in design-time, yes?

If we use Reflector to view Component.DesignMode, we will see:
[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Hidden),
Browsable(false)]
protected bool DesignMode
{
get
{
ISite site1 = this.site;
if (site1 != null)
{
return site1.DesignMode;
}
return false;
}
}

So, Component.DesignMode just query the internal ISite and return its
DesignMode property. However, if site is not created, it will just report
false. For more information, please refer to the link below:
"Bug Details: DesignMode variable does not appear to work as expected"
http://lab.msdn.microsoft.com/Produc...x?feedbackid=d
6ad5162-9693-49cc-abc0-659111823582

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Jeffrey,


感谢您的回复。对于第一篇文章的含糊不清感到抱歉,

,但你所有的假设都是完全正确的。我做了一些检查,并且你怀疑,我的控制还没有找到。我将代码移动到下面的

方法,这是通过控件的调整大小和绘制事件

(我会认为这是最好的''工作)。我已经在运行时监视输出

窗口,所以我知道分割器已启用,但我只是

当designmode = true时无法激活它。在设计模式下,

控制是否可能不允许焦点通过,如果

那么,您对如何处理问题有任何建议吗?

Private Sub RedrawControls()

Dim ControlHeight As Integer = txtField.Height


如果Me.ClientRectangle.Height<> ; txtField.Height然后

Me.SetClientSizeCore(Me.ClientRectangle.Width,txtField.Height)

退出Sub

结束如果


如果lblPrompt.Visible = True那么

txtField.SetBounds(lblPrompt.Width,0,Me.ClientRectangle.Width -

lblPrompt.Width ,lblPrompt.Height)

Else

txtField.SetBounds(0,0,Me.ClientRectangle.Width,

lblPrompt.Height)

结束如果


如果Me.DesignMode = True那么

Splitter1.Enabled = True

调试。 WriteLine(Splitter1.Enabled)

Else

Splitter1.Enabled = False

结束如果


End Sub


"" Jeffrey Tan [MSFT]"" <,V - ***** @ online.microsoft.com>在消息中写道

新闻:Ct ************** @ TK2MSFTNGXA01.phx.gbl ...
Jeffrey,

Thank you for your reply. I''m sorry for the ambiguity of the first post,
but all of your assumptions were exactly correct. I did some checking, and
as you suspected, my control was not yet sited. I moved the code to the
method below, which is by both the resize and paint events of the control
(I''ll figure which is best after it''s working). I''ve monitored the output
windows during runtime, so I know the splitter is enabled, however I just
can''t get it to activate when designmode=true. Is it possible that the
control while in design mode is not allowing focus to pass through, and if
so, do you have any suggestions for how to handle the problem?
Private Sub RedrawControls()
Dim ControlHeight As Integer = txtField.Height

If Me.ClientRectangle.Height <> txtField.Height Then
Me.SetClientSizeCore(Me.ClientRectangle.Width, txtField.Height)
Exit Sub
End If

If lblPrompt.Visible = True Then
txtField.SetBounds(lblPrompt.Width, 0, Me.ClientRectangle.Width -
lblPrompt.Width, lblPrompt.Height)
Else
txtField.SetBounds(0, 0, Me.ClientRectangle.Width,
lblPrompt.Height)
End If

If Me.DesignMode = True Then
Splitter1.Enabled = True
Debug.WriteLine(Splitter1.Enabled)
Else
Splitter1.Enabled = False
End If

End Sub

""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:Ct**************@TK2MSFTNGXA01.phx.gbl...

感谢您的帖子。

根据我的理解,您的应用程序实现了IDesignHost
和其他界面,以便为托管自定义提供设计时支持控制。

目前,我不确定我是否理解你的问题。看来
下面你的程序逻辑是正确的:

Private Sub Initialize()
如果Me.DesignMode = True那么
Splitter1.Enabled =真的
否则
Splitter1.Enabled = False
结束如果
结束子

你的意思是Me.DesignMode有时会报错状态吗?更具体的是,有时Me.DesignMode在设计时报告错误,是吗?

如果我们使用Reflector查看Component.DesignMode,我们将看到:
[DesignerSerializationVisibility(DesignerSerializat) ionVisibility.Hidden),
可浏览(假)]
受保护的bool DesignMode
{
获取
{
ISite site1 = this.site;
if(site1!= null)
{
返回site1.DesignMode;
}
返回false;
}
}
DesignMode属性。但是,如果未创建网站,则仅报告
false。有关详细信息,请参阅以下链接:
错误详细信息:DesignMode变量似乎无法按预期工作
http://lab.msdn.microsoft.com/Produc...x?feedbackid=d
6ad5162-9693-49cc-abc0-659111823582
希望这会有所帮助。

致以最诚挚的问候,
Jeffrey Tan
Microsoft在线合作伙伴支持安全! - www.microsoft.com/security
此帖子提供就像没有保证,也没有授予任何权利。
Hi,

Thanks for your post.

Based on my understanding, your application implemented the IDesignHost
and
other interfaces to introduce design-time support for hosting custom
controls.

Currently, I am not sure I understand your problem very well. It seems
that
your program logic below is correct:

Private Sub Initialize()
If Me.DesignMode = True Then
Splitter1.Enabled = True
Else
Splitter1.Enabled = False
End If
End Sub

Do you mean that Me.DesignMode sometimes reports the wrong state? More
specificly, sometimes Me.DesignMode reports false in design-time, yes?

If we use Reflector to view Component.DesignMode, we will see:
[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Hidden),
Browsable(false)]
protected bool DesignMode
{
get
{
ISite site1 = this.site;
if (site1 != null)
{
return site1.DesignMode;
}
return false;
}
}

So, Component.DesignMode just query the internal ISite and return its
DesignMode property. However, if site is not created, it will just report
false. For more information, please refer to the link below:
"Bug Details: DesignMode variable does not appear to work as expected"
http://lab.msdn.microsoft.com/Produc...x?feedbackid=d
6ad5162-9693-49cc-abc0-659111823582

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.



Hi Matt,


感谢您的反馈。
Hi Matt,

Thanks for your feedback.
我在运行时监视输出窗口,所以我知道分割器
已启用,

你的意思是你看到下面的Debug。 WriteLine行输出true

值?


如果Me.DesignMode = True那么

Splitter1.Enabled = True

Debug.WriteLine(Splitter1.Enabled)

否则

Splitter1.Enabled = False

结束如果

但是当designmode = true时我无法激活它
I''ve monitored the output windows during runtime, so I know the splitter is enabled,
Do you mean that you see the below Debug.WriteLine line outputs "true"
value?

If Me.DesignMode = True Then
Splitter1.Enabled = True
Debug.WriteLine(Splitter1.Enabled)
Else
Splitter1.Enabled = False
End If
however I just can''t get it to activate when designmode=true



我假设你的意思是,虽然Debug.WriteLine输出

Splitter1.Enabled是真的,它仍然无法得到任何关注。这是你的

关注,是吗?


在上面的陈述中,designmode = true是什么?是指

VS.net设计师中的DesignMode,或者是指应用程序设计时的DesignMode

支持实现?我怀疑后者。


目前,因为我没有你的运行时设计器实现

代码,我无法理解出了什么问题,不能给出非常好的有用的

建议。但在设计时,控件的行为被与之关联的

ControlDesigner所吸引。更具体地说,Winform应用了

System.Windows.Forms.Design.SplitterDesigner到Splitter控件。我想

您可以使用Reflector查看

System.Windows.Forms.Design.SplitterDesigner的源代码以获取更多信息

设计时行为。


通常,Splitter控件通过设计时边框显示焦点

矩形,由SplitterDesigner.DrawBorder方法绘制。 br />
SplitterDesigner.DrawBorder在SplitterDesigner.OnPaintAdornments中调用

像这样:

protected override void OnPaintAdornments(PaintEventArgs pe)

{

Splitter splitter1 =(Splitter)base.Component;

base.OnPaintAdornments(pe);

if(splitter1.BorderStyle == BorderStyle.None)

{

this.DrawBorder(pe.Graphics);

}

}


它的父类方法是:ControlDesigner.OnPaintAdornments,最后在ControlDesigner.WndProc中调用
,消息为:15,即

控件的WM_PAINT。


所以你可以按照这个调用堆栈来分析为什么焦点边框不会在你的应用程序DesignMode中出现



希望这个祝你好运。


祝你好运,

Jeffrey Tan

微软在线合作伙伴支持

安全! - www.microsoft.com/security

此帖子按原样提供没有保证,也没有赋予任何权利。


I assume you mean that, although the Debug.WriteLine outputs
Splitter1.Enabled to be true, it still can not get any focus. This is your
concern, yes?

In the above statement, does the "designmode=true" mean DesignMode in
VS.net designer, or mean the DesignMode in your application design-time
support implementation? I suspect the latter.

Currently, because I did not have your runtime designer implementation
code, I can not understand what going wrong and can not give very useful
suggestion. But in design-time, the control''s behavior is hooked by the
ControlDesigner associated with it. More specificly, Winform applied
System.Windows.Forms.Design.SplitterDesigner to Splitter control. I think
you can use Reflector to view the source code of
System.Windows.Forms.Design.SplitterDesigner to get more information of its
design-time behavior.

Normally, Splitter control shows focus through a design-time border
rectangle, which is drawn by SplitterDesigner.DrawBorder method.
SplitterDesigner.DrawBorder is called in SplitterDesigner.OnPaintAdornments
like this:
protected override void OnPaintAdornments(PaintEventArgs pe)
{
Splitter splitter1 = (Splitter) base.Component;
base.OnPaintAdornments(pe);
if (splitter1.BorderStyle == BorderStyle.None)
{
this.DrawBorder(pe.Graphics);
}
}

Its parent class method is: ControlDesigner.OnPaintAdornments, which is
finally called in ControlDesigner.WndProc with message: 15, that is
WM_PAINT for the control.

So you can follow this call stack to analysis why the focus border does not
appear in your application at "DesignMode".

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


这篇关于定制控制设计模式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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