none
How to get events at the title bar RRS feed

  • Question

  • How can we get the events fired from the title bar of a window?

    for example how can I get the click event if a user clicks my titlebar?


    The more I study, the more I realize how little I know.
    Tuesday, November 15, 2011 3:55 AM

Answers

  • Win32 API and override WndProc are both great idea.

    As far as I kown, there is no area called title bar or act as a title bar, so we can only intercept nonclient area message,For example the code below will show a messagebox if click on Border of the form.

    const int WM_NCLBUTTONDOWN = 0x00A1;
    
    protected override void WndProc(ref Message m)
    {
        base.WndProc(ref m);
        // no client area
        if (m.Msg == WM_NCLBUTTONDOWN)
        {
            //select tittle area only If (){
           this.Cursor = new Cursor(Cursor.Current.Handle);
           MessageBox.Show("Click");
            //}
        }
    }
    

     

    Another solution is create a custom borderless Form with a title bar.

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us
    Thursday, November 17, 2011 9:21 AM
    Moderator
  • Hi Sheen,

    You might have to use Win32 API for that.I dont think you can capture methods in WinForm domain for title bar click..

    Thanks,

    BR,

    JollyWagoner

    Please mark this as an answer if it solves your problem.

    Tuesday, November 15, 2011 5:46 PM
  • Override WndProc and intercept the non-client messages you want.

    Tuesday, November 15, 2011 5:50 PM

All replies

  • Titlebar is part of a form. This will be handled by form events. You will get the complete list of form events here... http://www.csharp411.com/c-winforms-form-event-order/

    Thanks


    Anirban Bhattacharya (Lead Consultant - ESSPL)
    Tuesday, November 15, 2011 1:31 PM
  • Hi Sheen,

    You might have to use Win32 API for that.I dont think you can capture methods in WinForm domain for title bar click..

    Thanks,

    BR,

    JollyWagoner

    Please mark this as an answer if it solves your problem.

    Tuesday, November 15, 2011 5:46 PM
  • Override WndProc and intercept the non-client messages you want.

    Tuesday, November 15, 2011 5:50 PM
  • Win32 API and override WndProc are both great idea.

    As far as I kown, there is no area called title bar or act as a title bar, so we can only intercept nonclient area message,For example the code below will show a messagebox if click on Border of the form.

    const int WM_NCLBUTTONDOWN = 0x00A1;
    
    protected override void WndProc(ref Message m)
    {
        base.WndProc(ref m);
        // no client area
        if (m.Msg == WM_NCLBUTTONDOWN)
        {
            //select tittle area only If (){
           this.Cursor = new Cursor(Cursor.Current.Handle);
           MessageBox.Show("Click");
            //}
        }
    }
    

     

    Another solution is create a custom borderless Form with a title bar.

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us
    Thursday, November 17, 2011 9:21 AM
    Moderator