473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

how to make control moveable from mouse in windows application.

I have one panel in which i have my control, know i want to move it at run
time using mouse.
Sep 16 '08 #1
2 2444

"Atul Rane" wrote:
I have one panel in which i have my control, know i want to move it at run
time using mouse.
Hi Atul,

Handle the MouseMove/MouseDown/MouseUp events on your control. Keep track
of where the mouse was last and calculate the offset when the MouseButton is
down. Adjust the Location property of the Control accordingly. It will
appear to be draggable.

Something along the lines of ...

OnMouseDown
startPosition = current position

OnMouseMove
if(MouseButtons.Left)
newPosition = current position
offset = newPosition - startPosition
adjustLocation(offset)
startPosition = newPosition

OnMouseUp/OnMouseLeave
startPosition = Point.Empty

--
Happy Coding!
Morten Wennevik [C# MVP]

Sep 16 '08 #2


"Morten Wennevik [C# MVP]" wrote:
>
"Atul Rane" wrote:
I have one panel in which i have my control, know i want to move it at run
time using mouse.

Hi Atul,

Handle the MouseMove/MouseDown/MouseUp events on your control. Keep track
of where the mouse was last and calculate the offset when the MouseButton is
down. Adjust the Location property of the Control accordingly. It will
appear to be draggable.

Something along the lines of ...

OnMouseDown
startPosition = current position

OnMouseMove
if(MouseButtons.Left)
newPosition = current position
offset = newPosition - startPosition
adjustLocation(offset)
startPosition = newPosition

OnMouseUp/OnMouseLeave
startPosition = Point.Empty

--
Happy Coding!
Morten Wennevik [C# MVP]
Thanks Morten
Sep 16 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: simon | last post by:
Is it posible to create moveable panel in asp.net? When user clicks on time link in my dataGrid, I open the panel over the datagrid. If the panel is opened, than data below the panel is not...
5
by: Charles Law | last post by:
Sorry for reposting this question, but I did not get a single answer last time, and I'm sure you guys must have some thoughts on the matter. I have a user control which can be dragged and dropped...
3
by: savage | last post by:
how do i make a window unmovable so its locked in place
2
by: Danny | last post by:
Hi I need to get the handle to the windows control that is directly below the mouse. This must work on any windows application, win32 and dotnet forms. The reason is I would like to highlight...
1
by: celoftis | last post by:
BACKGROUND: I have some PPT slides that have been converted to HTM (ensuring that the show slide animations while browsing checkbox is checked). The original HTM slides have custom animations to...
4
by: Jon Slaughter | last post by:
I've created some custom controls and forms that allow the feature to temporarily transfer focus to a control that has been entered by the mouse. Everything seems to work fine but the problem I...
2
by: ahmed.maryam | last post by:
Hello Everyone, I designed a custom control that is entirely covered by a picture box. I then dragged this custom control onto a windows form application (called main) and I need to handle mouse...
3
by: chandan | last post by:
Hi, Is any way to palce a control(button/label) at a location on webPage in runtime?? In page_load envet I am adding a button on the page in the contol collection of a panel but not able to...
3
VBWheaties
by: VBWheaties | last post by:
In vb.net, I want to allow a user to click and drag a form like what is supported when you click and drag a moveable forms title bar: you click and hold titlebar, then move the mouse, the form moves...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.