Les Snippets

Connexion

Déplacer un objet dans un formulaire

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 25/03/2006 14:04:35 et initié par Willi [Liste]
Date de mise à jour : 05/11/2008 20:11:07
Vue : 16160
Catégorie(s) : Control
Langages dispo pour ce code :
- VB 2005, VB.NET 1.x
- C# 1.x, C# 2.x
- Javascript
- Delphi 5
- VB6
- VBA



Langage : VB.NET 1.x , VB 2005
Date ajout : 25/03/2006
Posté par Willi [Liste]
DateMAJ : 25/03/2006
'Exemple appliqué sur un objet PictureBox

Dim x As Integer Dim y As Integer Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown    If e.Button = Windows.Forms.MouseButtons.Left Then         x = e.X         y = e.Y    End If End Sub Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove     If e.Button = Windows.Forms.MouseButtons.Left Then         PictureBox1.Left += (e.X - x)         PictureBox1.Top += (e.Y - y)    End If End Sub
Langage : C# 1.x , C# 2.x
Date ajout : 25/03/2006
Posté par Willi [Liste]
DateMAJ : 25/03/2006

//Exemple appliqué sur un objet PictureBox
int x;
int y;

private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
   if (e.Button == MouseButtons.Left)
     {
        pictureBox1.Left += e.X - x;
        pictureBox1.Top += e.Y - y;
     }
}

private void pictureBox1_MouseDown(object sender, MouseEventArgs e) 
{
   if (e.Button == MouseButtons.Left) 
     {
       x = e.X;
       y = e.Y;
     }
}


Langage : Javascript
Date ajout : 06/04/2007
Posté par stfou [Liste]
function move(OBJECT,X,Y,UNIT)//Objet à déplacer, position x, position y, unité(% ou px)
{
OBJECT.style.position="absolute";//position absolue de l'objet
OBJECT.style.left=X+UNIT;//positionnement horizontal ( position x + unité)
OBJECT.style.top=Y+UNIT;//positionnement vertical ( position y + unité)
}
Exemple d'utilisation :
<div style="position:absolute" onclick="move(this,50,200,'%')"></div>
Langage : Delphi 5
Date ajout : 23/07/2008
Posté par cirec [Liste]
{Pour déplacer tous les composants héritants de TWinControl (fenêtrés):
  TForm, TButton, TEdit, TComboBox, TListbox ... etc. etc.
  *** n'oubliez pas d'affecter FormMouseMove à tous les composants que vous voulez déplacer
  par l'intermédiaire de l'inspecteur d'objets}
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if (ssLeft in Shift) and (Sender is TWinControl) then
    if ReleaseCapture then
      TWinControl(Sender).Perform(WM_SYSCOMMAND, SC_MOVE or HTCAPTION, 0);
end;

{Pour déplacer tous les autres composants (non fenêtrés):
  TImage, TLabel ... ici un TImage}
var iX, iY : Integer;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbLeft then
  begin
    iX := X;
    iY := Y;
  end;
end;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if ssLeft in Shift then
  begin
    Image1.Left := Image1.Left + X - iX;
    Image1.Top := Image1.Top + Y - iY;
  end;
end;

Langage : VB6
Date ajout : 05/11/2008
Posté par jrivet [Liste]
DateMAJ : 05/11/2008
Dim dX As Single
Dim dY As Single
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
        dX = X
        dY = Y
    End If
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
        Picture1.Left = Picture1.Left + (X - dX)
        Picture1.Top = Picture1.Top + (Y - dY)
    End If
End Sub
Remarque :
Et voilà la petite version VB6 Fortement inspirée de la version de Willi
Langage : VBA
Date ajout : 05/11/2008
Posté par PCPT [Liste]
DateMAJ : 05/11/2008
Dim dX As Single, dY As Single '<- à placer en déclarations générales
Private Sub Frame1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X  As Single, ByVal Y As  Single)
    dX = X: dY = Y
End Sub
Private Sub Frame1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X  As Single, ByVal Y As  Single)
    If Button = Excel.XlMouseButton.xlPrimaryButton Then Frame1.Move Frame1.Left + (X -  dX), Frame1.Top + (Y - dY)
End Sub


Snippets en rapport avec : Controle, Deplacer, Objet, Forumulaire



Codes sources en rapport avec : Controle, Deplacer, Objet, Forumulaire

{Javascript / DHTML} CONTRÔLE POUR FORMULAIRE
Contrôle vertical avec trois événements qui sont gérés (onmove, onchange et onclick). Dans l'exemple...

{Visual Basic, VB6, VB.NET, VB 2005} TROUVER UN CONTROLE "ACTIF" DANS UN FORM
Petit bout de code pour trouver par exemple une checkbox à true dans un form, au milieu d'un groupbo...

{JAVA / J2EE} MEMORISER LE CHEMIN PARCOURU PAR LA SOURIS ET LE REFAIRE
Ce Code fait en sorte que tant que vous faites un trajet avec votre souri il l'enregistre puis refai...

{Visual Basic, VB6, VB.NET, VB 2005} EVALUER UN NOMBRE D'OBJETS AVEC UNE BALANCE ET DEUX ÉCHANTILLONS - CALCUL INCERTITUDES
Bonjour. BUT DU PROGRAMME Calculer un nombre total...

{Visual Basic, VB6, VB.NET, VB 2005} CONTROLE STARS
Petit contrôle qui permet de choisir une note sur 10 lors du passage de la sourie sur les étoiles. ...

{C / C++ / C++.NET} UTILISATION DES TYPELIST EN C++
========================== Note admin codes-sources: ========================== ATTENTION: Ce ...

{C# / C#.NET} CONTRÔLES : BOUTON, LISTE ET PANNEAU POUR VOS APPLIS
En fouillant dans mes archives c# j'ai récupéré ces contrôles que j'avais crée en me basant sur un e...

{Visual Basic, VB6, VB.NET, VB 2005} MOUVEMENT / DÉPLACEMENT D'OBJET (SHAPES,IMAGES)
salut, pour ceux qui ont vu mes tutos sur le "déplacement d'objet dans une "map" voici sa petite app...

{PHP} FORM, ORM POUR FORMULAIRE
Bonjour tout le monde, si je poste aujourd'hui c'est pour vous présenter fORM. fORM est une class...

{Assembleur} REUTILISER N'IMPORTE QUEL PROGRAMME EX:WORDPAD
La technique consiste a lancer l'execution du programme et a redonner la main au systeme. Le progr...