Move controls at runtime

  • Thread starter Thread starter johnb
  • Start date Start date
J

johnb

Hi Guys
I'm trying to get started on allowing the user move a button control around
a Form. For example I have say 30 jobs to do. Each button is a job and
clicking on it will reveal that job's details. The user wants not started
jobs on the left of a Form, those in progress in the middle and completed on
the right.

I don't think it's not a drag and drop job. It's more "Move a control at
runtime" by dragging it

TIA
johnb
 
Hi Guys
I'm trying to get started on allowing the user move a button control around
a Form. For example I have say 30 jobs to do. Each button is a job and
clicking on it will reveal that job's details. The user wants not started
jobs on the left of a Form, those in progress in the middle and completedon
the right.

I don't think it's not a drag and drop job. It's more "Move a control at
runtime" by dragging it

TIA
johnb

Hi,

Refer to my old post that contains code how to move control at
runtime:

http://groups.google.com/group/micr...1e2456c8230?hl=en&q=dragging#f2f7c1e2456c8230

HTH,

Onur Güzel
 
Onur,
That works a treat! But how do I persist(save) those new control postions,
so that when the app is closed and opened the last positions are maintained.

regards
johnb
 
Onur,
That works a treat! But how do I persist(save) those new control postions,
so that when the app is closed and opened the last positions are maintained.

regards
johnb

Hi John,

You have a couple of choices. You can try to use My.Settings by
defining control's Location property's X and Y coordinates.

http://msdn.microsoft.com/en-us/library/saa62613(VS.80).aspx

Plus, just save location's X and Y coordinates in a text-based file
using File.WriteAllText:

http://msdn.microsoft.com/en-us/library/system.io.file.writealltext.aspx

Also, you can find an INI library to group each control's location in
the same way you're storing locations in human-readable format:

http://www.google.com/search?hl=en&...b.net+ini+library&aq=f&aqi=&aql=&oq=&gs_rfai=

You need to apply the settings in Form_Load and save anytime you want,
preferably in Form_Close events.

HTH,

Onur Güzel
 
Thanks Onur
since my last post I've been reading up on this and concluded that MySetting
was an option. I read up on the methods you've outlined.

Thanks once more
johnb
 
Hi Onur,
I'm having trouble getting My.Setting to update. I've added a Setting in the
Project Properties Settings and added New name and call it Test, a Type and
set to string with Scope set to user and Value to "TestOnly"

Then on a Form added a button with the click event set it to
My.Settings.Test = "XXXX" and
My.Settings.Save()

I then closed the project; re-opened it and the Test setting was still
"TestOnly" Any ideas where I'm going wrong?

TIA
johnb
 
Hi Onur,
I'm having trouble getting My.Setting to update. I've added a Setting in the
Project Properties Settings and added New name and call it Test, a Type and
set to string with Scope set to user and Value to "TestOnly"

Then on a Form added a button with the click event set it to
My.Settings.Test = "XXXX" and
My.Settings.Save()

I then closed the project; re-opened it and the Test setting was still
"TestOnly" Any ideas where I'm going wrong?

TIA
johnb

Hi,

Couldn't reproduce it. Are you trying to get settings in Form_Load?
After assigning a new value and after you save, it should run with the
last value you've set. You can easily get the assigned string value
just by calling "My.Settings.Test".

Onur Güzel
 
Onur,
The code is in the Form_Closing event. You've got it to work so I'm going
wrong somewhere but where?? I shall leave it for an hour or 2 and have
another go

I'm after the Location property settings of a control so what should be in
the Type cell in Settings, I selected System.Drawing.Point (and used others
including String)with scope set to user without any success. I've used both
VB.net 05 and 08.

regards
johnb
 
Onur,
 The code is in the Form_Closing event. You've got it to work so I'm going
wrong somewhere but where?? I shall leave it for an hour or 2 and have
another go

I'm after the Location property settings of a control so what should be in
the Type cell in Settings, I selected System.Drawing.Point (and used others
including String)with scope set to user without any success. I've used both
VB.net 05 and 08.

regards
johnb






- Show quoted text -

Ok, here is my full shot for saving location of controls and re-
gaining the location on form_load as follows:

Imagine you're dealing with a button and want to remember its last
position, first off, on project settings page->settings tab, enter
"Button1_X" and "Button1_Y" on "Name" column, set the both's type to
"Integer", leave "Scope" as "User" and "Value" field(s) blank.

Add the following code to your application:

'-----------------------------------------
Private Sub Form1_FormClosing _
(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.FormClosingEventArgs) _
Handles MyBase.FormClosing

With My.Settings
' Assign values of current location's
' just before closing the form
..Button1_X = Button1.Location.X
..Button1_Y = Button1.Location.Y

' Save settings, so they'll
'be rememnbered on next launch
My.Settings.Save()
End With

End Sub

Private Sub Form1_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load

With My.Settings
' Apply saved location settings
' by creating a new instance of Point
Button1.Location = New Point(.Button1_X, .Button1_Y)
End With


End Sub
'-----------------------------------------


Hope this gives some idea,

Onur Güzel
 
Hi Onur
Thanks for the code it worked fine. Where I was going wrong, in the Settings
Value I was expecting to see the saved setting values. Antway over one
problem and on to the next.

Cheers Onur.
 
Back
Top