This is a migrated thread and some comments may be shown as answers.

Dragging a RadTitleBar

4 Answers 63 Views
TitleBar
This is a migrated thread and some comments may be shown as answers.
Espen
Top achievements
Rank 1
Espen asked on 25 Jan 2008, 05:39 PM
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?

4 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 28 Jan 2008, 01:05 PM
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
0
Espen
Top achievements
Rank 1
answered on 28 Jan 2008, 01:37 PM
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.
0
Accepted
Jack
Telerik team
answered on 28 Jan 2008, 06:55 PM
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
0
Espen
Top achievements
Rank 1
answered on 29 Jan 2008, 11:02 AM
Perfect. That worked like a charm.
Tags
TitleBar
Asked by
Espen
Top achievements
Rank 1
Answers by
Jack
Telerik team
Espen
Top achievements
Rank 1
Share this question
or