473,799 Members | 3,209 Online
Bytes | Software Development & Data Engineering Community
+ 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 ListBox1MouseDo wn(object sender, System.Windows. Forms.MouseEven tArgs e)
{
int xOffset;
int yOffset;

if(e.Button == MouseButtons.Le ft)
{
xOffset = -e.X - SystemInformati on.FrameBorderS ize.Width;
yOffset = -e.Y - SystemInformati on.CaptionHeigh t -
SystemInformati on.FrameBorderS ize.Height;
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
}
}

void ListBox1MouseMo ve(object sender, System.Windows. Forms.MouseEven tArgs e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePo sition;
mousePos.Offset (mouseOffset.X, mouseOffset.Y);
listBox1.Locati on = mousePos;
}
}

void ListBox1MouseUp (object sender, System.Windows. Forms.MouseEven tArgs e)
{
isMouseDown = false;
}
/*End Code*/
Feb 24 '06 #1
3 2690
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(HTCAPTIO N);

}
--
HTH
Stoitcho Goutsev (100)
"AM Hulshoff" <AM********@dis cussions.micros oft.com> wrote in message
news:CD******** *************** ***********@mic rosoft.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 ListBox1MouseDo wn(object sender, System.Windows. Forms.MouseEven tArgs
e)
{
int xOffset;
int yOffset;

if(e.Button == MouseButtons.Le ft)
{
xOffset = -e.X - SystemInformati on.FrameBorderS ize.Width;
yOffset = -e.Y - SystemInformati on.CaptionHeigh t -
SystemInformati on.FrameBorderS ize.Height;
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
}
}

void ListBox1MouseMo ve(object sender, System.Windows. Forms.MouseEven tArgs
e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePo sition;
mousePos.Offset (mouseOffset.X, mouseOffset.Y);
listBox1.Locati on = mousePos;
}
}

void ListBox1MouseUp (object sender, System.Windows. Forms.MouseEven tArgs 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 SystemInformati on.FrameBorderS ize
to another way to get the origin point
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"AM Hulshoff" <AM********@dis cussions.micros oft.com> wrote in message
news:CD******** *************** ***********@mic rosoft.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 ListBox1MouseDo wn(object sender, System.Windows. Forms.MouseEven tArgs
e)
{
int xOffset;
int yOffset;

if(e.Button == MouseButtons.Le ft)
{
xOffset = -e.X - SystemInformati on.FrameBorderS ize.Width;
yOffset = -e.Y - SystemInformati on.CaptionHeigh t -
SystemInformati on.FrameBorderS ize.Height;
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
}
}

void ListBox1MouseMo ve(object sender, System.Windows. Forms.MouseEven tArgs
e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePo sition;
mousePos.Offset (mouseOffset.X, mouseOffset.Y);
listBox1.Locati on = mousePos;
}
}

void ListBox1MouseUp (object sender, System.Windows. Forms.MouseEven tArgs 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 SystemInformati on.FrameBorderS ize
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
1934
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 handle moving objects around in memory (as is needed in compaction algorithms associated with 'moving collection' aka 'copy collection'). There are a number of ways to handle this without affecting the overarching structure of one's program (albeit...
0
2419
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 desktop. Nothing was changed on the desktop in respect of the configuration but I now get an error which I am unable to fix. I have a statement "Set cat = New ADOX.Catalog" This statement is
4
1565
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 app. It multi-form app that takes in a lot of user input and gives out high end calculations (engineering app). This app is starting to grow beyond the design and becoming very hard to maintian. I was considering moving it to C#. All of our new...
4
2064
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 PictureBox1_Paint1(ByVal sender As System.Object, ByVal Block1 As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint Block1.Graphics.FillRectangle(Brushes.Blue, 0, 0, 25, 30) Block1.Graphics.FillRectangle(Brushes.Blue, 25, 0, 25, 30)
2
2287
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 TreeView can be expanded/contracted to fill the available space. But there seems tb some sort of chicken-and-egg problem with objects within the TabControl. Their coordinates are expressed relative to the form instead of the TabControl and...
1
1859
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 wanted to be able when I point my mouse on any of them to replace it with another picture. It is pretty straight forward to do that in html coding as I found out these days, but when I tried to use a onmouseover event in the javascript that creates...
1
2363
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 negative values either defining the <style> of the img object or in the Javascript function that produces the image movement, but it doesn't work. The starting point from the images is always on screen. Anybody can turn on the light?? Thanks! ...
0
1854
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 the country. allows you to easily obtain no obligation moving quotes from local movers, long distance movers, international movers, auto transport, storage rentals and specialty movers. office movers, commercial moving, residential moving, movers...
0
1784
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 the country. allows you to easily obtain no obligation moving quotes from local movers, long distance movers, international movers, auto transport, storage rentals and specialty movers. office movers, commercial moving, residential moving, movers...
0
9546
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10243
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4146
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 we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.