2010-03-24 20 views
1

這可能是一個簡單的問題,即使我還沒有找到一個簡單的解決方案,它:PropertyGrid PaintValue問題:如何去除(並在外面繪製)標準矩形?

我實現了我的自定義UITypeEditor的使用增加了PaintValue到布爾變量的唯一目的。爲了討論,我們假設PaintValue將繪製一個選中或未選中的單選按鈕。

問題1:

現在,這裏的問題:似乎所有的繪製代碼完成後,像PaintValue自動插入一個20x13px矩形。當然,黑色矩形內的單選按鈕很難看。我可以輕鬆地指示或覆蓋這個可以塗漆的rectagle 而不是嗎?

問題2:

在這方面,是有可能畫上PropertyGrid中的本機外觀的頂部 - 這意味着我能畫的東西,以掩蓋(的一部分)的黑線分隔兩個網格單元垂直?這樣做的目的是爲了表明兩個值是相關聯的,如約束寬度/高度與寬高比。

任何答案是非常感謝。

回答

3

我不瞭解這幅畫,但在第2點 - 也許通過IPropertyValueUIService添加字形 - codeproject上有一個例子。

+0

有趣的鏈接。儘管我希望得到更簡潔的答案。這不是應用程序的核心功能,所以我寧願保持代碼基本清潔,也不要將它與許多東西混雜在一起,只畫幾行。 – Pedery 2010-03-24 23:49:29

1

您可以使用以下代碼刪除矩形,但不能在其外面繪製。那麼,你可以繪製,但PropertyGrid稍後會繪製它,所以它沒有多大意義。

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

豎起大拇指:) – Pedery 2017-01-18 14:07:12