[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Move a panel with mouse

Posted on 2009-02-20
6
Medium Priority
?
2,466 Views
Last Modified: 2013-12-17
Hi
I am developing a windows application.

I wrote the code on MouseUp,MouseMove n MouseDown event of the panel to move the panel with the help of mouse.

I am able to move the panel whereever I want.

Now the problem is that,I set the calendar in the panel.The calendar occupies the panel fully.
If the panel is visible a little bit and if I try  to move it,calendar n panel,both are moving.
But I don't want to show the panel and now I want to move panel n calendar both.How to do this?
0
Comment
Question by:rajputamitd
  • 4
  • 2
6 Comments
 
LVL 8

Accepted Solution

by:
theplonk earned 1600 total points
ID: 23691376
You can just assign the MouseDown and MouseMove event to the same delegate as the panel. Because you calendar is filling the form, you could just add event hanlders to the calendar to move the panel, rather than redirecting back to the panel. Depends on your purposes.

E.g.
this.panel1.MouseDown += new MouseEventHandler(panel1_MouseDown);
this.panel1.MouseMove += new MouseEventHandler(panel1_MouseMove);
this.monthCalendar1.MouseDown += new MouseEventHandler(panel1_MouseDown);
this.monthCalendar1.MouseMove += new MouseEventHandler(panel1_MouseMove);
private int _mouseX = 0;
private int _mouseY = 0;
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
    _mouseX = e.X;
    _mouseY = e.Y;
}
 
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        this.panel1.Left = this.panel1.Left + (e.X - _mouseX);
        this.panel1.Top = this.panel1.Top + (e.Y - _mouseY);
    }
}

Open in new window

0
 

Author Comment

by:rajputamitd
ID: 23691397
It is not working.
Here is my code.
frDate is panel name.

private void fraDate_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
_mouseDown = true;
_mousePos = new Point(e.X, e.Y);
}
}
private void fraDate_MouseMove(object sender, MouseEventArgs e)
{
if (_mouseDown)
{
fraDate.Location = PointToClient(this.fraDate.PointToScreen(new Point(e.X - _mousePos.X, e.Y - _mousePos.Y)));
}
}
private void fraDate_MouseUp(object sender, MouseEventArgs e)
{
if (_mouseDown)
{
_mouseDown = false;
}
}
0
 

Author Comment

by:rajputamitd
ID: 23691410
the panel is moving with the use of above code.But when I set a calendar in the panel,as I am unable to click on the panel,as Calendar fills whole area.I am not able to move it.
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

Author Comment

by:rajputamitd
ID: 23691463
Hi I tried as u say.
this.monthCalendar1.MouseDown += new MouseEventHandler(panel1_MouseDown);
this.monthCalendar1.MouseMove += new MouseEventHandler(panel1_MouseMove);
 
I changed it accordingly.The calendar moves with panel but when I leave mouse key,panel is invisible.
How?
0
 

Author Comment

by:rajputamitd
ID: 23691480
Ok.
I have sert the visible property of the panel to true on MouseUp.
Thanks For ur help.
0
 
LVL 8

Expert Comment

by:theplonk
ID: 23691957
That's no prob
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question