Convert Handle to Form, and Vice Versa

3 Comments »

This is one of those things that’s obvious once you know it.  When dealing with COM, there is often a need to convert a WinForms Form object to an IntPtr handle, and vice versa.

Read the rest of this entry »

NotifyIcon.ShowBalloonTip Issues

13 Comments »

NotifyIcon is .NET’s version of the system tray icon, those little icons that appear next to the clock in the Windows Start bar.  .NET 2.0 added the ability to display a pop-up balloon tip pointing at a tray icon.  However, this capability doesn’t always work as you would expect.

Read the rest of this entry »

See All Key Events with KeyPreview

4 Comments »

Handling keyboard shortcuts in your application can sometimes get a bit tricky.  Consider the standard Ctrl+C shortcut, which every application should support as a “Copy” to clipboard command.  When you users type in textboxes in your application’s form, they will expect that Ctrl+C will copy the selected text.  But this feature is not supported by default; you have to explicitly write some code.

Read the rest of this entry »

Enter Key in DataGridView

16 Comments »

The DataGridView is a terrific control built into .NET that provides a customizable table for entering and displaying data. If you provide the DataGridView in your software as a means for the user to enter multiple rows of data, you may wish to redefine the default behavior of the Enter key. Read the rest of this entry »

Hide Form from Alt+Tab

33 Comments »

When you show a .NET Form, by default the form will appear in the Windows Start bar and in the list of open windows shown when the user presses Alt+Tab.

Read the rest of this entry »

Console Output from a WinForms Application

45 Comments »

You may wish to enable your WinForms application to run from a console window or command line. And when it does, you probably want to send output messages to the console window that launched your WinForms application.

Unfortunately Console.WriteLine()–the standard method of writing to the console window–by default will not work from a WinForms application. That’s because the console window that launched your WinForms application belongs to the cmd.exe process, which is separate from your WinForms application process.

Read the rest of this entry »

Embedded Image Resources

15 Comments »

If you use images in a .NET application, chances are you will find it more convenient to embed those images as resources in your project, rather than leaving them as separate files and trying to locate and load the images from disk when the application runs.

Read the rest of this entry »

DoDragDrop is Synchronous

5 Comments »

The DoDragDrop method on a control is synchronous. This means that when you call DoDragDrop to start a drag operation, the program will not return and execute the rest of your handler code until the user 1) drops the data she is dragging, or 2) cancels the drag operation. This is one of those little facts that you need to file away in your brain, as it could have a profound effect on your drag & drop logic.

Read the rest of this entry »

Visual Studio “Orcas” and .NET 3.5 Beta Available

No Comments »

Microsoft has released a beta version of the next major release of Visual Studio and the .NET framework.

Visual Studio “Orcas” will enable developers to write programs that can run on Windows Vista, Longhorn Server, Office 2007 and the Web. The .NET Framework v3.5 will provide better support for Web 2.0 and AJAX applications. Microsoft has been planning to release Orcas this year, but a corporate VP recently told ZDNet that it may not happen until 2008.

Read the rest of this entry »

Prevent Beep for TextBox Enter

4 Comments »

Typically when you press the Enter key while typing in a TextBox control, you will hear the computer beep.

To prevent this beep, handle the Enter key in the KeyPress event, and set the Handled property to true. For example:

Read the rest of this entry »

« go back