Précédent   Forum du club des développeurs et IT Pro > Environnements de développement > Delphi > Contribuez
Contribuez Proposez vos articles, cours, tutoriels, FAQ, sources et autres ressources pour la rubrique Delphi.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 18/04/2008, 11h35   #1
Leurant
Invité de passage
 
Inscription : avril 2008
Messages : 2
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 2
Points : 3
Points : 3
Par défaut ScrollBox et mousewheel

Bonjour,
suite à quelques recherche voici la solution que j'ai trouvé pour pouvoir utiliser la roulette de la sourie avec un scrollBox. je ne suis pas très bien l'évolution des objet delphi et donc il existe peut-être un scrollBox qui inclut cette fonction. Mais pour contribuer, voici ce que j'ai fait :

Tout dabord il faut que le scrollbox soit en Align : alclient. Si ce n'est pas le cas et pour ne pas tout changer dans la form il suffit de le mettre dans un panel par exemple et de donner la propriété alClient au scrollbox.

Ensuite, l'evennement qui "capte" bien la roulette est le FormMouseWheel de la form qui contient le scrollbox.

Enfin, le code à inserrer dans cet évennement est le suivant :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
procedure TNomDeLaForm_e.FormMouseWheel(Sender: TObject; Shift: TShiftState;
    WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
var
  i: integer;
  PosHautGauche: TPoint;
  PosBasDroite: TPoint;
 
begin
 
  for i := 0 to TForm(Sender).ComponentCount - 1 do
    begin
      try
        if TForm(Sender).Components[i] is TScrollBox then
          begin
            if (TForm(Sender).Components[i] as Tscrollbox).CanFocus then
              begin
                PosHautGauche.X := (TForm(Sender).Components[i] as TScrollBox).Left;
                PosHautGauche.Y := (TForm(Sender).Components[i] as TScrollBox).Top;
                PosBasDroite.X := (TForm(Sender).Components[i] as TScrollBox).Left
                  + (TForm(Sender).Components[i] as TScrollBox).Width;
                PosBasDroite.Y := (TForm(Sender).Components[i] as TScrollBox).Top
                  + (TForm(Sender).Components[i] as TScrollBox).Height;
 
                PosHautGauche := TForm(Sender).ScreenToClient((TForm(Sender).Components[i] as TScrollBox).ClientToScreen(PosHautGauche));
                PosHautGauche.X := PosHautGauche.X + TForm(Sender).Left;
                PosHautGauche.Y := PosHautGauche.Y + TForm(Sender).Top + TForm(Sender).Height - TForm(Sender).ClientHeight;
 
                PosBasDroite := TForm(Sender).ScreenToClient((TForm(Sender).Components[i] as TScrollBox).ClientToScreen(PosBasDroite));
                PosBasDroite.X := PosBasDroite.X + TForm(Sender).Left;
                PosBasDroite.Y := PosBasDroite.Y + TForm(Sender).Top + TForm(Sender).Height - TForm(Sender).ClientHeight;
 
                if (MousePos.X > PosHautGauche.X) and (MousePos.Y > PosHautGauche.Y)
                  and (MousePos.X < PosBasDroite.X) and (MousePos.Y < PosBasDroite.Y)
                  then
                  (TForm(Sender).Components[i] as TScrollBox).VertScrollBar.Position := (TForm(Sender).Components[i] as TScrollBox).VertScrollBar.Position - WheelDelta;
              end;
          end;
      except
      end;
    end;
end;

voilà.

à plus
Laurent
Leurant est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 21/04/2008, 14h01   #2
Pedro
Rédacteur
 
Avatar de Pedro
 
Inscription : octobre 2003
Messages : 5 406
Détails du profil
Informations forums :
Inscription : octobre 2003
Messages : 5 406
Points : 6 771
Points : 6 771
Merci pour ta participation
__________________
Pedro
Aucune réponse aux sollicitations techniques par MP

Faut pas attendre d'en avoir besoin pour s'en servir... (Lucien Stéphane)

Les pages Source C'est bon. Mangez-en!
Le défi Delphi
Règles du forum - FAQ Delphi - Pensez au chtit

Le site de mon frangin
Pedro est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/05/2012, 12h17   #3
thefreecat
Invité de passage
 
Inscription : novembre 2005
Messages : 8
Détails du profil
Informations forums :
Inscription : novembre 2005
Messages : 8
Points : 3
Points : 3
Merci beaucoup, ça marche nickel.
thefreecat est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 19h14.


 
 
 
 
Partenaires

Hébergement Web