Click here to Skip to main content
15,889,116 members
Everything / Desktop Programming / Windows Forms

Windows Forms

WinForms

Great Reads

by Josh Smith
A task-oriented review of an animation library and the application which uses it
by Nish Nishant
This articles explains how to implement a TypeDescriptionProvider for a class to support multiple object types using a single class type
by Marc Clifton
Review your project dependencies.
by Nish Nishant
An ExifReader class in C# that supports custom formatting and extraction. StyleCop compliant code, with demos for WPF and Windows Forms.

Latest Articles

by Ralf Meier
The article walks through ShellySceneComponent and ShellyScenesComponent, which allow users to define scenes with multiple actions assigned to a control or controls for Shelly devices.
by Ralf Meier
This article is a continuation of a series on controlling Shelly® devices in a smart home. It introduces a component that works with standard controls without requiring adaptation.
by Graeme_Grant
.NET compliant Silent ClickOnce Update Background Worker Service for Winform, WPF & Console in C# & VB
by Mirnes Mrkaljevic
Make WinForms testable

All Articles

Sort by Updated

Windows Forms 

22 Nov 2011 by #realJSOP
A useful technique that could be used for winform apps which require a login dialog
26 Jan 2011 by #realJSOP
When you need to communicate with the app that contains your ServiceHost object, use custom events
2 Feb 2011 by #realJSOP
How to determine if your .Net app is running in the Visual Studio IDE
19 Feb 2011 by #realJSOP
Determine the number of unique colors in an image
14 Sep 2011 by #realJSOP
How to automatically display a Winforms menu when the mouse is hovered over an item
22 Nov 2011 by #realJSOP
Allow any number of forms to be used as a main form with easy transitions between forms
5 Jul 2016 by _Matt_Wilkinson_
How to centralise a Form when using multiple screens
19 Feb 2011 by a_pess
I think we may check if the color is repeated or not, any how this another alternative but in VB.NetPublic Shared Function GetImageColorsCount(ByVal bitmap As Bitmap) As Integer Dim ColorList As New System.Collections.Generic.List(Of Integer) Dim clr As Integer For...
6 May 2015 by Acharya Raja Sekhar
This tool helps a lot while capturing more number of snapshots. Example: Developers can use this tool to capture the UTR and save all snaps at the end to a Word document or save as individual images.
14 Aug 2013 by adriancs
A program/application for learning and writing HTML. Get instant visual effect side by side with your code as you type. Support HTML5, Javascript and CSS3 elements.
17 Sep 2018 by adriancs
A tool to backup & restore all MySQL databases in one click
17 Aug 2013 by adriancs
An Office 2010 Style Color Picker for .NET WinForm.
11 Jan 2012 by agent154
A method to move rows within a DataTable
28 Nov 2011 by Akos Orban
Set Owner of a WPF Window to a Form
17 Feb 2010 by Alan N
Handling the Popup event raised by the System.Windows.Forms.ToolTip component would seem offer an ideal opportunity to alter the tooltip text to reflect an underlying change. Unfortunately the stack overflow caused by calling ToolTip.SetToolTip will soon put a stop to the attempt.The test...
3 Feb 2011 by Alan N
I use the following to insert pauses into console apps when they are vs hosted. In fact it's the final lines in my standard template for a console app to ensure that the console stays visible until I dismiss it.if (AppDomain.CurrentDomain.FriendlyName.EndsWith("vshost.exe",...
29 Jun 2011 by Alexandros Pappas
Display of a context menu when pressing the Apps key in a DevExpress GridControl
27 Nov 2017 by Altaf Ansari
Converting XML Data into DataTable and Exporting DataTable into Excel File
20 Feb 2011 by Andrew Rissing
Just a few minor improvements to readability and such...The catch/throw isn't needed here, since you are just throwing it without doing anything in the catch block. A try/finally could have been used on its own.The try/finally isn't necessary because a using statement can achieve the same...
12 Jun 2010 by Anshul R
The original snippet I made is in VB.NETProtected Overrides Sub WndProc(ByRef e As Message) MyBase.WndProc(e) If e.Msg = &H84 AndAlso e.Result = &H1 Then e.Result = &H2 End SubI used Reflector to translate it to C#protected override void WndProc(ref Message...
2 Oct 2011 by Anshul R
You can use BackgroundWorker to do the work and report the progress using:private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e){ this.progressBar1.Value = e.ProgressPercentage;}
14 Oct 2012 by AnuragTripathi
Convertor for Unicode to Krutidev and vice-versa.
21 Aug 2011 by Armando de la Torre
How to activate a toolstrip button via a shortcut key
22 Sep 2011 by Armando de la Torre
Use an error log control to validate forms.
2 Aug 2018 by asiwel
Simple C# methods for saving snapshot images of a WinForm to the desktop
28 Jan 2013 by avigodse
This article is created for setting the tab focus on the controls, where the error-provider has error text.
4 Oct 2018 by Awesh Vishwakarma
By reading this trick, you will be able to update your database from DataGridView through external class instead of writing code on each page.
19 Nov 2015 by B.O.B.
A simple extension to add an item that has a data source bound to combobox.items
8 Apr 2015 by basilke7007
How to create rounded edge button (rounded corner button) in Winforms
20 Nov 2011 by Bernhard Hiller
That's far too obscure.All you need to do is store a reference to the TabPage instance which was removed from the TabPages collection of the TabControl. You may use the form where the TabControl is placed for that purpose.You could also create your own TabControl which has an extra property...
2 Dec 2012 by Bikash Karmokar
Connecting Windows Form Application With ADO.NET in C#
15 Jul 2011 by BillWoodruff
An interesting change in behavior in VS 2010 Pro ?
2 Dec 2009 by bobishkindaguy
A simple entry box for various numbers, especially phone numbers.
6 Jul 2011 by Brian C Hart
This tip shows how to add support for New Horizontal Tab Group and New Vertical Tab Group commands to the Window menu of an application using the DockPanel Suite by Weifen Luo, and some other minor improvements to help decided if at least one of your windows is docked to the side of the main form an
7 Oct 2011 by Bruce Lee Harrison
The background method is probably the most preferred method, but I've found this one is very easy to implement, and it's just one short line:BeginInvoke(new Action(() => progressBar1.Increment(1)));Place this in your worker thread to report to the UI. Not sure how "good" this is, but it...
4 Jul 2014 by Chakravarthi Elchuri
How to use WIA supported scanner using C#
19 Mar 2011 by charles henington
Run Only One Copy Of Application
27 Jun 2011 by charles henington
19 Oct 2015 by charles922
Another way to implement Falling Blocks Game
25 Aug 2015 by CharlieFoolsTheComputer
Constraining a form/dialog to a single monitor
18 Dec 2016 by Clivic TR
This are a practical ways to confine inputs into a specific range. The natural thinking is to track them and change. That derives two ways below.
4 Apr 2012 by CodeMajster
A detailed tutorial on how to embed multiple icons and color/animated cursors in VS2010 VB project assembly as native win32 resources.
26 Apr 2012 by coffee_machine
A component to add localized strings to a Form's res'x.
20 Sep 2011 by Ctznkane
Assuming you only want a single instance of a form type, I'd suggest you add a Dictionary(Of Type, Form). ShowOrActiveForm would have a single parameter of Type and would be a subroutine.The Form object could be found based on a ContainsKey. The rest of the ShowOrActiveForm function would be...
14 Oct 2015 by cwfong
Make these controls read-only on WinForm
13 Jul 2010 by Dima Popov
A slightly different solution.using System.Runtime.InteropServices;private const int WM_NCLBUTTONDOWN = 0xA1;private const int HTCAPTION = 0x2;[DllImport("User32.dll")]private static extern bool ReleaseCapture();[DllImport("User32.dll")]private static extern int...
8 Jan 2010 by dwilliss
Another way to do something like this is to handle the RowPrePaint event and change the background there. The advantage to doing it this way is that if you have thousands of rows, you don't have to set it for every row at the beginning, which could take a few seconds. This way only sets it for...
20 Dec 2011 by emolina
Public Sub DisableSound() Dim keyValue As String keyValue = "%SystemRoot%\Media\" If Environment.OSVersion.Version.Major = 5 AndAlso Environment.OSVersion.Version.Minor > 0 Then keyValue += "Windows XP Start.wav" ElseIf Environment.OSVersion.Version.Major = 6 Then ...
25 Mar 2011 by FDW
Maybe this is helpful, it tries to switch to the first running instance:namespace UltraSimple.Win{ static class Program { [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd); [STAThread] ...
6 Oct 2012 by Frans Jan
This article shows how to save a Windows Form to a PDF file.
28 Jun 2011 by George Swan
Couldn't the class RegEdit be replaced by one simple method?private void SetKey(bool enableTaskManager) { using ( var mKey = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System")) {...
4 Feb 2010 by Gordon Kushner
Say you need capture an event for a control in a User Control and you are not permitted to change the control itself.You can hook into control events, even for private controls with this code://In a Windows Form//Get the private control cboSomePrivateControl from the user control's...
14 Jun 2014 by Graham Wilson
A method of ensuring that SplitterContainer controls with fixed panels are properly resized when AutoScaleMode is ScaleMode.DPI
10 Jan 2012 by Grasshopper.iics
I will use a label with font color red just below the text box and will adopt the following code private void textBox1_TextChanged(object sender, EventArgs e) { int min=0,max=256; try { label1.Visible = false; ...
18 Feb 2011 by harbor
Manual Scroll Panel in a Panel or UserControl with AutoScroll=false
8 Jan 2010 by Harvey Saayman
Below is an example of changing the individual row colors based on one of the DataGridView's columns.While this is not hard to do, the property isn't always where you think it should be, its hidden within the rows DefaultCellStyle property.Here's the example:foreach (DataGridViewRow...
16 Nov 2014 by Hassan Mokdad
This is a just a small tip to show a simple way of designing the user interface of Windows Forms for Desktops applications.
26 Aug 2009 by Henry Minute
Never code whilst holding scissors. That is not what is meantby the 'cut' in cut and paste.
29 Apr 2020 by honey the codewitch
This tip shows you how to do UI updates without having to worry about locking.
27 Apr 2012 by Igor Pashchuk, MBA
This is an alternative for "C# Pivot Table"
10 Jul 2014 by IKalai
A Windows Forms toggle button with Android, Windows and iOS like styles.
8 Apr 2011 by intrueder
Extension method to make any WinForms control to be draggable at runtime
24 Jan 2012 by intrueder
Extension method to make it easy to retrieve all nodes of a TreeView control.
6 Mar 2014 by Jacky Yiu
Visual cryptography is a cryptographic technique which allows visual information (pictures, text, etc.) to be encrypted in such a way that the decryption can be performed by the human visual system, without the aid of computers.
14 Oct 2014 by Jamie Highfield
WinForms .NET Time Chooser grid control.
11 Jan 2022 by Jo_vb.net
My idea was to host a WPF user control with Ribbon within a WinForm VB.NET project and try to use MVVM pattern.
13 Jan 2012 by johannesnestler
Nice solution agent154, I'd just suggest to implement it as extension methods for data row: (and I don't liked your "error reporting" with the '0' Value - because '0' could be a valid index). But I have to say, even if you don't have a database behind the datatable you can use sorting (LINQ,...
5 Jul 2013 by Johnny J.
A sample owner-drawn ComboBox
25 Dec 2011 by Juan Davel
Managing Application Scoped Connection Strings
13 Nov 2011 by KazMaxLtd
This article describes how to hide or show TabControl tabs at runtime
28 Apr 2010 by Keith Barrow
If you have a Winforms application that auto loads data, there is no doubt that you’ll have come across the problem of data loading at design time (i.e. when opening the code in the designer). At best, this slows the designer down, at worst it might crash VS and prevent the control from...
23 Aug 2011 by KenBonny
This is nice for non standard buttons (like a CTRL + s), but OK and Cancel buttons have standard implementations in a Windows Form. Look for the properties AcceptButton and CancelButton of a Windows Form (not sure if this applies in ASP.NET or WPF, I need confirmation on that). There you can...
12 Apr 2011 by KevinPorter
How about using a Mutex? This should also work for Terminal Services sessions. Use in Program.csstatic Mutex mut;try{ bool isOwned = false; mut = new Mutex(true, Application.ProductName + " MUTEX: {53A4988C-F91F-4054-9076-220AC5EC03F3}", out isOwned); if (!isOwned)...
20 Sep 2011 by kris444
Showing progress bar while performing time consume processes.
12 Jun 2010 by Kristian Sixhøj
A code snippet which makes a borderless form draggable.
4 Aug 2011 by Lakhan Aanjana
If cell color is depend on criteriaif (ca.con.State == ConnectionState.Closed) { ca.con.Open(); } string qry = "select * From productmaster "; SqlDataAdapter da = new SqlDataAdapter(qry, ca.con); DataSet ds1 =...
30 Jan 2012 by leppie
Here is yet another alternative (originally from http://xacc.wordpress.com/2009/03/05/tree-traversal-extension-methods/[^]):public static class TreeExtensions{ public static IEnumerable TraverseDepthFirst( this T t, Func valueselect, Func
6 Dec 2010 by Luc Schenkeveld
Alternate 3Right click on the taskbar and use "Show Windows Side by Side"
3 Jan 2012 by Lutosław
This method, although it doesn't use binary search, handles Multiline tab pages too.private static intGetTabIndexAt( System.Windows.Forms.TabControl tabControl, System.Drawing.Point point){ int result = -1; if (tabControl != null) { for (int i = 0;...
15 Mar 2015 by manchanx
Tidy, generic solution to bind Enums (with or without a DescriptionAttribute) to a ComboBox or other Controls
3 Oct 2011 by Manfred Rudolf Bihy
Using SendMessage and the PARAFORMAT structure, one can easily change the line spacing in a RichTextBox control
2 Oct 2011 by Manish K. Agarwal
Single Instance Form in a MDI application
7 Jan 2012 by Manish K. Agarwal
Simple Numeric TextBox to accept digits for a given minimum maximum range
30 Nov 2010 by MartinW1307
I have for years used the follow to fetch a window to a visible screen.1. Right click the window on the taskbar and select 'Move' (or use the keystrokes Alt-Space, M)2. Move the mouse a bit3. Press "left arrow"4. Move the mouse around - you will see the window outline ;) 5. left click...
7 Nov 2013 by MayurDighe
This tip describes how to fill the PDF Form Template programmatically
24 Mar 2010 by mdanh2002
Depending on system preferences (in Control Panel/Sounds), the .NET WebBrowser control (just like Internet Explorer) may produce a click sound when changes are made programmatically to its DocumentText property, which is irritating to the user.There are two ways to avoid this:1. Use...
19 Dec 2010 by meaningoflights
Tried it in VB.NET Winforms app, but no luck. It's still shown in the alt-tab menu:Protected Overrides ReadOnly Property CreateParams As System.Windows.Forms.CreateParams Get Dim cp As CreateParams = MyBase.CreateParams cp.ExStyle = cp.ExStyle Or &H80 ...
3 Feb 2012 by Member 147785
Hello!Here is a small article - Show progress on long-running operations, which describes approach to keep the UI responsive, starting long-running operations in separate thread. This approach is native and without any 3d-party libraries and even without BackgroundWorker.For example, the...
21 Dec 2011 by Member 8208766
To me the second method was problematic. After searching, I found an apparently equally good solution:webBrowser1.DocumentText = text;or in your case:webBrowser1.Document.Write("Hello, world!");from here:...
23 Sep 2016 by Midi_Mick
This is an alternative for "Resolve DesignMode for a user control"
26 Oct 2016 by Midi_Mick
An edit control for the masked input of GUIDs
15 Nov 2015 by Midi_Mick
The simplest solution for adding a custom collection of custom objects to the designer
30 Nov 2011 by mohanaitec
WinForm DataGridView loading from ObjectCollection.
18 Dec 2013 by Nanda Kumar Chintam
Demonstration of Excel manipulations using C#
29 Mar 2011 by Neil A. Harding
I actually use code like this, which allows me to detect a existing instance and to call the original instance with the command line (I expand any filenames present so that it can access the filenames even if the original path is different).string processName =...
24 Jan 2011 by Nejimon CR
Make irregular splash screens without writing a single line of code!
21 Mar 2011 by Nitin Singh India
People wonder how do delegates work and the threading issues associated with multicast ones.
18 Nov 2010 by ola halvorsen
When going from a multimonitor environment to a single monitor, windows get stuck on the other screens