Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9118555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:10:54+00:00 2026-06-17T05:10:54+00:00

Possible Duplicate: Setting the start position for OpenFileDialog/SaveFileDialog I’ve to show a ColorDialog, just

  • 0

Possible Duplicate:
Setting the start position for OpenFileDialog/SaveFileDialog

I’ve to show a ColorDialog, just above the button where the user clicked.

Currently I can’t find how to specify this location:

  1. There is no StartPosition/Location properties ( How can I control the location of a dialog when using ShowDialog to display it? )
  2. The constructor only take a windows a parameter and put this in the middle

I need to place it directly above my cursor, specifying a X;Y.

Any idea about how to achieve this?

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:10:55+00:00Added an answer on June 17, 2026 at 5:10 am

    I finally found a way, not the prettiest thing, but it works:

    public class ColorDialogExtension : ColorDialog
    {
        #region private const
        //Windows Message Constants
        private const Int32 WM_INITDIALOG = 0x0110;
    
        //uFlag Constants
        private const uint SWP_NOSIZE = 0x0001;
        private const uint SWP_SHOWWINDOW = 0x0040;
        private const uint SWP_NOZORDER = 0x0004;
        private const uint UFLAGS = SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW;
        #endregion
    
        #region private readonly
        //Windows Handle Constants
        private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
        private static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
        private static readonly IntPtr HWND_TOP = new IntPtr(0);
        private static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
        #endregion
    
        #region private vars
        //Module vars
        private int _x;
        private int _y;
        private string _title = null;
        #endregion
    
        #region private static methods imports
        //WinAPI definitions
    
        /// <summary>
        /// Sets the window text.
        /// </summary>
        /// <param name="hWnd">The h WND.</param>
        /// <param name="text">The text.</param>
        /// <returns></returns>
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        private static extern bool SetWindowText(IntPtr hWnd, string text);
    
        /// <summary>
        /// Sets the window pos.
        /// </summary>
        /// <param name="hWnd">The h WND.</param>
        /// <param name="hWndInsertAfter">The h WND insert after.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <param name="cx">The cx.</param>
        /// <param name="cy">The cy.</param>
        /// <param name="uFlags">The u flags.</param>
        /// <returns></returns>
        [DllImport("user32.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
        #endregion
    
        #region public constructor
        /// <summary>
        /// Initializes a new instance of the <see cref="ColorDialogExtension"/> class.
        /// </summary>
        /// <param name="x">The X position</param>
        /// <param name="y">The Y position</param>
        /// <param name="title">The title of the windows. If set to null(by default), the title will not be changed</param>
        public ColorDialogExtension(int x, int y, String title = null)
        {
            _x = x;
            _y = y;
            _title = title;
        }
        #endregion
    
        #region protected override methods
        /// <summary>
        /// Defines the common dialog box hook procedure that is overridden to add specific functionality to a common dialog box.
        /// </summary>
        /// <param name="hWnd">The handle to the dialog box window.</param>
        /// <param name="msg">The message being received.</param>
        /// <param name="wparam">Additional information about the message.</param>
        /// <param name="lparam">Additional information about the message.</param>
        /// <returns>
        /// A zero value if the default dialog box procedure processes the message; a nonzero value if the default dialog box procedure ignores the message.
        /// </returns>
        protected override IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
        {
            //We do the base initialization
            IntPtr hookProc = base.HookProc(hWnd, msg, wparam, lparam);
            //When we init the dialog
            if (msg == WM_INITDIALOG)
            {
                //We change the title
                if (!String.IsNullOrEmpty(_title))
                {
                    SetWindowText(hWnd, _title);
                }
                //We move the position
                SetWindowPos(hWnd, HWND_TOP, _x, _y, 0, 0, UFLAGS); 
    
            }
            return hookProc;
        }
        #endregion
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: setting up a database for tracking which users have clicked which links?
Possible Duplicate: Setting image src attribute not working in Chrome When user clicks on
Possible Duplicate: position: absolute without setting top/left/bottom/right? Looking at the following code, I have
Possible Duplicate: winapi CreateWindowEx -> create button with user system styles? Hi, I am
Possible Duplicate: Setting the scrollbar position of a ListBox How can I set WPF
Possible Duplicate: Using Git with an existing Xcode project Setting up a git repository
Possible Duplicate: check whether internet connection is available with C# I just want to
Possible Duplicate: Setting a different section for each month with fetchedresultcontroller I am trying
Possible Duplicate: Setting up a cover flow in Android i wish to create a
Possible Duplicate: Setting up a build dependency without using a reference? Is it possible

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.