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 : 10199
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} BOUTON UP_DOWN
Bonjours à tous , Je suis tombé récement sur un programme (écrit en Delphi , je pense) qui comporta...

{Visual Basic, VB6, VB.NET, VB 2005} OPENGL AVEC VB6
JE VOUS PRESENTE UN ENVIRONNEMENT 3D EN OPENGL QUI PERMET D'AFFICHER DES OBJETS WAVEFRONT (.OBJ), .3...

{PHP} GESTION D'ESPACE MEMBRES
Ce petit projet contient un ensemble de pages php (et php objet) et se base sur une base mysql (scri...

{Visual Basic, VB6, VB.NET, VB 2005} LISTVIEW_TRI_EXTENSIONS
Ce programme tri les fichiers d'un dossier ayant la même extension. Ces fichiers sont automatiquemen...

{Javascript / DHTML} LES COOKIES ET JAVASCRIPT
Comme la propriété cookie de l'objet document de l'objet window (window.document.cookie) est assez c...

{Visual Basic, VB6, VB.NET, VB 2005} INDIRECTION SUR LES MEMBRES D'UNE CLASSE EN VB.NET OU C#, INDIRECTION ON CLASS MEMBERS IN VB.NET OR C#
Bonjour, Ayant fait un peu de Windev, la fonction la plus pratique de ce langage est que l'on peu...

{Flash} OBJETFLASH!
flash tout simple et bon pour les débutants qui veulent compiler des objets. Un play(); et c'est to...

{Flash} ANIMATION FLASH, DÉPLACEMENT D'OBJET
Une petite annimation flash, avec voiture et personnage qui se déplacent, l'hitoire et toute simple,...

{Javascript / DHTML} DRAG/DROP/REDIMENSIONNER...
Cette petite source est certe connue vu partout mais elle est assez simple et avancé... Grâce à cet...