Einzelnen Beitrag anzeigen

Benutzerbild von SirThornberry
SirThornberry
(Moderator)

Registriert seit: 23. Sep 2003
Ort: Bockwen
12.235 Beiträge
 
Delphi 2006 Professional
 
#8

Re: Multiselect mit Strg + Maus (wie?)

  Alt 26. Jun 2007, 11:24
Also ich hab mal fix eine Testkomponente programmiert und die funktioniert eigentlich Windowsüblich:
Delphi-Quellcode:
unit uExampleCtrl;

interface

uses
  windows, classes, graphics, controls;

type
  TExampleCtrl = class(TCustomControl)
  private
    fStati : Array[0..5] of Boolean;
  protected
    procedure Paint(); override;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  public
    constructor Create(AOwner: TComponent); override;
  end;

implementation

{ TExampleCtrl }

constructor TExampleCtrl.Create(AOwner: TComponent);
var
  lCount : Integer;
begin
  inherited Create(AOwner);
  ZeroMemory(@fStati, SizeOf(fStati));
  SetBounds(0, 0, 300, 300);
end;

procedure TExampleCtrl.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  lIndex : Integer;
begin
  inherited;
  lIndex := X div (Width div 3) + Y div (Height div 2) * 3;
  if (ssCtrl in Shift) then
    fStati[lIndex] := not(fStati[lIndex])
  else
  begin
    ZeroMemory(@fStati, SizeOf(fStati));
    fStati[lIndex] := True;
  end;
  Invalidate();
end;

procedure TExampleCtrl.Paint;
var
  lCountX,
  lCountY,
  lIndex,
  lPartHeight,
  lPartWidth : Integer;

begin
  lPartHeight := Height div 2;
  lPartWidth := Width div 3;

  Canvas.Brush.Color := clWhite;
  Canvas.FillRect(Rect(0, 0, Width, Height));
  Canvas.Brush.Color := clBlue;
  for lCountY := 0 to 1 do
  begin
    for lCountX := 0 to 2 do
    begin
      lIndex := lCountX + lCountY * 3;
      if fStati[lIndex] then
      begin
        Canvas.FillRect(Rect(lCountX * lPartWidth, lCountY * lPartHeight, (lCountX + 1) * lPartWidth, (lCountY + 1) * lPartHeight));
      end
      else
      begin

      end;
    end;
  end;

  Canvas.Pen.Color := clBlack;
  Canvas.MoveTo(0, Height div 2);
  Canvas.LineTo(Width, Height div 2);

  Canvas.MoveTo(lPartWidth, 0);
  Canvas.LineTo(lPartWidth, Height);
  Canvas.MoveTo(lPartWidth * 2, 0);
  Canvas.LineTo(lPartWidth * 2, Height);
end;

end.
Jens
Mit Source ist es wie mit Kunst - Hauptsache der Künstler versteht's
  Mit Zitat antworten Zitat