如何自定义ToolStripTextBox的渲染? [英] How to customise rendering of a ToolStripTextBox?

查看:512
本文介绍了如何自定义ToolStripTextBox的渲染?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢ToolStripProfessionalRenderer样式颇多,但我不喜欢它呈现一个ToolStripTextBox的方式。在这里,ToolStripSystemRenderer做一个更好的工作IMO。现在有没有办法既渲染器的行为,以用于文本框的系统风格和专业风格的一切结合起来?我成功设法利用亲样式的按钮和系统风格的休息(由两个派生类)。但文本框在ToolStrip的似乎并没有被渲染处理。使用.NET反射,这些文本框甚至不似乎有一个Paint事件处理程序,但它被称为由ToolStrip.OnPaint方法。我不知道哪来的code绘制这样一个文本框,在所有的,以及它如何可以被配置为绘制文本框像所有其他文本框。

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.

推荐答案

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

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; } }
}

我已经拍了,而不是委托其所有属性讨巧这里直接暴露底层的文本框的窗体设计器。显然,如果你愿意,你可以写所有的财产delgation code。

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.

在另一方面,如果有人想做真正的自定义呈现,我会告诉你什么ToolStripTextBox一样。而不是直接托管文本框的,它承载的私人派生类称为ToolStripTextBoxControl。这个类覆盖了的WndProc以直接处理WM_NCPAINT。而不是委派实际绘制的渲染器,然后,它会检查渲染器的类型,然后跳转到不同的渲染code ToolStripTextBoxControl内。这是pretty的难看。

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的渲染?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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