cs_andrebernard
Messages postés404Date d'inscriptionlundi 9 juin 2003StatutMembreDernière intervention 4 septembre 2013
-
6 sept. 2007 à 12:50
cs_andrebernard
Messages postés404Date d'inscriptionlundi 9 juin 2003StatutMembreDernière intervention 4 septembre 2013
-
7 sept. 2007 à 14:11
Bonjour à tous
Voila je voudrais pouvoir déposer les données de boutons dans un MsFlexgrid par drag and drop.
Quand je met mon bouton en drag mode = automatic ça marche, mais le probleme c'est que l'on ne voit pas le bouton se déplacer, juste le cadre transparent.
Et quand je le met en drag mode = manual, alors la, le bouton se deplace bien, mais il se depose en entier dans le msflexgrid au lieu que ce soit la couleur et son texte.
Donc, comment faire pour que l'on deplace le bouton en entier avec la souris, et que lorsque l'on relache le bouton dans la flexgrid, le texte et la couleur du bouton se rajoute à la flexgrid et le bouton reprenne sa place initiale.
Private Declare Function ReleaseCapture Lib "User32" () As Long
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal LParam As Any) As Long
Private MaxInstructionDefaut As Integer
Private NomInstructionADeplacer As String
Private CouleurInstructionADeplacer As Long
Public Sub Form_Load()
Me.Show
Dim NomInstruction(100) As String
NomInstruction(1) = "Essai"
NomInstruction(2) = "Essai2"
For i = 1 To 2
CreationBouton NomInstruction(i), 350, 100 + ((i - 1) * 400), 50, 2000, i * 12000
Next
FlexGridInstruction.Visible = True
FlexGridInstruction.Rows = 1
FlexGridInstruction.ColWidth(0) = 9500
FlexGridInstruction.ColAlignment(0) = flexAlignCenterCenter
FlexGridInstruction.Text = "Bonjour je suis une burne en programmation"
End Sub
Private Sub FlexGridInstruction_DragDrop(Source As Control, x As Single, y As Single)
FlexGridInstruction.AddItem NomInstructionADeplacer
FlexGridInstruction.Row = FlexGridInstruction.Row + 1
FlexGridInstruction.CellBackColor = CouleurInstructionADeplacer
End Sub
Private Sub BoutonInstruction_MouseMove(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
NomInstructionADeplacer = BoutonInstruction(Index).Caption
CouleurInstructionADeplacer = BoutonInstruction(Index).BackColor
End Sub
Private Sub BoutonInstruction_MouseDown(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
Call ReleaseCapture
Call SendMessage(BoutonInstruction(Index).Hwnd, &HA1, &H2, ByVal 0&)
End Sub
Public Sub CreationBouton(NomBouton, Haut, y, x, Largeur, CouleurFond)
Index = Programme.BoutonInstruction.Count + 1
Load Programme.BoutonInstruction(Programme.BoutonInstruction.Count + 1)
Programme.BoutonInstruction(Index).Left = x
Programme.BoutonInstruction(Index).Top = y
Programme.BoutonInstruction(Index).Width = Largeur
Programme.BoutonInstruction(Index).Height = Haut
Programme.BoutonInstruction(Index).Caption = NomBouton
Programme.BoutonInstruction(Index).BackColor = CouleurFond
Programme.BoutonInstruction(Index).Visible = True
End Sub
cs_MPi
Messages postés3877Date d'inscriptionmardi 19 mars 2002StatutMembreDernière intervention17 août 201823 7 sept. 2007 à 12:13
Personnellement, que ce soit en DragMode Manual ou Automatic, c'est un rectangle vide qui se promène... (?) Pour voir le contrôle se déplacer, je préfère la commande Move.
Voici un petit exemple simple
Option Explicit
Public CurX As Single, CurY As Single 'pour le mouvement
Public XDepart As Single, YDepart As Single 'pour replacer le bouton
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
CurX = X
CurY = Y
XDepart = Command1.Left
YDepart = Command1.Top
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Command1.Move Command1.Left + (X - CurX), Command1.Top + (Y - CurY)
End If
End Sub
Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Ligne As Single, Colonne As Single
Command1.Left = XDepart
Command1.Top = YDepart
Ligne = Grid1.MouseRow
Colonne = Grid1.MouseCol
Grid1.TextMatrix(Ligne, Colonne) = Command1.Caption
End Sub