<i id='TYb95'><tr id='TYb95'><dt id='TYb95'><q id='TYb95'><span id='TYb95'><b id='TYb95'><form id='TYb95'><ins id='TYb95'></ins><ul id='TYb95'></ul><sub id='TYb95'></sub></form><legend id='TYb95'></legend><bdo id='TYb95'><pre id='TYb95'><center id='TYb95'></center></pre></bdo></b><th id='TYb95'></th></span></q></dt></tr></i><div id='TYb95'><tfoot id='TYb95'></tfoot><dl id='TYb95'><fieldset id='TYb95'></fieldset></dl></div>
  • <small id='TYb95'></small><noframes id='TYb95'>

    <legend id='TYb95'><style id='TYb95'><dir id='TYb95'><q id='TYb95'></q></dir></style></legend>

      <tfoot id='TYb95'></tfoot>

        <bdo id='TYb95'></bdo><ul id='TYb95'></ul>

        如何自定义 ToolStripTextBox 的呈现?

        How to customise rendering of a ToolStripTextBox?(如何自定义 ToolStripTextBox 的呈现?)
          <bdo id='1Ogxs'></bdo><ul id='1Ogxs'></ul>

            <tbody id='1Ogxs'></tbody>

            • <legend id='1Ogxs'><style id='1Ogxs'><dir id='1Ogxs'><q id='1Ogxs'></q></dir></style></legend>

              <small id='1Ogxs'></small><noframes id='1Ogxs'>

              <i id='1Ogxs'><tr id='1Ogxs'><dt id='1Ogxs'><q id='1Ogxs'><span id='1Ogxs'><b id='1Ogxs'><form id='1Ogxs'><ins id='1Ogxs'></ins><ul id='1Ogxs'></ul><sub id='1Ogxs'></sub></form><legend id='1Ogxs'></legend><bdo id='1Ogxs'><pre id='1Ogxs'><center id='1Ogxs'></center></pre></bdo></b><th id='1Ogxs'></th></span></q></dt></tr></i><div id='1Ogxs'><tfoot id='1Ogxs'></tfoot><dl id='1Ogxs'><fieldset id='1Ogxs'></fieldset></dl></div>
                  <tfoot id='1Ogxs'></tfoot>
                  本文介绍了如何自定义 ToolStripTextBox 的呈现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我非常喜欢 ToolStripProfessionalRenderer 样式,但我不喜欢它呈现 ToolStripTextBox 的方式.在这里,ToolStripSystemRenderer 在 IMO 上做得更好.现在有没有办法将两个渲染器的行为结合起来,为文本框使用系统样式,为其他所有内容使用专业样式?我已经成功地成功地使用专业风格的按钮和系统风格的其余部分(通过派生两个类).但是 ToolStrip 中的文本框似乎没有由渲染器处理.使用 .NET Reflector,这些文本框甚至似乎都没有 Paint 事件处理程序,尽管它是由 ToolStrip.OnPaint 方法调用的.我想知道绘制这样一个文本框的代码在哪里,以及如何将它配置为像所有其他文本框一样绘制文本框.

                  解决方案

                  如果你只是想要系统渲染,最简单的方法是使用 ToolStripControlHost 代替:

                  <上一页>类 ToolStripSystemTextBox : ToolStripControlHost{公共工具条系统文本框:基础(新文本框()){}[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)][TypeConverter(typeof(ExpandableObjectConverter))]public TextBox TextBox { get { return Control as TextBox;} }}

                  我在这里采取了简单的方法,将底层的 TextBox 直接暴露给表单设计器,而不是委托其所有属性.显然,如果你愿意,你可以编写所有的属性委托代码.

                  另一方面,如果有人想做真正的自定义渲染,我会告诉你 ToolStripTextBox 是做什么的.它不是直接托管 TextBox,而是托管一个名为 ToolStripTextBoxControl 的私有派生类.此类重写其 WndProc 以便直接处理 WM_NCPAINT.然后它不是将实际绘图委托给渲染器,而是检查渲染器的类型,然后分支到 ToolStripTextBoxControl 内的不同渲染代码.太丑了.

                  I like the ToolStripProfessionalRenderer style quite a lot, but I do not like the way it renders a ToolStripTextBox. Here, ToolStripSystemRenderer does a better job IMO. Now is there a way to combine both renderers' behaviour to use system style for text boxes and pro style for everything else? I have successfully managed to use pro style for buttons and system style for the rest (by deriving both classes). But text boxes in a ToolStrip don't seem to be handled by the renderer. Using .NET Reflector, those text boxes don't even seem to have a Paint event handler, although it's called by the ToolStrip.OnPaint method. I'm wondering where's the code to paint such a text box at all and how it can be configured to draw a text box like all other text boxes.

                  解决方案

                  If you just want system rendering, the easiest approach is to use ToolStripControlHost instead:

                  class ToolStripSystemTextBox : ToolStripControlHost
                  {
                     public ToolStripSystemTextBox : base(new TextBox()) { }
                  
                     [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                     [TypeConverter(typeof(ExpandableObjectConverter))]
                     public TextBox TextBox { get { return Control as TextBox; } }
                  }
                  

                  I've taken the easy way out here and exposed the underlying TextBox directly to the form designer, instead of delegating all its properties. Obviously you can write all the property delgation code if you want.

                  On the other hand, if anyone wants to do truly custom rendering, I'll tell you what ToolStripTextBox does. Instead of hosting a TextBox directly, it hosts a private derived class called ToolStripTextBoxControl. This class overrides its WndProc in order to directly handle WM_NCPAINT. And then instead of delegating the actual drawing to the Renderer, it checks the Renderer's Type, and then branches to different rendering code inside of ToolStripTextBoxControl. It's pretty ugly.

                  这篇关于如何自定义 ToolStripTextBox 的呈现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to keep the Text of a Read only TextBox after PostBack()?(PostBack()之后如何保留只读文本框的文本?)
                  Winforms Textbox - Using Ctrl-Backspace to Delete Whole Word(Winforms 文本框 - 使用 Ctrl-Backspace 删除整个单词)
                  C# - Add button click events using code(C# - 使用代码添加按钮单击事件)
                  Multi-color TextBox C#(多色文本框 C#)
                  How can i set the caret position to a specific index in passwordbox in WPF(如何将插入符号位置设置为 WPF 密码框中的特定索引)
                  C# Numeric Only TextBox Control(C# 纯数字文本框控件)
                  <tfoot id='GzI1T'></tfoot>

                      • <bdo id='GzI1T'></bdo><ul id='GzI1T'></ul>
                          <tbody id='GzI1T'></tbody>
                        <i id='GzI1T'><tr id='GzI1T'><dt id='GzI1T'><q id='GzI1T'><span id='GzI1T'><b id='GzI1T'><form id='GzI1T'><ins id='GzI1T'></ins><ul id='GzI1T'></ul><sub id='GzI1T'></sub></form><legend id='GzI1T'></legend><bdo id='GzI1T'><pre id='GzI1T'><center id='GzI1T'></center></pre></bdo></b><th id='GzI1T'></th></span></q></dt></tr></i><div id='GzI1T'><tfoot id='GzI1T'></tfoot><dl id='GzI1T'><fieldset id='GzI1T'></fieldset></dl></div>

                          <small id='GzI1T'></small><noframes id='GzI1T'>

                            <legend id='GzI1T'><style id='GzI1T'><dir id='GzI1T'><q id='GzI1T'></q></dir></style></legend>