开发者

PropertyGrid PaintValue issue: How to remove (and paint outside) the standard rectangle?

开发者 https://www.devze.com 2022-12-24 05:51 出处:网络
This might be a straightforward question, even though I haven\'t found an easy solution to it: I\'ve implemented my custom UITypeEditor with the sole purpose of adding a PaintValue to bools. For the

This might be a straightforward question, even though I haven't found an easy solution to it:

I've implemented my custom UITypeEditor with the sole purpose of adding a PaintValue to bools. For the sake of the discussion, let's assume that PaintValue will either paint a che开发者_StackOverflowcked or unchecked radiobutton.

Question 1:

Now, here's the problem: It seems like PaintValue automatically inserts a 20x13px rectangle after all paint code has completed. Naturally, a radiobutton inside a black rectangle is ugly. Can I easily instruct or override this rectagle not to be painted?

Question 2:

In this respect, is it possible to paint on top of the propertygrid's native look - meaning could I paint something in order to obscure (part of) the black line separating two grid cells vertically? The purpose of doing this would be to indicate that two values were linked, like constrained width/height to an aspect ratio.

Any answer is highly appreciated.


I don't know about the painting, but on point 2 - maybe add a glyph via IPropertyValueUIService - there's an example on codeproject.


You can remove the rectangle using the following code but you cannot paint outside of it. Well, you can paint but the PropertyGrid will paint over it later, so it makes not much sense.

public override void PaintValue(PaintValueEventArgs e)
{
    // remove the lines (you cannot draw on these lines anymore)
    e.Graphics.ExcludeClip(
        new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, 1));
    e.Graphics.ExcludeClip(
        new Rectangle(e.Bounds.X, e.Bounds.Y, 1, e.Bounds.Height));
    e.Graphics.ExcludeClip(
        new Rectangle(e.Bounds.Width, e.Bounds.Y, 1, e.Bounds.Height));
    e.Graphics.ExcludeClip(
        new Rectangle(e.Bounds.X, e.Bounds.Height, e.Bounds.Width, 1));
    // now draw your own image - it will be shown without the box
    e.Graphics.DrawImage(myImage, e.Bounds);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消