bonsoir tout le monde

j'aimerais savoir si , tout comme pour la création dynamique de Button

, serait-il possible de creer dynamiquement des bitbutton ou des speedbutton ?

car j'ai essayé ceci :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
unit Unit_Caisse2;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, KADaoDBGrid, DB, KDaoTable, KDaoDataBase, ExtCtrls,
  StdCtrls, jpeg, ToolWin, ComCtrls,TypInfo;
 
type
  TForm_Rubrique = class(TForm)
    MPanel: TPanel;
    KADaoTable_Rubriques: TKADaoTable;
    DataSource_Rubriques: TDataSource;
    procedure FormCreate(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
 
  end;
 
var
  Form_Rubrique: TForm_Rubrique;
  ListeBoutons: array of TBitButton;
  Nombre: integer = 0;
 
implementation
 
{$R *.dfm}
 const
  MaxCol = 5;
  MaxRow = 5; // Matrice de 5x5 = 25 bouton possible dans ton TPanel...
  Margin = 2;
 
procedure TForm_Rubrique.FormCreate(Sender: TObject);
Var
  ButtonsPerCol, ButtonWidth, ButtonHeight, FColumns,
    FMargin, WinCtrlCount, I, J: Integer;
  DeferHandle       : THandle;
  ALeft             : Integer;
 
Begin
KADaoTable_Rubriques.Active:=true;
Nombre:=KADaoTable_Rubriques.RecordCount;
SetLength(ListeBoutons,Nombre);
 i:=0;
  while (i<Nombre) do
  begin
  ListeBoutons[i] := TBitButton.Create(self);
  with ListeBoutons[i] do
  begin
  Parent := MPanel;
  Caption := KADaoTable_Rubriques.FieldByName('Famille_Nom').AsString;
  ParentColor:=false;
  ParentBackground:=false;
  Font.Size:=10;
  //Font.Style:=[fsBold];
  //Font.Color:=clblack;
  end;
  inc(i);
  KADaoTable_Rubriques.Next;
  end;
  FColumns := 6; // Nombre de colonnes
  FMargin := 10; // Marge entre le bord du MPanel et le premier composant
  WinCtrlCount := 0;
  If MPanel.ControlCount <> 0 Then   // Si MPanel contient des controles
    For I := 0 To MPanel.ControlCount - 1 Do
      If (MPanel.Controls[I] Is Twincontrol) Then Inc(WinCtrlCount);// Si ils sont de type TWinControl alors on incrémente
  If WinCtrlCount <> 0 Then // Si on à trouvé des TWinControl dans MPanel
    Begin
      ButtonsPerCol := (WinCtrlCount + FColumns - 1) Div FColumns; // Calcule ddes positions
      ButtonWidth := (MPanel.Width - FMargin) Div FColumns;
      ButtonHeight := (MPanel.Height - FMargin) Div ButtonsPerCol;
      MPanel.Width := FMargin + ButtonWidth * FColumns;
      MPanel.Height := FMargin + ButtonHeight * ButtonsPerCol;
      DeferHandle := BeginDeferWindowPos(WinCtrlCount);
      J := 0;
      Try
        For I := 0 To MPanel.ControlCount - 1 Do  // Et on applique les changements aux Controles
          If (MPanel.Controls[I] Is Twincontrol) Then
            With (MPanel.Controls[I] As Twincontrol) Do
              Begin
                BiDiMode := MPanel.BiDiMode;
                ALeft := (J Div ButtonsPerCol) * ButtonWidth + FMargin Div 2;
                If UseRightToLeftAlignment Then
                  ALeft := MPanel.ClientWidth - ALeft - ButtonWidth;
                DeferHandle := DeferWindowPos(DeferHandle, Handle, 0,  ALeft,
                  (J Mod ButtonsPerCol) * ButtonHeight + FMargin Div 2,
                  ButtonWidth, ButtonHeight,
                  SWP_NOZORDER Or SWP_NOACTIVATE);
                Inc(J);
              End;
      Finally
        EndDeferWindowPos(DeferHandle);
      End;
    End;
End;
 
 
end.
je précise que ce code fonctionne lorsqu'on utilise du Tbutton au lieu de Tbitbutton ou de Tspeedbutton

donc voila,comment faire svp ? merci d'avance a tous