For Opecity of datagrid in windows
-
here i am pasting my code now i want that behind this datagrid i want to show some text that should be visible throw the datagrid and that text may be a only text or any label's text behind the datagrid. so want my datagrid as transparent but i have tried. but not succeeded. please help. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class CheckItem : Form { public CheckItem() { InitializeComponent(); } private DataTable Item = new DataTable("CheckItem"); private Label lbl = new Label(); private Label lbl5 = new Label(); //To drag The Form Without Border #region"To drag The Form Without Border" const int WM_NCHITTEST = 0x84; const int HTCLIENT = 0x1; const int HTCAPTION = 0x2; protected override void WndProc(ref System.Windows.Forms.Message m) { switch (m.Msg) { case WM_NCHITTEST: base.WndProc(ref m); if (m.Result.ToInt32() == HTCLIENT) m.Result = new IntPtr(HTCAPTION); break; default: base.WndProc(ref m); break; } } #endregion #region"private void CheckItem_Load" private void CheckItem_Load(object sender, EventArgs e) { try { //Fixing the length and position of windows form. Screen scr = Screen.PrimaryScreen; //this.Left = (scr.WorkingArea.Width - this.Width) / 2; //this.Top = (scr.WorkingArea.Height - this.Height) / 2; this.MaximumSize = new Size(this.Width, this.Height); this.MinimumSize = new Size(this.Width, this.Height); // Label #region"Label" DataGridTableStyle dgStyle = new DataGridTableStyle(); dgStyle.HeaderBackColor = Color.Chocolate; dgStyle.HeaderForeColor = Color.White; dgStyle.HeaderFont = new Font("verdana", 8, FontStyle.Bold); DataGridTextBoxColumn dgItemCode = new DataGridTextBoxColumn(); dgItemCode.ReadOnly = true;
-
here i am pasting my code now i want that behind this datagrid i want to show some text that should be visible throw the datagrid and that text may be a only text or any label's text behind the datagrid. so want my datagrid as transparent but i have tried. but not succeeded. please help. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class CheckItem : Form { public CheckItem() { InitializeComponent(); } private DataTable Item = new DataTable("CheckItem"); private Label lbl = new Label(); private Label lbl5 = new Label(); //To drag The Form Without Border #region"To drag The Form Without Border" const int WM_NCHITTEST = 0x84; const int HTCLIENT = 0x1; const int HTCAPTION = 0x2; protected override void WndProc(ref System.Windows.Forms.Message m) { switch (m.Msg) { case WM_NCHITTEST: base.WndProc(ref m); if (m.Result.ToInt32() == HTCLIENT) m.Result = new IntPtr(HTCAPTION); break; default: base.WndProc(ref m); break; } } #endregion #region"private void CheckItem_Load" private void CheckItem_Load(object sender, EventArgs e) { try { //Fixing the length and position of windows form. Screen scr = Screen.PrimaryScreen; //this.Left = (scr.WorkingArea.Width - this.Width) / 2; //this.Top = (scr.WorkingArea.Height - this.Height) / 2; this.MaximumSize = new Size(this.Width, this.Height); this.MinimumSize = new Size(this.Width, this.Height); // Label #region"Label" DataGridTableStyle dgStyle = new DataGridTableStyle(); dgStyle.HeaderBackColor = Color.Chocolate; dgStyle.HeaderForeColor = Color.White; dgStyle.HeaderFont = new Font("verdana", 8, FontStyle.Bold); DataGridTextBoxColumn dgItemCode = new DataGridTextBoxColumn(); dgItemCode.ReadOnly = true;
I hate to tell you this, but you cannot do what you want to do with the standard controls in the ToolBox. Transparent is not really transparent. When you set the BackColor of a control to Transparent, you're really telling the control to take on the background properties of the controls parent container. You will NOT be able to see any controls sitting behind the DGV. You cannot achieve what you want without custom drawing the DGV. That's not something that I want to think about, let alone do. I think your best shot at success with this would be to implement this in a WPF app, not Windows Forms.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...