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

这一生的挚爱 提交于 2019-12-11 10:59:20

问题


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 checked 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.


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/2512018/propertygrid-paintvalue-issue-how-to-remove-and-paint-outside-the-standard-re

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!