| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- unit main;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ComCtrls, StdCtrls, Grids, ExtCtrls,
- DropSource, DragDropText, DragDrop, DropTarget;
- type
- TFormAutoScroll = class(TForm)
- DropTextTarget1: TDropTextTarget;
- Panel1: TPanel;
- StringGrid1: TStringGrid;
- PanelSource: TPanel;
- Panel3: TPanel;
- DropTextSource1: TDropTextSource;
- RichEdit1: TRichEdit;
- procedure FormCreate(Sender: TObject);
- procedure PanelSourceMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure DropTextTarget1Drop(Sender: TObject; ShiftState: TShiftState;
- Point: TPoint; var Effect: Integer);
- procedure DropTextTarget1Enter(Sender: TObject;
- ShiftState: TShiftState; Point: TPoint; var Effect: Integer);
- procedure DropTextTarget1DragOver(Sender: TObject;
- ShiftState: TShiftState; Point: TPoint; var Effect: Integer);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- FormAutoScroll: TFormAutoScroll;
- implementation
- {$R *.DFM}
- uses
- ActiveX;
- procedure TFormAutoScroll.FormCreate(Sender: TObject);
- var
- i,j: integer;
- begin
- // Populate the grid with data
- for i := ord('A') to ord('Z') do
- StringGrid1.Cells[0, 1+i-ord('A')] := chr(i);
- for i := 0 to StringGrid1.ColCount-1 do
- StringGrid1.Cells[1+i, 0] := IntToStr(i);
- for i := ord('A') to ord('Z') do
- for j := 0 to StringGrid1.ColCount-1 do
- StringGrid1.Cells[1+j, 1+i-ord('A')] := chr(i)+IntToStr(j);
- end;
- procedure TFormAutoScroll.PanelSourceMouseDown(Sender: TObject;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- begin
- if DragDetectPlus(PanelSource.Handle, Point(X,Y)) then
- begin
- // Drag the current time of day.
- DropTextSource1.Text := DateTimeToStr(Now);
- DropTextSource1.Execute;
- end;
- end;
- procedure TFormAutoScroll.DropTextTarget1Enter(Sender: TObject;
- ShiftState: TShiftState; Point: TPoint; var Effect: Integer);
- var
- FirstCell: TRect;
- CustomNoScrollZone: TRect;
- begin
- (*
- ** Set up a custom no-scroll zone:
- ** 1. Get the grids client rect.
- ** 2. Move the top left corner to the first data cell.
- ** 3. Shrink the rect 1/3 or the grid cell size.
- *)
- CustomNoScrollZone := StringGrid1.ClientRect;
- FirstCell := StringGrid1.CellRect(StringGrid1.LeftCol,StringGrid1.TopRow);
- CustomNoScrollZone.TopLeft := FirstCell.TopLeft;
- InflateRect(CustomNoScrollZone, -StringGrid1.DefaultColWidth div 3,
- -StringGrid1.DefaultRowHeight div 3);
- TCustomDropTarget(Sender).NoScrollZone := CustomNoScrollZone;
- end;
- procedure TFormAutoScroll.DropTextTarget1DragOver(Sender: TObject;
- ShiftState: TShiftState; Point: TPoint; var Effect: Integer);
- var
- CellX, CellY: integer;
- begin
- // Determine if the cursor if over a data cell. If it isn't, we do not accept
- // a drop.
- StringGrid1.MouseToCell(Point.x, Point.y, CellX, CellY);
- if (CellX < 1) or (CellY < 1) then
- Effect := DROPEFFECT_NONE;
- end;
- procedure TFormAutoScroll.DropTextTarget1Drop(Sender: TObject;
- ShiftState: TShiftState; Point: TPoint; var Effect: Integer);
- var
- CellX, CellY: integer;
- begin
- // Determine which cell we dropped on and fill it with the dragged text.
- StringGrid1.MouseToCell(Point.x, Point.y, CellX, CellY);
- StringGrid1.Cells[CellX, Celly] := TDropTextTarget(Sender).Text;
- end;
- end.
|