![]() |
AW: [StringGrid] berechnen d. Zellenbreite nach resize
Hallo,
Zitat:
Heiko |
AW: [StringGrid] berechnen d. Zellenbreite nach resize
Nö, im FormCreate (hab feste Breiten, wollte aber - so wie von Omata beschrieben - die weißen "Ränder weghaben").
Ich setz mich jetzt gleich mal ran und frickel mir det zurecht.. |
AW: [StringGrid] berechnen d. Zellenbreite nach resize
Hallo Buddelflink,
wie hast du das gemacht dass einen Kalender in einem Stringgrid angezeigt wird? Kann du mal bitte ein Beispiel zeigen! danke. |
AW: [StringGrid] berechnen d. Zellenbreite nach resize
Liste der Anhänge anzeigen (Anzahl: 1)
Zitat:
In der Unit DateUtils findest du zahlreiche nützliche Funktionen wie z.B. DayOfTheWeek, DaysInMonth und WeekOfTheYear. Es gibt mehrere Wege, die nach Rom (zum Ziel) führen, daher möchte ich deiner Lernfähigkeit nicht im Wege stehen, indem ich hier den vollständigen Code reinstelle. Mit anderen Worten: Selber ausprobieren heißt die Devise. Für die Kalenderdarstellung einer Terminverwaltung hab ich einige Tage aus- und rumprobiert, auch mal die Hilfe eines Delphi-Forums in Anspruch genommen bei ganz gezielten Fragen. Dagegen wird dir die pauschale Frage, wie man einen Kalender programmiert, wohl kaum einer beantworten wollen. |
AW: [StringGrid] berechnen d. Zellenbreite nach resize
Zitat:
Form:
Delphi-Quellcode:
und die Klasse, die das gesamte Handling übernimmt:
unit MainView;
interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, uStringGridCalendar, Vcl.StdCtrls, Vcl.ExtCtrls; type TForm1 = class( TForm ) StringGrid1 : TStringGrid; Button1 : TButton; Button2 : TButton; Panel1: TPanel; procedure FormCreate( Sender : TObject ); procedure FormDestroy( Sender : TObject ); procedure Button1Click( Sender : TObject ); procedure Button2Click( Sender : TObject ); private { Private-Deklarationen } FCal : TStringGridCalendar; public { Public-Deklarationen } end; var Form1 : TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click( Sender : TObject ); begin FCal.DoIncYear( 1 ); end; procedure TForm1.Button2Click( Sender : TObject ); begin FCal.DoIncYear( -1 ); end; procedure TForm1.FormCreate( Sender : TObject ); begin FCal := TStringGridCalendar.Create( StringGrid1 ); end; procedure TForm1.FormDestroy( Sender : TObject ); begin FCal.Free; end; end.
Delphi-Quellcode:
Diese Klasse kann man nun noch um beliebige Features erweitern um die Anzeige aufzuhübschen oder weitere Funktionalitäten anzupassen.
unit uStringGridCalendar;
interface uses Vcl.Grids; type TStringGridCalendar = class private FGrid : TStringGrid; FSelDate : TDate; procedure SetSelDate( const Value : TDate ); protected procedure GridSelectCell( Sender : TObject; ACol, ARow : Integer; var CanSelect : Boolean ); procedure DoGridDataFill; function TryGetDateFromGrid( ACol, ARow : Integer; out aDate : TDate ) : Boolean; function GetDateFromGrid( ACol, ARow : Integer ) : TDate; public constructor Create( aStringGrid : TStringGrid ); property SelDate : TDate read FSelDate write SetSelDate; procedure DoIncYear( aValue : Integer ); end; implementation uses System.SysUtils, System.DateUtils; { TStringGridCalendar } constructor TStringGridCalendar.Create( aStringGrid : TStringGrid ); begin inherited Create; FGrid := aStringGrid; FGrid.Options := FGrid.Options - [goRangeSelect]; FGrid.OnSelectCell := GridSelectCell; FSelDate := Date; DoGridDataFill; end; procedure TStringGridCalendar.DoGridDataFill; var idx : Integer; DateIdx : TDate; lRow, lCol : Integer; begin FGrid.FixedCols := 1; FGrid.FixedRows := 1; FGrid.ColCount := 38; FGrid.RowCount := MonthsPerYear + FGrid.FixedRows; // Jahreszahl in die erste Zelle FGrid.Cells[0, 0] := IntToStr( YearOf( SelDate ) ); // Tagesnamen in die erste Zeile for idx := FGrid.FixedCols to Pred( FGrid.ColCount ) do begin FGrid.Cells[idx, 0] := ShortDayNames[( idx - FGrid.FixedCols + 1 ) mod DaysPerWeek + 1]; end; // Monatsnamen in die erste Spalte for idx := FGrid.FixedRows to Pred( FGrid.RowCount ) do begin FGrid.Cells[0, idx] := LongMonthNames[idx - FGrid.FixedRows + 1]; end; for lRow := FGrid.FixedRows to Pred( FGrid.RowCount ) do begin for lCol := FGrid.FixedCols to Pred( FGrid.ColCount ) do begin if TryGetDateFromGrid( lCol, lRow, DateIdx ) then FGrid.Cells[lCol, lRow] := IntToStr( DayOf( DateIdx ) ) else FGrid.Cells[lCol, lRow] := ''; end; end; end; function TStringGridCalendar.GetDateFromGrid( ACol, ARow : Integer ) : TDate; begin if not TryGetDateFromGrid( ACol, ARow, Result ) then raise Exception.Create( 'Fehlermeldung' ); end; procedure TStringGridCalendar.GridSelectCell( Sender : TObject; ACol, ARow : Integer; var CanSelect : Boolean ); var lDate : TDate; begin if TryGetDateFromGrid( ACol, ARow, lDate ) then begin CanSelect := True; SelDate := lDate; end else CanSelect := False; end; procedure TStringGridCalendar.DoIncYear( aValue : Integer ); begin SelDate := IncYear( SelDate, aValue ) end; function TStringGridCalendar.TryGetDateFromGrid( ACol, ARow : Integer; out aDate : TDate ) : Boolean; var lMonth, lDay, lYear : Word; lMinCol, lMaxCol : Integer; begin Result := False; if ( ACol >= FGrid.FixedCols ) and ( ARow >= FGrid.FixedRows ) then begin lYear := YearOf( SelDate ); lMonth := ARow - FGrid.FixedRows + 1; aDate := EncodeDate( lYear, lMonth, 1 ); lMinCol := DayOfTheWeek( aDate ) + FGrid.FixedCols - 1; lMaxCol := lMinCol + DaysInMonth( aDate ) - 1; if ( ACol >= lMinCol ) and ( ACol <= lMaxCol ) then begin Result := True; lDay := ACol - lMinCol + 1; aDate := EncodeDate( lYear, lMonth, lDay ); end; end; end; procedure TStringGridCalendar.SetSelDate( const Value : TDate ); var lYearChange : Boolean; begin if ( Value <> SelDate ) then begin lYearChange := YearOf( Value ) <> YearOf( SelDate ); FSelDate := Value; if lYearChange then DoGridDataFill; end; end; end. |
AW: [StringGrid] berechnen d. Zellenbreite nach resize
vielen vielen dank!
an Sir Rifo |
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:54 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz