473,385 Members | 1,798 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.

Allow users to rearrange the form

For a certain app, I'd like the user to be able to move buttons around (I
mean physically move them). The reason isn't really important, but it has
to do with an organizational layout. Anyway, it would be cool if the user
could click a "mode" button which almost makes a portion of the form in
"design view" (showing a grid would be cool too) and lets them move the
buttons around. Seeing code-behind is not what I want here. Just moving
them around.

In a form event, I would then capture the new coordinates for all of the
buttons and save them to a database or XML. Then at next form load, replay
the new locations.

Any hints?

thanks,
Eric
Nov 20 '05 #1
4 2831
You can do this by setting a variable to detect when you're in 'design'
mode and then catching the mouse down event to select which button to move
and then catching the form_mousemove event to change the location of the
button. here's a quick example.

open a new windows app and add 1 checkbox and 1 button. then add the
following code. Run it. Click the checkbox then click the button and move
the mouse around. Click the mouse again and the button stays where you
clicked:

Public down As Boolean = False
Public ReadyToMove As Boolean = False
Public ButtonToMove As Button
Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles CheckBox1.CheckedChanged
'if you're in design mode
If CheckBox1.Checked = True Then
down = True
Else
down = False
ReadyToMove = False
End If

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If down = True Then
ButtonToMove = Button1
ReadyToMove = True
End If
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If down And ReadyToMove Then
ButtonToMove.Location = New Point(Cursor.Current.Position.X -
Form1.ActiveForm.Location.X, Cursor.Current.Position.Y -
Form1.ActiveForm.Location.Y)
End If
End Sub
Private Sub Form1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click
If down And ReadyToMove Then
ReadyToMove = False
End If
End Sub

For a certain app, I'd like the user to be able to move buttons around (I
mean physically move them). The reason isn't really important, but it has
to do with an organizational layout. Anyway, it would be cool if the user
could click a "mode" button which almost makes a portion of the form in
"design view" (showing a grid would be cool too) and lets them move the
buttons around. Seeing code-behind is not what I want here. Just moving
them around.

In a form event, I would then capture the new coordinates for all of the
buttons and save them to a database or XML. Then at next form load, replay
the new locations.

Any hints?

thanks,
Eric


Nov 20 '05 #2
"Eric Sabine" <mo*****@hyottmail.com> schrieb
For a certain app, I'd like the user to be able to move buttons
around (I mean physically move them). The reason isn't really
important, but it has to do with an organizational layout. Anyway,
it would be cool if the user could click a "mode" button which almost
makes a portion of the form in "design view" (showing a grid would be
cool too) and lets them move the buttons around. Seeing code-behind
is not what I want here. Just moving them around.

In a form event, I would then capture the new coordinates for all of
the buttons and save them to a database or XML. Then at next form
load, replay the new locations.

Any hints?


In addition to Steve's answer, another suggestion:
When the user switches to "design mode", disable the form and put another
form on top of it at the same location. This second form can be used as a
"designer". It doesn't contain controls but it handles the mouse events to
move the controls. It does not really contain controls, but paints
rectangles instead of the controls. You could pass the first form to the
second, and the second can take all control information from the first.
--
Armin

Nov 20 '05 #3
Very cool! thanks

"Steve DuMosch [MSFT]" <sd******@online.microsoft.com> wrote in message
news:$W**************@cpmsftngxa06.phx.gbl...
You can do this by setting a variable to detect when you're in 'design'
mode and then catching the mouse down event to select which button to move
and then catching the form_mousemove event to change the location of the
button. here's a quick example.

open a new windows app and add 1 checkbox and 1 button. then add the
following code. Run it. Click the checkbox then click the button and move the mouse around. Click the mouse again and the button stays where you
clicked:

