473,385 Members | 1,830 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,385 software developers and data experts.

The Forms in my 'EXE' program seperate when moved

Hello Everybody!
my program is made up of several Forms, and once compiled to an exe, if I were to move it across the desktop, the Forms seperate; can this be prevented?

regards
Tomservo
Mar 18 '07 #1
9 1026
willakawill
1,646 1GB
Hi. What do you mean when you say they separate?
Mar 19 '07 #2
Killer42
8,435 Expert 8TB
Hello Everybody!
my program is made up of several Forms, and once compiled to an exe, if I were to move it across the desktop, the Forms seperate; can this be prevented?
I'm guessing you mean that you want the forms to stick together and move around the desktop in unison.

Off-hand, I can't think of any elegant way to accomplish this, but you could try something like a timer control which keeps watch for the .Top or .Left property changing, and moves the other forms to keep them together. I can think of a couple of things you might want to keep in mind...
  • Don't get into an infinite loop. this could happen if your "form has moved" routine moves the form to catch up, and the movement triggers the "form has moved" routine again.
  • Ordinarily you wouldn’t want the timer to be looping too fast and wasting too many cycles, so I would set the Interval fairly long (250 perhaps?). When it spots a move and triggers the “I’m coming too” routine, you could set the timer interval shorter so that things move a bit more smoothly. Once they stop moving, set it back to the original value.
Hm... this is an interesting one. I’m on lunch right now, so I think I’ll throw together a simple trial program.
Mar 19 '07 #3
Killer42
8,435 Expert 8TB
Okay, I've done that. It's a bit rough, but may be of some interest. The second form actually doesn't snap into position until I drop the first form, but that's probably because I have "show forms while dragging" switched off in my Windows display settings.

If you want to try it, just create a new project, add two forms (default names) then paste this code into the code window for Form1.

Then run it and try dragging form1 around.

Note that it doesn’t have any safeguards against things like re-entering routines.
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. DefLng A-Z
  3.  
  4. Private LatestTop As Single, LatestLeft As Single
  5. Private Const SLOW As Long = 250, FAST As Long = 50
  6.  
  7.  
  8. Private Sub Form_Load()
  9.   With Me
  10.     LatestTop = .Top
  11.     LatestLeft = .Left
  12.     Load Form2
  13.     Form2.Move .Left + .Width, .Top
  14.     Form2.Show
  15.     DoEvents
  16.     .Show
  17.   End With
  18. End Sub
  19.  
  20. Private Sub Timer1_Timer()
  21.   With Me
  22.     If .Top <> LatestTop Or .Left <> LatestLeft Then
  23.       LatestTop = .Top
  24.       LatestLeft = .Left
  25.       Form2.Move .Left + .Width, .Top
  26.       .Timer1.Interval = FAST
  27.     Else
  28.       .Timer1.Interval = SLOW
  29.     End If
  30.  
  31.   End With
  32. End Sub
  33.  
Also, keep in mind that there are probably much better ways of achieving this kind of thing.
Mar 19 '07 #4
willakawill
1,646 1GB
Would this work better in the form click event?
Mar 19 '07 #5
Killer42
8,435 Expert 8TB
Would this work better in the form click event?
I don't think the form click event fires when you drag the form.
Mar 19 '07 #6
willakawill
1,646 1GB
I don't think the form click event fires when you drag the form.
You're right.
Better to subclass the form window and catch the 'moved' windows message.
Download a code sample here
Mar 19 '07 #7
You Guys are Brilliant!
Thankyou!
regards
Tomservo
Mar 19 '07 #8
willakawill
1,646 1GB
You Guys are Brilliant!
Thankyou!
regards
Tomservo
You are welcome. For the record, Killer is brilliant. I am just waiting to be 'found out'.
Mar 19 '07 #9
Killer42
8,435 Expert 8TB
... For the record, Killer is brilliant...
Ahem... you forgot "modest".

How many times do I have to tell everyone... "brilliant, but modest". :p


Incidentally, thank for the link Will - I'll have to check that out.

(Has anyone tried my example with "show window contents while dragging" on?)
Mar 19 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: (Pete Cresswell) | last post by:
I've got a .BAT file that I use for executing various MS Access apps that I wrote way back in the days of 2.0. It's evolved over time, but it still contains a number of possible paths to...
1
by: Alasdair | last post by:
Friends, I'm an old C programmer who upgraded to C++ but was never comfortable with it. I've recently moved to C# and love it but I obviously am missing some of the subtleties. I thought the...
6
by: JonS. | last post by:
Hi, I'm trying to create a Windows Forms portal application and need some help. What I currently have is a main application (.exe) containing an MDI form. The idea is that this main application...
3
by: stumorgan | last post by:
There is probably an extremely simple answer to this question and I'm just being foolish. I have a main form (let's say FormMain) which opens other forms (let's say Form1, Form2). How do I keep...
15
by: Joshua Kendall | last post by:
I have a script in which it keeps opening the same form instead of only one instance. I also need help with a form that has a password. Where do I put the actual password? can I use a database for...
5
by: SenthilVel | last post by:
hi , Where can we physically see gacutil.exe for dotnet2.0 version ? i saw in my machine and its not appearing in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727. Is this gacutil.exe present...
1
by: Chris Taylor | last post by:
Hi, I have a simple c# winforms app which was comprised of two seperate projects - a splash screen and a main app. The main app called the splash screen, which used a Forms.Timer, created on a...
5
by: mmcd79 | last post by:
I built a VB.net application that makes use of a machine level DB connection string setting, and a user level starting location setting. The machine level setting and the default user based...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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?
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...

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.