Posts

Donate

How To Apply Fore Color Or Font Weight To DataGridView Cell

Here's the code to apply font weight and font color to your datagridview cell. DataGridViewCellStyle style = new DataGridViewCellStyle(); style.ForeColor = Color.Red; style.Font = new Font( this .Font, FontStyle.Bold); dg.Rows[dg.Rows.Count - 1].Cells[i + 2].Style = style;

Check If Mouse Coordinate Is Outside The Form Coordinates In Mouseup Event In C#

This snippet will check if mouse coordinate is outside the form coordinates in mouseup event using the object's ClientRectangle property. private void dgvScriptsTime_MouseUp( object sender, MouseEventArgs e) { if (! this .ClientRectangle.Contains(e.Location)) { FShowGrid showGrid = new FShowGrid( "Test" , dgvScriptsTime); showGrid.ShowDialog(); } }

Show Sql Server Instance On The Network In ASP.NET Web Forms

The key is the SqlDataSourceEnumerator to display all instances. You can use gridview or ajax controls for display purposes. protected void Page_Load( object sender, EventArgs e) { // Retrieve the enumerator instance and then the data. SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance; System.DataDataTable table = instance.GetDataSources(); // Display the contents of the table. DisplayData(table); } private void DisplayData(System.DataDataTable table) { foreach (System.DataDataRow row in table.Rows) { foreach (System.DataDataColumn col in table.Columns) { Response.Write(String.Format( "{0} = {1}<br>" , col.ColumnName, row[col])); } } }

Save RGB Color To SolidBrush Object In C#

To save a RGB color to a Solidbrush object, pass the RGB color in the solidbrush constructor. SolidBrush brush = new SolidBrush(Color.FromArgb(211, 222, 229)); Then apply it in your graphics method. evs.Graphics.FillRectangle(brush, evs.CellBounds); Cheers!

Graphic Lines In Picture Box Gone After Switching Tab Pages In C#

In a program i'm working with, I have a timer event which draws lines or graphs on a picture box. This picture box is inside a tab and panel. When I switched views to other tabs and return to the tab that has the picture box, the previous lines or graphs disappears. I suspect, the controls are redrawn when switching tabs. I tried several solutions and options in picture box paint event and infact tried overriding it. Same results. Luckily, I found a tip in an article to draw the real time graphics on the image itself. This helped solve the issue. Greg

Limit Flickering On Winforms In C#

Here's the snippet to limit flicker in forms. Put it above the initialize component method in your constructor. //limit flicker SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true ); InitializeComponent(); Cheers! Source: mijalko

Process Memory Usage Percentage Not Computing Properly In C#

In a scenario when i want to compute the percentage of a process memory consumption against the total memory installed, I encountered a logic error where in the result is zero. The simple formula is this: double x = p.PrivateMemorySize64 / installed_memory_pc * 100; However, the result in x is zero. The trick is to convert p.PrivateMemorySize64 and installed_memory_pc to megabytes by dividing each variable with 1048576. 1Mb = 1048576 bytes. The modified formula is: mbInstalledMemory = ( int )installedMemory / 1048576; mbUsage = ( int )p.PrivateMemorySize64 / 1048576; Then you can apply the percentage formula. Cheers!

Enable/Disable ToolstripButton Using Delegates (Thread) In C#

Assuming you will access the toolstrip button from another thread, then here's the code on how to enable or disable ToolstripButton using delegates. delegate void EnableDisableButtonRunDeleg( bool value ); private void EnableDisableButtonRun( bool value ) { if (tsMenu.InvokeRequired) { this .tsMenu.Invoke( new EnableDisableButtonRunDeleg (EnableDisableButtonRun), value ); } else { ToolStripItem ts = tsMenu.Items[0]; ((ToolStripButton)ts).Enabled = value ; } } Cheers!

How To Get Icon From Process In C#

If you want to convert to image, just cast it to a bitmap object. Icon ico = Icon.ExtractAssociatedIcon(process.MainModule.FileName); Source: Stack overflow

Prevent Listview Column From Being Resized In Windows Forms C#

I added the snippet below in the columnwidthchanging event: switch (e.ColumnIndex) { case 0: e.NewWidth = 400; break ; case 1: e.NewWidth = 200; break ; case 2: e.NewWidth = 100; break ; case 3: e.NewWidth = 100; break ; default : break ; } e.Cancel = true ; Where 400, 200, and 100 are the original column sizes.

Donate