回答
我這樣做解決方案(當電網被包含在與背景圖像的形式)的特定問題simples修改就可以適應它創建一個通用的透明網格,只問如果父母有背景圖像,否則只需使用父背景顏色來繪製網格即可。
必須從DataGridView繼承並重寫PaintBackground方法是這樣的:
protected override void PaintBackground(Graphics graphics, Rectangle clipBounds, Rectangle gridBounds)
{
base.PaintBackground(graphics, clipBounds, gridBounds);
Rectangle rectSource = new Rectangle(this.Location.X, this.Location.Y, this.Width, this.Height);
Rectangle rectDest = new Rectangle(0, 0, rectSource.Width, rectSource.Height);
Bitmap b = new Bitmap(Parent.ClientRectangle.Width, Parent.ClientRectangle.Height);
Graphics.FromImage(b).DrawImage(this.Parent.BackgroundImage, Parent.ClientRectangle);
graphics.DrawImage(b, rectDest, rectSource, GraphicsUnit.Pixel);
SetCellsTransparent();
}
public void SetCellsTransparent()
{
this.EnableHeadersVisualStyles = false;
this.ColumnHeadersDefaultCellStyle.BackColor = Color.Transparent;
this.RowHeadersDefaultCellStyle.BackColor = Color.Transparent;
foreach (DataGridViewColumn col in this.Columns)
{
col.DefaultCellStyle.BackColor = Color.Transparent;
col.DefaultCellStyle.SelectionBackColor = Color.Transparent;
}
}
在'SetCellsTransparent'下,只需使用'this.DefaultCellStyle'來設置'.BackColor'和(可選 - 但我不會)'.SelectionBackColor'。不需要'foreach'循環。 – OhBeWise 2016-12-22 16:23:35
您需要將所有行和列設置爲透明。更簡單的方法是:
for (int y = 0; y < gridName.Rows[x].Cells.Count; y++)
{
yourGridName.Rows[x].Cells[y].Style.BackColor =
System.Drawing.Color.Transparent;
}
而你需要將其嵌入到另一個循環中才能獲得列... – choudeshell 2009-08-25 18:58:48
以及數據清除視圖本身的背景顏色.. – Moon 2009-08-26 03:28:31
這應該可以在設計期間進行。 – galford13x 2010-03-18 14:26:14
集的DataGridView的背景色相同與窗體的顏色。爲此,請選擇datagridview:轉到屬性 - > RowTemplate - > DefaultCellStyle - > BackColor,然後選擇表單的顏色。
我這樣做與Deumber的解決方案,它的工作原理,但使我避免了通過添加少量的改進一些麻煩:
A.滾動DGV弄亂的背景。解決方案:把這個地方:
public partial class main : Form
{
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}
}
背景仍然會滾動,但在每個滾動步驟後立即糾正。這是顯而易見的,但對我來說是可以接受的。有沒有人知道更好的解決方案來支持滾動? B.設計人員有麻煩使用它。解決方案:
protected override void PaintBackground(Graphics graphics, Rectangle clipBounds, Rectangle gridBounds)
{
base.PaintBackground(graphics, clipBounds, gridBounds);
if (main.ActiveForm != null && this.Parent.BackgroundImage != null)
{
Rectangle rectSource = new Rectangle(this.Location.X, this.Location.Y, this.Width, this.Height);
Rectangle rectDest = new Rectangle(-3, 3, rectSource.Width, rectSource.Height);
Bitmap b = new Bitmap(Parent.ClientRectangle.Width, Parent.ClientRectangle.Height);
Graphics.FromImage(b).DrawImage(this.Parent.BackgroundImage, Parent.ClientRectangle);
graphics.DrawImage(b, rectDest, rectSource, GraphicsUnit.Pixel);
SetCellsTransparent();
}
}
現在,設計師就像DGV一樣對待它。如果你想在沒有ActiveForm的情況下繪製DGV,它會失敗,但情況通常不是這樣。也可以在保留if-line的同時繼續使用設計器,並刪除該版本。
在DataGridView BackGroundColor屬性中具有透明顏色是不可能的。
所以我決定將這個屬性與父母的BackColor同步。的WinForms的好老的數據綁定功能是在這個非常好:
myDataGridView.DataBindings.Add(nameof(DataGrid.BackgroundColor),
this,
nameof(Control.BackColor));
剛過InitializeComponents();
我知道這是很老了,但是這個作品非常好。
- 1. 如何爲DataGrid設置透明背景?
- 2. Ho將JxBrowser背景設置爲透明
- 3. Cocos3d:將CC3Scene背景設置爲透明
- 4. 設置透明背景
- 5. 設置CGContext透明背景
- 6. 設置透明背景
- 7. 設置透明背景Win32
- 8. uisearchbar透明背景視圖
- 9. 爲背景設置常量半透明
- 10. 如何將透明圖像設置爲背景?
- 11. 儘管透明設置爲'true',但沒有透明背景。
- 12. 在xml中設置透明背景視圖
- 13. 如何在GridLayout中將設置的圖像按鈕背景設置爲透明
- 14. 如何將UICollection視圖的背景設置爲透明而不使其中的單元格透明Swift
- 15. 如何設置UITableViewCell背景不透明?
- 16. 設置在android中透明背景alertdialog
- 17. UILabel設置透明背景顏色?
- 18. 設置菜單背景是不透明
- 19. ActionSheet不透明的背景視圖
- 20. iphone sdk透明子視圖背景
- 21. 透明背景透明圖像問題
- 22. 如何在Android中將AutoCompleteTextView下拉背景設置爲透明?
- 23. Google Docs API將透明字體背景設置爲
- 24. 將UILabel的背景設置爲透明黑色
- 25. 我可以將Leaflet背景設置爲透明嗎?
- 26. 如何將CAEmitterLayer背景設置爲透明?
- 27. 如何將UIScrollView的背景設置爲透明?
- 28. 透明背景
- 29. 圖像背景透明GIMP
- 30. 使圖像背景透明
這是設計者的錯誤嗎? – galford13x 2010-03-18 14:25:24