473,466 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Moving objects

Can someone tell me how I can move an object, in this case a listbox, over a
form. The code below works, but not when the form is custom sized. It works
perfectly when the form is maximized. And what is the best way to give the
object boundries to move within?

Hope someone can help me.
TIA,
Arjan.

/*Begin Code*/
/*Source: MSDN*/
void ListBox1MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
int xOffset;
int yOffset;

if(e.Button == MouseButtons.Left)
{
xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
yOffset = -e.Y - SystemInformation.CaptionHeight -
SystemInformation.FrameBorderSize.Height;
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
}
}

void ListBox1MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
listBox1.Location = mousePos;
}
}

void ListBox1MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
isMouseDown = false;
}
/*End Code*/
Feb 24 '06 #1
3 2668
AM,

If I were you I would derive a new class from list box and in this new class
I would override WndProc and process WM_NCHITTEST message to return
HTCAPTION. This way the windows will handle all the moving of the cotnrol.

Here is basically how the WndProc can be written:

private const int WM_NCHITTEST = 0x84;
private const int HTCAPTION = 0x2;
private const int HTCLIENT = 0x1;

protected override void WndProc(ref Message m)
{
base.WndProc (ref m);
if(m.Msg == WM_NCHITTEST && m.Result == new IntPtr(HTCLIENT))
{
m.Result = new IntPtr(HTCAPTION);

}
--
HTH
Stoitcho Goutsev (100)
"AM Hulshoff" <AM********@discussions.microsoft.com> wrote in message
news:CD**********************************@microsof t.com...
Can someone tell me how I can move an object, in this case a listbox, over
a
form. The code below works, but not when the form is custom sized. It
works
perfectly when the form is maximized. And what is the best way to give the
object boundries to move within?

Hope someone can help me.
TIA,
Arjan.

/*Begin Code*/
/*Source: MSDN*/
void ListBox1MouseDown(object sender, System.Windows.Forms.MouseEventArgs
e)
{
int xOffset;
int yOffset;

if(e.Button == MouseButtons.Left)
{
xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
yOffset = -e.Y - SystemInformation.CaptionHeight -
SystemInformation.FrameBorderSize.Height;
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
}
}

void ListBox1MouseMove(object sender, System.Windows.Forms.MouseEventArgs
e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
listBox1.Location = mousePos;
}
}

void ListBox1MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
isMouseDown = false;
}
/*End Code*/

Feb 24 '06 #2
Hi,

You should check the current position of the mouse and make sure it's inside
the boundary you want.

You should probably need to change from SystemInformation.FrameBorderSize
to another way to get the origin point
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"AM Hulshoff" <AM********@discussions.microsoft.com> wrote in message
news:CD**********************************@microsof t.com...
Can someone tell me how I can move an object, in this case a listbox, over
a
form. The code below works, but not when the form is custom sized. It
works
perfectly when the form is maximized. And what is the best way to give the
object boundries to move within?

Hope someone can help me.
TIA,
Arjan.

/*Begin Code*/
/*Source: MSDN*/
void ListBox1MouseDown(object sender, System.Windows.Forms.MouseEventArgs
e)
{
int xOffset;
int yOffset;

if(e.Button == MouseButtons.Left)
{
xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
yOffset = -e.Y - SystemInformation.CaptionHeight -
SystemInformation.FrameBorderSize.Height;
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
}
}

void ListBox1MouseMove(object sender, System.Windows.Forms.MouseEventArgs
e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
listBox1.Location = mousePos;
}
}

void ListBox1MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
isMouseDown = false;
}
/*End Code*/

Feb 24 '06 #3
That's what I tried, but everytime I move the object I get the same result.
The boundries is something I won't have much problems with. But that other
part is causing me a headache.

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

You should check the current position of the mouse and make sure it's inside
the boundary you want.

You should probably need to change from SystemInformation.FrameBorderSize
to another way to get the origin point
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Feb 24 '06 #4

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

Similar topics

0
by: HeroOfSpielburg | last post by:
hi, I know this is a much-travelled subject, but I was wondering what people's thoughts were on the bare minimum (and conversely the grand scheme) for augmenting standard memory references to...
0
by: Uttam | last post by:
Hello, I created and worked on my application on my desktop and copied it to my laptop. After putting in many additions to the functionality on the Laptop version, I copied it back to my...
4
by: Ron Mexico | last post by:
Hi, Currently have an app that maintain that is written in VB6 and uses an access db (backend db only used as a data store not writing to the db). This app is a client app not server multi-teir...
4
by: easily confused | last post by:
Ok so im going intomaking a tetris type program and was wondering how i would move the drawing after i have crated the shape for the shape i have this code .... Public Class Form1 Public Sub...
2
by: (PeteCresswell) | last post by:
I've got a form that has a TreeView in the upper part of the form and a TabControl in the lower. When processing a Resize event, the TabControl does not need tb resized - just moved so that the...
1
by: Goutour | last post by:
Hello, I am a 2-day old Javascript developer :-) and I have a problem. I am trying to do examples I find on net about using onmouse events. I found a javascript that generates flying objects, and I...
1
pavlov
by: pavlov | last post by:
Hello everybody. I've this problem: I'm making a jpg moving horizontally from left to right in my page. I'd like to make it start moving from the left off-screen side. I tried using position...
0
by: linkswanted | last post by:
We are your trusted source. World Moving & Storage is bonded and licensed by the U.S. Department of Transportation and is one of the largest residential moving and corporate relocation company in...
0
by: linkswanted | last post by:
We are your trusted source. World Moving & Storage is bonded and licensed by the U.S. Department of Transportation and is one of the largest residential moving and corporate relocation company in...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.