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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
unit UEditStrGrd;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, ComCtrls;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure StringGrid1SelectCell(Sender: TObject; Col, Row: Integer;
var CanSelect: Boolean);
procedure FormShow(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Déclarations privées }
public
{ Déclarations publiques }
procedure ComboBox1Exit(Sender: TObject);
procedure EditCelluleExit(Sender: TObject);
procedure FenPluieExit(Sender: TObject);
end;
var
Form1: TForm1;
FenPluie: TForm;
ComboBox1:TComboBox;
EditCellule, EditPluie:TEdit;
UpDownPluie : TUpDown;
implementation
{$R *.dfm}
procedure TForm1.ComboBox1Exit(Sender: TObject);
begin
StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]:=ComboBox1.Text;
ComboBox1.Visible := False;
StringGrid1.SetFocus;
end;
procedure TForm1.EditCelluleExit(Sender: TObject);
begin
StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]:=EditCellule.Text;
EditCellule.Visible := False;
StringGrid1.SetFocus;
end;
procedure TForm1.FenPluieExit(Sender : TObject);
begin
StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]:=EditPluie.Text;
FenPluie.ModalResult := mrNone;
StringGrid1.SetFocus;
end;
procedure TForm1.FormShow(Sender: TObject);
Var
X:Integer;
begin // création de la comboBox
StringGrid1.Options:=StringGrid1.Options+[goColSizing,goThumbTracking]-[goEditing];
ComboBox1:=TComboBox.Create(Self);
ComboBox1.Parent:=Form1;
ComboBox1.Visible:=False;
ComboBox1.OnExit:=ComboBox1Exit;
// Initialisation de la comboBox
ComboBox1.Clear;
For X:=1 to 10
do ComboBox1.Items.Add(IntToStr(X));
// Création du tEdit
EditCellule := TEdit.Create(Self);
EditCellule.Parent := Form1;
EditCellule.Visible := False;
EditCellule.OnExit := EditCelluleExit;
// cr&ation de la fenetre pluie
FenPluie := TForm.Create(self);
With FenPluie do
begin
Height := Form1.Height div 2;
Width := Form1.Width div 3;
Left := ((Form1.Width - Width) div 2 )+Form1.Left;
Top := ((Form1.Height - Height) div 2 )+ Form1.Top;
caption := 'Cumul de pluie';
BorderIcons := [biSystemMenu];
Visible := False;
OnExit := FenPluieExit;
Parent := Form1;
end;
// Création des controls de la fenetre de pluie
// la zone d'édition
EditPluie := TEdit.Create(FenPluie);
With EditPluie do
begin
Parent := FenPluie;
Width := 90;
ReadOnly := true;
Left := ((FenPluie.ClientWidth Div 2) - 10)-45;
Top := 30;
end;
// Le bouton +-
UpDownPluie := TUpDown.Create(FenPluie);
With UpDownPluie do
begin
Parent := FenPluie;
Left := ((FenPluie.ClientWidth Div 2) - 10) + 60;
Top := 10;
Width := 30;
Height := 60;
min := 0;
Max := 500;
increment := 1;
Position := 0;
//OnChangingEx := ChangeCumul; futur dévelopement
end;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
ComboBox1.Free;
EditCellule.Free;
FenPluie.Free;
EditPluie.Free;
UpDownPluie.Free;
end;
procedure TForm1.StringGrid1SelectCell(Sender: TObject;Col,Row: Integer; var CanSelect: Boolean);
var
R: TRect;
begin
if (Col = 10)
and (Row <> 0)
then begin // initalisation de la comboBox
R := StringGrid1.CellRect(Col, Row);
R.Left := R.Left + StringGrid1.Left;
R.Right := R.Right + StringGrid1.Left;
R.Top := R.Top + StringGrid1.Top;
R.Bottom := R.Bottom + StringGrid1.Top;
ComboBox1.Left := R.Left + 1;
ComboBox1.Top := R.Top + 1;
ComboBox1.Width := (R.Right + 1) - R.Left;
ComboBox1.Height := (R.Bottom + 1) - R.Top;
ComboBox1.Visible := True;
if StringGrid1.Cells[Col,Row]<>''
then ComboBox1.Text:=StringGrid1.Cells[Col,Row]
else ComboBox1.Text:='';
ComboBox1.SetFocus;
end;
if (Col in [1,2,3,4,5,6,7,9])
and (Row <> 0)
then begin // initialisation du TEdit
R := StringGrid1.CellRect(Col, Row);
R.Left := R.Left + StringGrid1.Left;
R.Right := R.Right + StringGrid1.Left;
R.Top := R.Top + StringGrid1.Top;
R.Bottom := R.Bottom + StringGrid1.Top;
EditCellule.Left := R.Left + 1;
EditCellule.Top := R.Top + 1;
EditCellule.Width := (R.Right + 1) - R.Left;
EditCellule.Height := (R.Bottom + 1) - R.Top;
EditCellule.Visible := True;
if StringGrid1.Cells[Col,Row]<>''
then EditCellule.Text:=StringGrid1.Cells[Col,Row]
else EditCellule.Text:='';
EditCellule.SetFocus;
end;
if (Col =8)
and (Row <> 0)
then begin // initialisation de la fenetre cumul de pluie
if StringGrid1.Cells[Col,Row]<>''
then EditCellule.Text:=StringGrid1.Cells[Col,Row]
else EditCellule.Text:='';
FenPluie.ShowModal;
end;
end;
end. |
Partager