本文介绍了定制控制设计模式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我开发了一个在我的应用程序中使用的自定义控件。我的 应用程序包含一个表单设计器,因此控件可以托管,而 控件的设计模式是真还是假,取决于它们是否为正在使用表单设计器,或者处于运行模式。自定义控件包含一个 滑块控件,该控件应该在我们的表单设计器中处于活动状态(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. Myapplication includes a form designer, so the control can be hosted whiledesignmode for the control is either true or false, depending on whether theyare using the form designer, or in "run mode". The custom control includes aslider control that is supposed to be active in our form designer(designmode=true) and inactive in our run mode (designmode=false). Theproblem is that I''m getting the reverse.I''ve put this code into an Intialize method that fires when the customcontrol is instantiated.Private Sub Initialize()If Me.DesignMode = True ThenSplitter1.Enabled = TrueElseSplitter1.Enabled = FalseEnd IfEnd SubThis works in order to disable the splitter if the controlsdesignmode=False, but does not enable the splitter if the reverse is true.I am working in VB.Net 2003.推荐答案 我假设你的意思是,虽然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 outputsSplitter1.Enabled to be true, it still can not get any focus. This is yourconcern, yes?In the above statement, does the "designmode=true" mean DesignMode inVS.net designer, or mean the DesignMode in your application design-timesupport implementation? I suspect the latter.Currently, because I did not have your runtime designer implementationcode, I can not understand what going wrong and can not give very usefulsuggestion. But in design-time, the control''s behavior is hooked by theControlDesigner associated with it. More specificly, Winform appliedSystem.Windows.Forms.Design.SplitterDesigner to Splitter control. I thinkyou can use Reflector to view the source code ofSystem.Windows.Forms.Design.SplitterDesigner to get more information of itsdesign-time behavior.Normally, Splitter control shows focus through a design-time borderrectangle, which is drawn by SplitterDesigner.DrawBorder method.SplitterDesigner.DrawBorder is called in SplitterDesigner.OnPaintAdornmentslike 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 isfinally called in ControlDesigner.WndProc with message: 15, that isWM_PAINT for the control.So you can follow this call stack to analysis why the focus border does notappear in your application at "DesignMode".Hope this helps.Best regards,Jeffrey TanMicrosoft Online Partner SupportGet Secure! - www.microsoft.com/securityThis posting is provided "as is" with no warranties and confers no rights. 这篇关于定制控制设计模式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-29 06:34