Public down As Boolean = False
Public ReadyToMove As Boolean = False
Public ButtonToMove As Button
Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
'if you're in design mode
If CheckBox1.Checked = True Then
down = True
Else
down = False
ReadyToMove = False
End If

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If down = True Then
ButtonToMove = Button1
ReadyToMove = True
End If
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If down And ReadyToMove Then
ButtonToMove.Location = New Point(Cursor.Current.Position.X -
Form1.ActiveForm.Location.X, Cursor.Current.Position.Y -
Form1.ActiveForm.Location.Y)
End If
End Sub
Private Sub Form1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click
If down And ReadyToMove Then
ReadyToMove = False
End If
End Sub

For a certain app, I'd like the user to be able to move buttons around (I
mean physically move them). The reason isn't really important, but it hasto do with an organizational layout. Anyway, it would be cool if the usercould click a "mode" button which almost makes a portion of the form in
"design view" (showing a grid would be cool too) and lets them move the
buttons around. Seeing code-behind is not what I want here. Just moving
them around.

In a form event, I would then capture the new coordinates for all of the
buttons and save them to a database or XML. Then at next form load, replaythe new locations.

Any hints?

thanks,
Eric

Nov 20 '05 #4
Thanks too Armin
"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
"Eric Sabine" <mo*****@hyottmail.com> schrieb
For a certain app, I'd like the user to be able to move buttons
around (I mean physically move them). The reason isn't really
important, but it has to do with an organizational layout. Anyway,
it would be cool if the user could click a "mode" button which almost
makes a portion of the form in "design view" (showing a grid would be
cool too) and lets them move the buttons around. Seeing code-behind
is not what I want here. Just moving them around.

In a form event, I would then capture the new coordinates for all of
the buttons and save them to a database or XML. Then at next form
load, replay the new locations.

Any hints?


In addition to Steve's answer, another suggestion:
When the user switches to "design mode", disable the form and put another
form on top of it at the same location. This second form can be used as a
"designer". It doesn't contain controls but it handles the mouse events to
move the controls. It does not really contain controls, but paints
rectangles instead of the controls. You could pass the first form to the
second, and the second can take all control information from the first.
--
Armin

Nov 20 '05 #5

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

Similar topics

0
by: tommazzo | last post by:
I'm currently writing a photo album sotware in C#. I'm using a ListView component to diaplay thumbnail previews of the photos and want to give the user the possibility to rearrange the photos via a...
2
by: Danny | last post by:
How to allow users to select a set of records and then let them change a field for all these records at once? I would like to do this in code on a form. I will have a form with tabular view of...
6
by: Cro | last post by:
Dear Access Developers, The 'Allow Additions' property of my form is causing unexpected results. I am developing a form that has its 'Default View' property set to 'Continuous Forms' and am...
11
by: tlyczko | last post by:
Hello Rob B posted this wonderful code in another thread, http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/c84d8538025980dd/6ead9d5e61be85f0#6ead9d5e61be85f0 I could not...
5
by: profdotnet | last post by:
Below is the code of web.config file: <configuration> <system.web> <authentication mode="Forms" /> <authorization> <allow users="Admin"/> <deny users="Jack,Mary" /> <deny users="?">...
5
by: deekay | last post by:
I want to allow users to resize and reposition columns of a datasheet but for a prompt to be brought up and only the layout only to be saved if they select "save changes". This is the way it works...
5
by: freelancex | last post by:
Hi, Im new to this forum, and new to scripting in general. Im an ICT Technician for a high school and i am designing a Form in visual basic 2005. The intended purpose of the Form, is to prevent...
2
by: laxwrestler27 | last post by:
Hello everyone, I'm creating a program for a courier service that takes info from a database to make a 2d array with the necessary info, then puts that on to an excel spreadsheet per delivery. ...
2
by: =?Utf-8?B?S2F5xLFoYW4=?= | last post by:
i have a datagridview on my Form. When i maximize form ,datagridview remains in its initial size. i want it rearrage itself with parent form. is it possible to solve on v.studio design mode ...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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...

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.