FORM MAGNETIQUE A LA WINAMP

ManDeq59 Messages postés 55 Date d'inscription dimanche 12 mai 2002 Statut Membre Dernière intervention 6 juillet 2004 - 12 août 2004 à 21:58
goldorakiller Messages postés 16 Date d'inscription mercredi 31 octobre 2007 Statut Membre Dernière intervention 6 juillet 2011 - 23 févr. 2009 à 15:11
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/18457-form-magnetique-a-la-winamp

goldorakiller Messages postés 16 Date d'inscription mercredi 31 octobre 2007 Statut Membre Dernière intervention 6 juillet 2011
23 févr. 2009 à 15:11
parfait comment adapter cela pour des formes entre elles ?
dvdstory Messages postés 192 Date d'inscription dimanche 23 janvier 2005 Statut Membre Dernière intervention 10 août 2009
26 déc. 2005 à 01:41
J'ai un system dual screnn, ce qui veut dire que j'ai 2 écrans.
Mais ton code bloque l'application au premier écran. Il est impossible de passer l'application d'un écran à l'autre.
Donc voici ton code amélioré qui corrige mon problème.
Merci à NetWedge

#Region " Effet Magnétique "
'Début de l'effet magnétique et de déplacement par la form
Dim x As Integer = 10
Dim StartControlPos, StartMousePos As Point
Friend WithEvents unrealnetworkdafuncom As System.Windows.Forms.LinkLabel

Private Sub FormMagnetique_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
If e.Button <> e.Button.Left Then Exit Sub 'On quitte l'évènement si le bouton de la souris gauche n'est pas enfoncé
StartMousePos = Me.PointToScreen(New Point(e.X, e.Y))
StartControlPos = New Point(Me.Left, Me.Top)
End Sub

Private Sub FormMagnetique_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
Dim CurrentScreen As Screen
If e.Button <> e.Button.Left Then Exit Sub 'On quitte l'évènement si le bouton de la souris gauche n'est pas enfoncé
Dim NewMousePos As Point = Me.PointToScreen(New Point(e.X, e.Y))
CurrentScreen = Screen.FromPoint(NewMousePos)
Debug.WriteLine(CurrentScreen.WorkingArea.X & "" & CurrentScreen.WorkingArea.Y)
Dim NewLeft As Long = StartControlPos.X + NewMousePos.X - StartMousePos.X
Dim NewTop As Long = StartControlPos.Y + NewMousePos.Y - StartMousePos.Y
If NewLeft < CurrentScreen.WorkingArea.X + x And NewLeft > CurrentScreen.WorkingArea.X - x Then
NewLeft = CurrentScreen.WorkingArea.X
End If
If NewTop < CurrentScreen.WorkingArea.Y + x And NewTop > CurrentScreen.WorkingArea.Y - x Then
NewTop = CurrentScreen.WorkingArea.Y
End If
If NewLeft + x > CurrentScreen.WorkingArea.X + CurrentScreen.WorkingArea.Width - Me.Width And NewLeft - x < CurrentScreen.WorkingArea.X + CurrentScreen.WorkingArea.Width - Me.Width Then
NewLeft = CurrentScreen.WorkingArea.X + CurrentScreen.WorkingArea.Width - Me.Width
End If
If NewTop + x > CurrentScreen.WorkingArea.Y + CurrentScreen.WorkingArea.Height - Me.Height And NewTop - x < CurrentScreen.WorkingArea.Y + CurrentScreen.WorkingArea.Height - Me.Height Then
NewTop = CurrentScreen.WorkingArea.Y + CurrentScreen.WorkingArea.Height - Me.Height
End If
Me.Left = NewLeft
Me.Top = NewTop
End Sub

Private Sub FormMagnetique_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
If e.Button <> e.Button.Left Then Exit Sub 'On quitte l'évènement si le bouton de la souris gauche n'est pas enfoncé
StartMousePos = Nothing
End Sub 'Fin de l'effet magnétique et de déplacement par la form
#End Region
ManDeq59 Messages postés 55 Date d'inscription dimanche 12 mai 2002 Statut Membre Dernière intervention 6 juillet 2004
13 août 2004 à 18:41
Jai compris pkoi.

En faite si je l'as déplace en cliquant dans la form ==> Ca marche.

Mais par contre si je l'as deplace à partir de la barre de titre ==> Ca ne marche plus

Vois-tu ce qu'on pourrais faire ?

Sinon c'est trés simple !!!! félicitation 8/10
spy166 Messages postés 207 Date d'inscription jeudi 21 novembre 2002 Statut Membre Dernière intervention 29 mars 2006
12 août 2004 à 23:09
???
Heu précise s'il te plaît, parce que je vois pas comment ça ne pourrait pas marcher.
ManDeq59 Messages postés 55 Date d'inscription dimanche 12 mai 2002 Statut Membre Dernière intervention 6 juillet 2004
12 août 2004 à 21:58
Marche pô
Rejoignez-nous