Skip to main content

Posts

Showing posts from August, 2015

Add Combo box in a cell of DataGridView at Run Time - C#.NET Windows Form

In DataGridView control of windows form we can set the column type " DataGridViewComboBoxColumn " to show combo box in the cells of the column. Sometimes we need to show only a single or few cells having combo box. For this we need to add Combo box to the required cell on run time. Here is the sample code to do the same - //to get the correct cell get value of row and column indexs of the cell  ColIndex = 1;  RowIndex = 1;  DataGridViewComboBoxCell ComboBoxCell = new DataGridViewComboBoxCell();  ComboBoxCell.Items.AddRange("XYZ", "ABC", "PQR");  ComboBoxCell.Value = "XYZ";  datagridview1[ColIndex, RowIndex] = ComboBoxCell; From the above code DataGirdCell at the location (1,1) will be converted to a "DataGridViewComboBoxCell" and combo box will be shown in the cell. It might be possible that to dropdown the combo box multiple mouse clicks are required. To activate combo box on single click fol

Drawing Custom Border Color on a Control in C#.NET Windows Form Application

Sometimes we need to change the border color of a control to match its color with UI. Visual studio designer only allows us to choose borderStyle. To change border color of controls (like panel, DataGrid etc.) we need to write custom code to set the border color of control. Here is the custom code -   private void ControlBorder_Paint(object sender, PaintEventArgs e)         {             try             {                 Control ctrl = sender as Control;                 ControlPaint.DrawBorder(e.Graphics, ctrl.ClientRectangle,                   Color.FromArgb(130, 135,144), ButtonBorderStyle.Solid);                           }             catch (Exception ex)             {                   //write log             }         } Use above paint function in the paint event for the control which requires custom border color.

Create a Custom Tooltip dialog from a Form C# Windows Form Application

  T o show information on any button we can use a form and custom format it to show use it as a tooltip. For example to explain any functionality related to some section we have a long tooltip message. Here we can create a custom tooltip dialog that can show the message in more user friendly way.   To create a custom formatted dialog create a form with following settings -     namespace Project1 { public partial class frmCustomToolTipDlg : Form {   public frmCustomToolTipDlg() { InitializeComponent(); this .FormBorderStyle = FormBorderStyle.None; this .BackColor = Color.FromArgb(50, 50, 50); this .Opacity = 0; fadeTimer = new Timer { Interval = 15, Enabled = true }; fadeTimer.Tick += new EventHandler(fadeTimer_Tick); } void fadeTimer_Tick( object sender, EventArgs e) { if ( this .