SALVAR POSICAO DOS BOTOES NO FORM

KELVINCD 20/02/2013 11:21:49
#419395
Bom Dia.
estou usando essas funções para mover um commandButon em meu projeto em tempo de execução como se fosse a área de trabalho de um computador normal.

Option Explicit

Dim MyCount As Integer
Dim MyLeft As Long
Dim MyTop As Long
Dim m_Drag As Boolean
Dim m_StartX As Single, m_StartY As Single

Private Sub Command1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
m_Drag = True
m_StartX = X
m_StartY = Y
MyCount = MyCount + 1

End Sub

Private Sub Command1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If m_Drag Then
Command1(Index).Move Command1(Index).Left + (X - m_StartX), Command1(Index).Top + (Y - m_StartY)
End If
End Sub

Private Sub Command1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
m_Drag = False
Load Command1(MyCount)
With Command1(MyCount)
.Left = MyLeft
.Top = MyTop
Visible = True
.Caption = [Ô]Command1[Ô] & [Ô]([Ô] & MyCount & [Ô])[Ô]
End With
End Sub

So que quando fecho projeto e abro de novo os botões não estão no local onde havia deixado eles. como faço pra salvar eles onde estão.
MARCELO.TREZE 20/02/2013 12:50:13
#419409
grave a posição no registro do windows, ex:

Private Sub Command1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
m_Drag = False
Load Command1(MyCount)
With Command1(MyCount)
.Left = MyLeft
SaveSetting <nome_aplicativo>, [Ô]posicao[Ô], [Ô]left[Ô], Myleft
.Top = MyTop
SaveSetting [Ô]<nome_aplicativo>[Ô], [Ô]posicao[Ô], [Ô]top[Ô], MyTop
Visible = True
.Caption = [Ô]Command1[Ô] & [Ô]([Ô] & MyCount & [Ô])[Ô]
End With
End Sub

no load do form basta chamar a posição, ex:


command1.top = GetSetting ([Ô]<nome_aplicativo>[Ô], [Ô]posicao[Ô], [Ô]top[Ô])
command1.Left = GetSetting ([Ô]<nome_aplicativo>[Ô], [Ô]posicao[Ô], [Ô]left[Ô])

pronto
KELVINCD 20/02/2013 15:23:48
#419427
Testei aqui não aconteceu nada.
MARCELO.TREZE 20/02/2013 16:29:41
#419436
posta como ficou seu código
KELVINCD 20/02/2013 16:32:38
#419437
Private Sub Command1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
m_Drag = False
Load Command1(MyCount)
With Command1(MyCount)
.Left = MyLeft
SaveSetting [Ô]menu[Ô], [Ô]posicao[Ô], [Ô]left[Ô], MyLeft
.Top = MyTop
SaveSetting [Ô]menu[Ô], [Ô]posicao[Ô], [Ô]top[Ô], MyTop
End With
End Sub

Private Sub Form_Load()
Command1(0).Top = GetSetting([Ô]menu[Ô], [Ô]posicao[Ô], [Ô]left[Ô])
Command1(0).Left = GetSetting([Ô]menu[Ô], [Ô]posicao[Ô], [Ô]top[Ô])
End Sub
MARCELO.TREZE 20/02/2013 17:13:49
#419439
Resposta escolhida
primeiro ta invertido as posições o certo é

Command1(0).Top = GetSetting([Ô]menu[Ô], [Ô]posicao[Ô], [Ô][txt-color=#e80000]top[/txt-color][Ô])
Command1(0).Left = GetSetting([Ô]menu[Ô], [Ô]posicao[Ô], [Ô][txt-color=#e80000]lef[/txt-color]t[Ô])

outra coisa vc está criando os botões em tempo de execução isso talvez possa atrapalhar uma vez que o botão ainda não existe
KELVINCD 20/02/2013 17:33:52
#419444
ok vo deletar e refazer esse codigo.
KELVINCD 20/02/2013 17:47:25
#419445
Option Explicit

Dim MyLeft As Long
Dim MyTop As Long
Dim m_Drag As Boolean
Dim m_StartX As Single, m_StartY As Single

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
m_Drag = True
m_StartX = X
m_StartY = Y
End Sub

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If m_Drag Then
Command1.Move Command1.Left + (X - m_StartX), Command1.Top + (Y - m_StartY)
End If
End Sub

Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
m_Drag = False
With Command1
MyLeft = .Left
MyTop = .Top
.Left = MyLeft
SaveSetting [Ô]<nome_aplicativo>[Ô], [Ô]posicao[Ô], [Ô]left[Ô], MyLeft
.Top = MyTop
SaveSetting [Ô]<nome_aplicativo>[Ô], [Ô]posicao[Ô], [Ô]top[Ô], MyTop
End With
End Sub

Private Sub Form_Load()
Command1.Left = GetSetting([Ô]<nome_aplicativo>[Ô], [Ô]posicao[Ô], [Ô]left[Ô])
Command1.Top = GetSetting([Ô]<nome_aplicativo>[Ô], [Ô]posicao[Ô], [Ô]top[Ô])
End Sub

deu certo vlw
MARCELO.TREZE 20/02/2013 23:43:31
#419453
que bom disponha.
Tópico encerrado , respostas não são mais permitidas