VB version here.

Someone posted a question recently asking how to set the initial location of a ColorDialog. I originally posted that it wasn't possible and you'd have to use the Windows API to get the window's handle and move it yourself. I recently discovered that that's not strictly true. You do have to work with unmanaged code but you can do it within a class derived from your common dialogue of choice. Here's an example that answers the aforementioned question:
CSharp Code:
  1. using System;
  2. using System.Drawing;
  3. using System.Runtime.InteropServices;
  4. using System.Windows.Forms;
  5.  
  6. namespace MyProject
  7. {
  8.     /// <summary>
  9.     /// Extends the ColorDialog class and allows the initial location of the window to be specified.
  10.     /// </summary>
  11.     public class ColorDialogEx : ColorDialog
  12.     {
  13. #region Types
  14.  
  15.         /// <summary>
  16.         /// Defines values that can be assigned to the Flags field of a WindowPos object.
  17.         /// </summary>
  18.         [Flags()]
  19.         private enum WindowPosFlags : uint
  20.         {
  21.             NoResize = 0x1,
  22.             NoMove = 0x2,
  23.             NoZOrder = 0x4,
  24.             NoRedraw = 0x8,
  25.             NoActivate = 0x10,
  26.             FrameChanged = 0x20,
  27.             ShowWindow = 0x40,
  28.             HideWindow = 0x80,
  29.             NoCopyBits = 0x100,
  30.             NoOwnerZOrder = 0x200,
  31.             NoSendChanging = 0x400,
  32.             DeferErase = 0x2000,
  33.             AsyncWindowPos = 0x4000
  34.         }
  35.  
  36.         /// <summary>
  37.         /// Received as the lParam value when a WM_WINDOWPOSCHANGING message is received.
  38.         /// </summary>
  39.         private struct WindowPos
  40.         {
  41.             public IntPtr HWnd;
  42.             public IntPtr HWndInsertAfter;
  43.             public int X;
  44.             public int Y;
  45.             public int Cx;
  46.             public int Cy;
  47.             public WindowPosFlags Flags;
  48.         }
  49.  
  50. #endregion // Types
  51.  
  52. #region Constants
  53.  
  54.         /// <summary>
  55.         /// The message received when the window position is changing.
  56.         /// </summary>
  57.         private const int WM_WINDOWPOSCHANGING = 0x46;
  58.  
  59. #endregion // Constants
  60.  
  61. #region Variables
  62.  
  63.         /// <summary>
  64.         /// The location at which the window will be initially displayed.
  65.         /// </summary>
  66.         /// <remarks>
  67.         /// If no value is assigned the window is displayed at the default location.
  68.         /// </remarks>
  69.         private Point? initialLocation = null;
  70.  
  71. #endregion // Variables
  72.  
  73. #region Constructors
  74.  
  75.         /// <summary>
  76.         /// Creates a new instance of the ColorDialogEx class.
  77.         /// </summary>
  78.         public ColorDialogEx()
  79.             : base()
  80.         {
  81.         }
  82.  
  83.         /// <summary>
  84.         /// Creates a new instance of the ColorDialogEx class.
  85.         /// </summary>
  86.         /// <param name="initialLocation">
  87.         /// The location at which the window will be initially dispalyed.
  88.         /// </param>
  89.         public ColorDialogEx(Point initialLocation)
  90.             : this()
  91.         {
  92.             this.initialLocation = initialLocation;
  93.         }
  94.  
  95. #endregion // Constructors
  96.  
  97. #region Methods
  98.  
  99.         /// <summary>
  100.         /// Hooks into the common dialog's message queue.
  101.         /// </summary>
  102.         /// <param name="hWnd">
  103.         /// The handle to the native window.
  104.         /// </param>
  105.         /// <param name="msg">
  106.         /// The message received from the operating system.
  107.         /// </param>
  108.         /// <param name="wparam">
  109.         /// Message-specific data.
  110.         /// </param>
  111.         /// <param name="lparam">
  112.         /// Message-specific data.
  113.         /// </param>
  114.         /// <returns>
  115.         /// A zero value if the default dialog box procedure processes the message; a nonzero value if the default dialog box procedure ignores the message.
  116.         /// </returns>
  117.         protected override IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
  118.         {
  119.             // Trap the WM_WINDOWPOSCHANGING message if an initial location has been specified.
  120.             if (msg == WM_WINDOWPOSCHANGING && this.initialLocation.HasValue)
  121.             {
  122.                 // Get the data provided by the OS.
  123.                 WindowPos pos = (WindowPos)Marshal.PtrToStructure(lparam, typeof(WindowPos));
  124.  
  125.                 // Look for the specific combination of flags that indicates that
  126.                 // this is the appropriate message on which to set the location.
  127.                 if (pos.Flags == (WindowPosFlags.NoResize | WindowPosFlags.NoZOrder | WindowPosFlags.NoActivate))
  128.                 {
  129.                     pos.X = this.initialLocation.Value.X;
  130.                     pos.Y = this.initialLocation.Value.Y;
  131.  
  132.                     // Make the new data available to unmanaged code.
  133.                     Marshal.StructureToPtr(pos, lparam, true);
  134.                 }
  135.             }
  136.  
  137.             // Pass on the message.
  138.             return base.HookProc(hWnd, msg, wparam, lparam);
  139.         }
  140.  
  141. #endregion // Methods
  142.     }
  143. }
Note that there were six WM_WINDOWPOSCHANGING messages received before the window was fully loaded and I found the correct combination of flags by trial and error. That combination is received on the second of those six messages. If you try to set the location on any of the others it doesn't work. Note that this will also not prevent you moving the dialogue by dragging the title bar.

Adapting this idea you can trap any Windows message you want and then use the window's handle to manipulate it using unmanaged code. The HookProc method is a member of the CommonDialog class, so all classes derived from CommonDialog provide this functionality.

One final point to note here is that I've used a Nullable<Point> to store the initial location. If it has no value then the default location is used. In .NET 1.x you don't have Nullable types so you'd have to use two variables: one Point and one Boolean.