Click here to Skip to main content
15,886,362 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 

4 Nov 2012 by #realJSOP
The classic word game using words and letter scores allowed in Scrabble
24 Jun 2010 by #realJSOP
Create a dynamically resizable wizard form
13 Jan 2010 by #realJSOP
Along with Rick's response, you can also create custom events that you can use to notify subscribed objects of the progress of important events within the thread. I use a thread pool, and custom events and it works great. I also would like to reiterate Rick's recommendation of the use of Invoke...
17 Jan 2010 by #realJSOP
I ended up just putting label controls where I wanted text. I don't think you can label the tick marks in the control itself without overriding it with your own control.Beyond that, the labels you want don't mean the same thing. The tick marks on a track bar control are evenly spaced and...
22 Nov 2011 by #realJSOP
A useful technique that could be used for winform apps which require a login dialog
26 Jan 2010 by #realJSOP
My most often used design pattern is the SWC pattern (Start Writing Code). It has served me well for almost 30 years.
23 Apr 2010 by #realJSOP
It's called "being a programmer" and "thinking about the problem". It's obvious that yiou can't just take your dataset and bind it to a grid because you're not going to get the visuals that you desire. You're going to have to build another structure to hold the data in the way you require,...
2 May 2010 by #realJSOP
Try it this way:Multiple Subsequent Main Forms in C# Apps[^]
25 May 2010 by #realJSOP
Google "microsoft office sdk", and see what you come up with. (I'll give you a hint - there are 1.78 MILLION hits).
28 Sep 2010 by #realJSOP
If you would just use google (I searched for "C# image opacity"), you'd have your answer:http://www.geekpedia.com/code110_Set-Image-Opacity-Using-Csharp.html[^]Not only does it provide a complete method for setting image opacity, but it was the very first result returned in...
5 Oct 2010 by #realJSOP
One way to create a completely random encryption key, and sharing it with a client application
6 Nov 2010 by #realJSOP
private void Sell_FormClosing(object sender, FormClosingEventArgs e){ if (this.DialogResult == false) { if (dgvProducts.Rows != null ) { e.Cancel = (MessageBox.Show("do u really want to close?", "attention", MessageBoxButtons.YesNo,...
6 Nov 2010 by #realJSOP
Yeah, their stuff works. Of course, you probably could have google them and found out what other people have experienced...
10 Nov 2010 by #realJSOP
I wrote this article:Winform Application Login[^]and this tip/trick:Multiple Subsequent "Main" Forms in C# Apps[^]They're in C#, but you shouldn't have any problems adapting them to VB.Net.
19 Nov 2010 by #realJSOP
If you delete/hide the scrollbar, how is the user going to know that he can/should scroll the form, or where he is in relation to the top/bottom of the scrollable area?Use the "Add Comment" link to respond.
10 Dec 2010 by #realJSOP
You can display consecutive forms, allowing each one to live as long as it's needed and then close itself. I wrote a tip/trick about it:Multiple Subsequent "Main" Forms in C# Apps[^]
13 Nov 2011 by #realJSOP
New and improved! Keep an eye on your CodeProject articles and reputation without having to log onto CP.
20 Dec 2010 by #realJSOP
What makes you think we have any better insight than people that work at Microsoft? Depending on what day it is and who's blog you're reading, Microsoft is talking about abandoning WPF, Silverlight, and now, Winforms. I guess we'll all soon be out of a job.
24 Jan 2011 by #realJSOP
I'm writing a WinForms app where I want to show/hide a modeless window at a specific location relative to a control's position of the parent form. Not being able to find anything in the framework that let me do this via google, I started muddling around, and I came up with the following code...
23 Feb 2011 by #realJSOP
I have a WCF service that I've created, and when a client calls one of the service methods, I want to post an event from the service host to the app that instantiated it (NOT to the client app), and have the app that handle those events. I tried this:public class MyService :...
26 Jan 2011 by #realJSOP
When you need to communicate with the app that contains your ServiceHost object, use custom events
1 Feb 2011 by #realJSOP
I have an app that can mostly run as the current non-admin user, but some features of the app (user-activated by way of a button click) need to have admin privileges to work. I want the UAC to pop up when the user tries to use these privileged features, but I don't want to have to run the app...
2 Feb 2011 by #realJSOP
How to determine if your .Net app is running in the Visual Studio IDE
7 Feb 2011 by #realJSOP
Why do you want the click event for the UserControl to fire. Instead, make all of its child controls public so the hosting form can hook their events.You can, of course do what you want by using interopservices and forcing a mouse click event, but the click event is the only event that would...
17 Feb 2011 by #realJSOP
Add a new resource file to your project, create your images, and for each one, set the Copy To Output Directory property to Copy If Newer.That way, if you change any of your images after running the application the first time, your changed images will remain.
19 Feb 2011 by #realJSOP
Determine the number of unique colors in an image
23 Feb 2011 by #realJSOP
While Nish's answer steered me in the right direction, the more precise solution was to add the following attribute to the service declaration:[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
3 Mar 2011 by #realJSOP
Create a static Globals class that holds app-wide data members.public static class Globals{ public static DataSet MyData { get; set; } static Globals() { // initialize MyData property in the constructor with static methods }}This is the way I do it....
19 Mar 2011 by #realJSOP
Are the two different behaviors the way you want it to work, or are you asking why it doesn't work the same when running with or without the debugger? It should work the same regardless of whether or not the debugger is attached to the process.Regarding the Invoke question, there are a few...
23 Mar 2011 by #realJSOP
Handle the TextChanged event for the TextBox.
6 Apr 2011 by #realJSOP
0) Do the permission check before even instantiating the form1) Or you can set the form to be initially hidden (Form.Visible=false;), and only make it visible after the user has been validated.2) Or you can setup a class that performs the validation and generates an event that your...
7 Apr 2011 by #realJSOP
You can add any control to the Controls collection in a form or container.Chances are that you made some critical errors when you changed over from use the Tag property/ArrayList to using the more appropriate collection (Controls).
21 Apr 2011 by #realJSOP
If you requested the file (I assume via the HttpWebRequest or WebClient objects), you should know the name of the file. In any case, just save the file with a temporary name, prompt the user for the name they want to use, and rename the temporary file.
15 May 2011 by #realJSOP
For winforms login:User Login For WinForm Applications[^]For Opening another form after logging in:Multiple Subsequent "Main" Forms in C# Apps[^]
19 May 2011 by #realJSOP
Try this Codeproject article to see if it will help.User Login For WinForm Applications[^]And this semi-related tip/trick may also be applicable to your needs:Multiple Subsequent "Main" Forms in C# Apps[^]BTW, there's no such thing as "sso" with rerspect to winforms (at least...
19 May 2011 by #realJSOP
First, if you're talking about MDI, you're talking about Winforms, because WPF doesn't support MDI. Second, changing system icons is what is commonly referred to as "bad practice". Think about it this way - users are accustomed to the icons we have today. if you go and change those icons, it...
19 May 2011 by #realJSOP
In your selection changed handler, multiply the DesiredSize property of the element by the selected percentage.
3 Jun 2011 by #realJSOP
Use a thread to update the contents of a Label control. When initializtion is completed, abort the thread.
27 Jun 2011 by #realJSOP
First, there's no reason a form should be "busy". Your query should be in its own thread, and should notify the form when it's done via an event. At that point, your form is free to handle other events from other threads, such as a BackgroundWorker. Finally, why on earth do you have a Sleep...
1 Jul 2011 by #realJSOP
You simply can't read that much data at once. You're going to have to be more selective iin the data returned from the query. We have a web page that returns no more than 250 records at a time from a 4-million record table.
18 Jul 2011 by #realJSOP
You need to return the table's primary key column.
29 Jul 2011 by #realJSOP
The only thing I can suggest is that your png image wasn't saved in such a way as to have a transparency color/attribute.
10 Aug 2011 by #realJSOP
From MSDN:When you change the focus by using the keyboard (TAB, SHIFT+TAB, and so on), by calling the Select or SelectNextControl methods, or by setting the ContainerControl..::.ActiveControl property to the current form, focus events occur in the following...
12 Aug 2011 by #realJSOP
The Form has a Loaded event. You can use that handler and enumerate through the controls and if you find a textbox, do whatever you need to do.
12 Aug 2011 by #realJSOP
The "complete" process would go something like this:0) Install Fusion Charts1) Change your code to use Fusion objects instead of ZedGraph.Looks pretty simple to me.
30 Aug 2011 by #realJSOP
Keep more detailed track of your Codeproject reputation points.
20 Sep 2012 by #realJSOP
Keep more detailed track of your Codeproject reputation points.
20 Aug 2011 by #realJSOP
Keep more detailed track of your Codeproject reputation points.
18 Aug 2011 by #realJSOP
If I understand what you're aslking...Since the ListBoxItems collection is a collection of type object, you don't have to cast the object when you add it to the ListBox. Just add this method to your item class:public override string ToString(){ // assuming desiredProperty is a...
4 Sep 2011 by #realJSOP
listbox2.Items is a collection of all of the items in the ListBox. I would cycle through the collection and update the database with each item.foreach (string item in listBox2.Items){ // same the item to the database}
7 Sep 2011 by #realJSOP
0) Put the database code into a thread (a BackgroundWorker object would be suitable)1) Put a ProgressBar on your form.2) Handle the BackgroundWorker Progress event in your form, and update the progress bar.3) Google is your friend.
9 Sep 2011 by #realJSOP
We're not going to write the code for you. Try to implement it yourself and ask questions if you experience any problems. The best help I can give you right now is the URL for google:http://www.google.com[^]
13 Sep 2011 by #realJSOP
So change it to allow two instances, or just remove the mutex and ignore the non-issue.
14 Sep 2011 by #realJSOP
How to automatically display a Winforms menu when the mouse is hovered over an item
8 Oct 2011 by #realJSOP
I've created a custom control that allows me to render an image. This image is supposed to be scalable, which is performed by using an up/down control. The image scales just fine, but when it does, it leaves the original image on the screen along with the rescaled version of it. I've tried a...
10 Oct 2011 by #realJSOP
I'm back. I've got an image that I'm trying to scale, rotate, and move within a user control. The scaling and rotate are working fine, but when I try to move AFTER scaling or rotating, it doesn't quite move like it ought to, and the more it's scaled or rotated, the worse it gets. Here's the...
8 Nov 2011 by #realJSOP
First, why are you creating a winform app? This should be a windows service so that it runs even when there is no user logged onto the system.Second, you should use a thread to perform the task, or even a BackgroundWorker...
22 Nov 2011 by #realJSOP
Allow any number of forms to be used as a main form with easy transitions between forms
1 Dec 2011 by #realJSOP
This Codeproject tip might help:Multiple Subsequent "Main" Forms in C# Apps[^]
8 Dec 2011 by #realJSOP
Use a Panel object, set the BackgroundImage property to your loaded image, and then you can draw on the panel without affecting your background image.
15 Dec 2011 by #realJSOP
Google is your friend. Here's one link I found in less than five seconds:http://www.programmersheaven.com/mb/VBNET/248350/248350/copy-text-from-a-txtbox-to-another-by-drag-n-drop/[^]
16 Dec 2011 by #realJSOP
That's certainly possible. I'm doing something like that in an app I'm writing, and I'll try to formulate an answer you can actually use.In my case, I created a custom control derived from the Panel control. I then overrode the Paint method, and put code in to draw an image in the specified...
19 Dec 2011 by #realJSOP
Of course you can write a program to do that - I've written just such a tool for my own use (and that probably would be completely useless to you). I have to ask - if you're not allowed to use 3rd party programs, why would you be allowed to use something you wrote yourself? We can't even do...
27 Dec 2011 by #realJSOP
You don't "draw" to a PictureBox. You draw to a Bitmap, and display the bitmap in the PictureBox.
25 Feb 2012 by #realJSOP
The best way to do that is to pass a reference for the control to the class in question, like this:public class MyClass{ public void DoSomething(ref ListBox listbox) { ... do something with the listbox contents }}And in your form:myClass.DoSomethingWith(ref...
1 Mar 2012 by #realJSOP
Nope. Your best recourse is to design your form with a minimum and/or maximum size in mind, and use docking and/or anchors in a manner appropriate to your intentions when the form is resized.Once the form is designed, you can compile run the app and see what happens when you resize.Of...
13 Mar 2012 by #realJSOP
That's kinda bad practice. If it were me, I'd move the code in the Load event handler into a separate method, and then call that method from both the Load handler and the button click handler.
30 Jan 2017 by #realJSOP
0) Use a class instead of a struct.1) Use serialization to load/save the xml.
25 Feb 2018 by #realJSOP
The simplest method is to save the data (presumably in a database of some description), and when returning to the parent for, simply reload all the data again. BTW, you should use the designer to specify control properties (like font family, size, and color), because that crap just clutters up...
4 Mar 2018 by #realJSOP
One way to make adding items to a Combo box easier is to override the ToString() method of the collection item, so that it returns the desired property. public class MyItem { public string Name { get; set; } public override string ToString() { return this.Name; } } To...
5 Mar 2018 by #realJSOP
The double-click even is not typically used for a delete action. In pretty much every app I've ever seen/written, deleting an item required the user to right click the desired item(s), and then select "Delete" from the subsequent context menu. Reconsider your design.
18 Mar 2018 by #realJSOP
You didn't provide the other table's name, nor the names of the columns, so substitute where applicable. SELECT a.[my_date_column] FROM dbo.[mytable] AS a RIGHT JOIN dbo.[holiday_dates] AS b ON CONVERT(DATE,a.[my_date_column]) CONVERT(DATE,b.[holiday_date]);
12 May 2018 by #realJSOP
The problem is when you click a button in a row, the row isn't selected until after the button click is handled. If it were me, I'd create a button external of the grid and only enable it when a grid row is selected.
26 Jun 2018 by #realJSOP
This is not the proper place to post this kind of question. Try the Collaboration and Beta Testing[^] forum.
6 Nov 2018 by #realJSOP
should i be doing this with data binding because this is WPF? Yes.
1 Dec 2018 by #realJSOP
I know - it's unfortunate that you have to actually write some code, but that's how it goes. Put a try/catch block around the code that's attempting to insert the new user, and in the catch part, show a message box that shows "User name already exists.", and let that be that. At the same time.
2 Dec 2018 by #realJSOP
I do it this way: SqlConnection conn = null; SqlCommand cmd = null; try { using (conn = new SqlConnection("blah blah")) { conn.Open(); using (cmd = new SqlCommand(...)) { //... your code } } } catch (Exception ex) { //... do something...
28 Mar 2019 by #realJSOP
DON'T USE TIMERS. Timer events are the lowest priority event on a Windows system. Use threading to do this. In fact, try using a BackgroundWorker objecvt to marshall image display. If that doesn't work, move to threading. If you can't manage that, try the React framework (google is your friend).
7 Oct 2019 by #realJSOP
0) As already noted, don't do it that way. 1) Why in the hell are you using a Winforms control in WPF? Just because it "can be done", doesn't mean it should be done. 2) Use the MVVM pattern, and perform appropriate binding(s). You should be able to move your foreach loop into your observable...
30 Nov 2019 by #realJSOP
Well, if EF6 is configured approrpiately, it should create your schema on the app's first usage. An Alternative is to "generate scripts" in your database inside SSMS, and simply run those scripts to create the schema inside the database, and even populate static data in the appropriate tables. ...
28 Mar 2020 by #realJSOP
Visual Studio comes with a tool called "Spy++". Use that to find controls in a given window. To manipulate a control in a window in an external app, you're going to need to use System.Runtime.InteropServices. You're gonna need to search for the...
20 Apr 2020 by #realJSOP
My suggestion is to create a new winforms project in your current solution, and add a reference to your console app assembly to the new winforms solution. At that point, you should be able to access any public class defined in your console app. ...
22 Apr 2020 by #realJSOP
As already stated, we can't give you specific help if you won't share your code. But... 0) If the data is "new", you should be setting the date to a reasonable default, so that saving it ifit's not selected isn't an issue. 1) The date should...
3 Apr 2021 by #realJSOP
Well, your question sucks because you don't mention if one of the keys works, and one of them doesnt. The reason I say this is because based on the code you posted, you're checking Keys.LWin twice. If that's really what your code is doing, you'll...
25 Jul 2021 by #realJSOP
Maintain a list of notifications, and any time that list contains 1 or more items, display the balloon. If there are more than one notification, provide a way for the user to move from one to the next (and back again).
19 Dec 2021 by #realJSOP
From what I could find on google, that dll is 32-bit only. That's why it works when you "prefer 32-bit".
26 Dec 2021 by #realJSOP
There are no "controls" for those dialogs. You have to use the OpenFileDialog class in the Microsoft.Win32 namespace. The PrintDialog is in the System.Windows.Controls namespace
28 Apr 2022 by #realJSOP
Here's an idea. I leave it to you to implement it in your code as appropriate. I use string extension methods to perform the "work". If you're not familiar with extension methods, google is your friend. I also implemented some rudimentary sanity...
21 Jun 2022 by #realJSOP
Your query is malformed... SET @sql_Query = 'Update TPCA set ' IF ISNULL(@POL_NBR, '') '' BEGIN SET @sql_Query = @sql_Query + 'TPCA.POL_NBR=''' + @POL_NBR + ''' END
19 Mar 2014 by $*Developer - Vaibhav*$
if (cntl is TextBox) { TextBox txt = (TextBox)cntl; txt.Text = "";}if (cntl is ComboBox ) { ComboBox cmb = (ComboBox )cntl; cmb.Items.Clear();}
20 Mar 2009 by $enthi£
A simple Google chat ( gtalk ) application using Jabber.Net
7 Nov 2012 by -Dr_X-
Below is a inherited winforms control with two buttons.The code, 'Me.ParentForm.AcceptButton' errors during design time. I've tried the DesignerSerializationVisibility tag as well as the LicenseUsageMode with no luck to prevent it from running when opening a user control that is inherits...
8 Nov 2012 by -Dr_X-
After a bit more research, I found this is a prevalent issue with the work-around below. Basically, avoid having any handles clauses from your base class.Public Class CalculationPanelBase Private Sub CalculationPanelBase_Load(sender As Object, e As EventArgs) Handles...