SALVAR POSICAO DOS BOTOES NO FORM
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.
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.
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
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
Testei aqui não aconteceu nada.
posta como ficou seu código
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
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
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
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
ok vo deletar e refazer esse codigo.
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
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
que bom disponha.
Tópico encerrado , respostas não são mais permitidas