Dragging a RadTitleBar

5 posts, 1 answers
  1. Espen
    Espen avatar
    11 posts
    Member since:
    Jan 2008

    Posted 25 Jan 2008 Link to this post

    Is there a way to know when a user is dragging a RadTitleBar around?

    I tried to have a ShapedForm with a RadTitleBar, and catch the events in the MouseDown and MouseUp events for the titlebar with the following :

    private void radTitleBar1_MouseDown(object sender, MouseEventArgs e)  
    {  
        if (e.Button == MouseButtons.Left)  
        {  
            txtTest.Text = "Down";  
        }  
    }  
     
    private void radTitleBar1_MouseUp(object sender, MouseEventArgs e)  
    {  
        if (e.Button == MouseButtons.Left)  
        {  
            txtTest.Text = "Up";  
        }  
    }  
     

    The problem is that I don't always get the MouseUp event. I get the event about once every 20 times I tried it. Is there a problem with the mouseup event, or is there another way I can get the info about the start/stop of dragging a form around?
  2. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 28 Jan 2008 Link to this post

    Hello Espen,

    Thank you for this question.

    RadTitleBar sends notification messages directly to the form below. The only way to capture these messages is  overriding the WndProc method of the Form. I suggest you captur the WM_NCLBUTTONDOWN or the WM_WINDOWPOSCHANGED message.

    Consider the following code snippet:

    public const int WM_WINDOWPOSCHANGED = 0x47; 
     
    protected override void WndProc(ref Message m) 
        if (m.Msg == WM_WINDOWPOSCHANGED) 
        { 
            this.label1.Text = Control.MousePosition.ToString(); 
        } 
     
        base.WndProc(ref m); 
     

    Please tell us if this solves your issue. We will be glad to help you further.

    Regards,
    Jack
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Espen
    Espen avatar
    11 posts
    Member since:
    Jan 2008

    Posted 28 Jan 2008 Link to this post

    I got the same problem when I tried to override the WinProc.

    A quick test can be created by opening up a modal dialog based on the ShapedForm with an added RadTitleBar and override the WindProc with :

    protected override void WndProc(ref Message m)  
    {  
        if(m.Msg == WM_NCLBUTTONUP)  
        {  
            Opacity = 1.0;  
        }  
        if (m.Msg == WM_NCLBUTTONDOWN)  
        {  
            Opacity = 0.85;  
        }  
        base.WndProc(ref m);  
    }  
     

    When you start dragging (or rather, when you click the header) I get the down message, and opacity is set to 85%. But when I stop the drag and release the mouse I don't get the ButtonUp message.

    I can't just override the WindowPosChanged because I need to do some calculations when you 'enter' drag mode and also when you 'leave' drag mode.
  5. Answer
    Jack
    Admin
    Jack avatar
    2335 posts

    Posted 28 Jan 2008 Link to this post

    Hello Espen,

    Thank you for this detailed description.

    I understand the issue. You can monitor this process by using the MouseMove event of the RadTitleBar. Refer to the code snippet below:

    const int WM_NCLBUTTONDOWN = 0xa1; 
    const int HTCAPTION = 2; 
     
    void radTitleBar1_MouseMove(object sender, MouseEventArgs e) 
        if (e.Button == MouseButtons.None) 
        { 
            this.Opacity = 1; 
        } 
     
    protected override void WndProc(ref Message m) 
        if (m.Msg == WM_NCLBUTTONDOWN && m.WParam == (IntPtr)HTCAPTION) 
        { 
            this.Opacity = 0.5; 
        } 
     
        base.WndProc(ref m); 
     

    Let us know if you have other questions.

    Sincerely yours,
    Jack
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Espen
    Espen avatar
    11 posts
    Member since:
    Jan 2008

    Posted 29 Jan 2008 Link to this post

    Perfect. That worked like a charm.
Back to Top
UI for WinForms is Visual Studio 2017 Ready