📄 tsdatetime.pas
字号:
FComboMonth.Height := FComboMonth.DefaultRowHeight;
//ShowMessage('TtsDateTime Create Step 5-4e');
FComboMonth.Width := FComboMonth.Col[1].Width;
//ShowMessage('TtsDateTime Create Step 5-4f');
FComboMonth.HeadingOn := False;
FComboMonth.RowBarOn := False;
FComboMonth.WantTabs := False;
FComboMonth.FlatButtons := False;
FComboMonth.ButtonEdgeWidth := 0;
FComboMonth.DefaultButtonWidth := FComboMonth.VertScrollBarWidth - 1;
FComboMonth.StoreData := True;
FComboMonth.VertAlignment := vtaCenter;
FComboMonth.CellSelectMode := cmNone;
FComboMonth.FocusColor := clHighlight;
FComboMonth.FocusFontColor := clHighlightText;
FComboMonth.CheckMouseFocus := False;
FComboMonth.ScrollBars := ssNone;
FComboMonth.AutoScale := False;
//ShowMessage('TtsDateTime Create Step 5-5');
FComboMonth.Col[1].ButtonType := btCombo;
//ShowMessage('TtsDateTime Create Step 5-5a');
FComboMonth.Col[1].AssignCombo;
//ShowMessage('TtsDateTime Create Step 5-5b');
FComboMonth.Col[1].Combo.Grid.Rows := 12;
//ShowMessage('TtsDateTime Create Step 5-5c');
FComboMonth.Col[1].Combo.Grid.Cols := 1;
//ShowMessage('TtsDateTime Create Step 5-5d');
FComboMonth.Col[1].Combo.DropDownRows := 5;
FComboMonth.Col[1].Combo.DropDownCols := 1;
FComboMonth.Col[1].Combo.AutoSearch := asTop;
////ShowMessage('TtsDateTime Create Step 5-5e');
FComboMonth.Col[1].Combo.ValueCol := 1;
FComboMonth.Col[1].Combo.ValueColSorted := False;
////ShowMessage('TtsDateTime Create Step 5-5f');
FComboMonth.Col[1].Combo.Grid.StoreData := True;
////ShowMessage('TtsDateTime Create Step 5-5g');
FComboMonth.Col[1].DropDownStyle := ddDropDownList;
////ShowMessage('TtsDateTime Create Step 5-5h');
FComboMonth.Col[1].Combo.Grid.Width := FComboMonth.Width;
////ShowMessage('TtsDateTime Create Step 5-5i');
FComboMonth.Col[1].Combo.Grid.SelectionType := sltColor;
////ShowMessage('TtsDateTime Create Step 5-5j');
FComboMonth.Col[1].Combo.Grid.GridLines := glNone;
////ShowMessage('TtsDateTime Create Step 5-5k');
FComboMonth.Col[1].Combo.Grid.VertAlignment := vtaCenter;
////ShowMessage('TtsDateTime Create Step 5-6');
FComboMonth.OnComboGetValue := grdMonthComboGetValue;
FComboMonth.OnKeyPress := grdMonthKeyPress;
////ShowMessage('TtsDateTime Create Step 5-7');
FComboBevel.Top := FComboMonth.Top - 1;
FComboBevel.Left := FComboMonth.Left - 1;
FComboBevel.Style := bsLowered;
////ShowMessage('TtsDateTime Create Step 5-8');
FTxtYear.MaxLength := 4;
FTxtYear.TabOrder := 1;
FTxtYear.Top := 1;
FTxtYear.Left := 4;
FTxtYear.Ctl3D := False;
FTxtYear.BorderStyle := bsNone;
FTxtYear.OnExit := txtYearExit;
FTxtYear.OnKeyDown := txtYearKeyDown;
FTxtYear.OnKeyPress := txtYearKeyPress;
////ShowMessage('TtsDateTime Create Step 5-9');
FPnlEditYear.BevelOuter := bvLowered;
FPnlEditYear.BorderStyle := bsNone;
FPnlEditYear.Color := clWindow;
////ShowMessage('TtsDateTime Create Step 5-10');
FPnlCalendar.BevelOuter := bvNone;
FPnlCalendar.BorderWidth := 1;
FPnlCalendar.Caption := '';
FPnlCalendar.Color := clBtnShadow;
FPnlCalendar.TabOrder := 2;
////ShowMessage('TtsDateTime Create Step 5-11');
FDateGrid.Align := alClient;
FDateGrid.BorderStyle := bsNone;
FDateGrid.CellSelectMode := cmNone;
FDateGrid.CenterPicture := False;
FDateGrid.CheckBoxStyle := stCheck;
FDateGrid.ColMoving := False;
FDateGrid.Cols := 8;
FDateGrid.Rows := CalcGridRows;
FDateGrid.ColSelectMode := csNone;
FDateGrid.Ctl3D := True;
FDateGrid.DefaultColWidth := 19;
FDateGrid.DefaultRowHeight := 18;
FDateGrid.FixedColCount := 1;
FDateGrid.FixedRowCount := 1;
FDateGrid.GridLines := glNone;
FDateGrid.GridMode := gmListBox;
FDateGrid.HeadingColor := clWindow;
FDateGrid.HeadingOn := False;
FDateGrid.ParentCtl3D := False;
FDateGrid.ParentFont := True;
FDateGrid.ParentShowHint := False;
FDateGrid.ResizeCols := rcNone;
FDateGrid.ResizeRows := rrNone;
FDateGrid.RowBarOn := False;
FDateGrid.RowMoving := False;
FDateGrid.RowSelectMode := rsNone;
FDateGrid.ScrollBars := ssNone;
FDateGrid.TabOrder := 0;
FDateGrid.AutoScale := False;
////ShowMessage('TtsDateTime Create Step 5-12');
FDateGrid.OnCellLoaded := DateGridCellLoaded;
FDateGrid.OnKeyPress := DateGridKeyPress;
FDateGrid.OnKeyDown := DateGridKeyDown;
FDateGrid.OnMouseDown := DateGridMouseDown;
FDateGrid.OnMouseUp := DateGridMouseUp;
FDateGrid.OnPaint := DateGridPaint;
for I := 1 to FDateGrid.Cols do
begin
FDateGrid.Col[i].Align := True;
FDateGrid.Col[i].Alignment := taCenter;
end;
////ShowMessage('TtsDateTime Create Step 5-13');
FDateScrollBar.Kind := sbVertical;
FDateScrollBar.LargeChange := 4;
FDateScrollBar.Max := 47;
FDateScrollBar.Position := 23;
FDateScrollBar.TabOrder := 3;
FDateScrollBar.TabStop := False;
FDateScrollBar.OnKeyPress := DateScrollBarKeyPress;
FDateScrollBar.OnScroll := DateScrollBarScroll;
////ShowMessage('TtsDateTime Create Step 5-14');
FTimKeyDownDelay.Enabled := False;
FTimKeyDownDelay.OnTimer := timKeyDownDelayTimer;
////ShowMessage('TtsDateTime Create Step 5-15');
FPnlTime.BevelOuter := bvNone;
FPnlTime.Ctl3D := True;
FPnlTime.ParentColor := True;
FPnlTime.ParentCtl3D := False;
FPnlTime.TabOrder := 1;
////ShowMessage('TtsDateTime Create Step 5-16');
FButHourIncr.Layout := blGlyphBottom;
FButHourIncr.OnMouseDown := butTimeIncrMouseDown;
FButHourIncr.OnMouseUp := butTimeIncrMouseUp;
FButHourDecr.Layout := blGlyphBottom;
FButHourDecr.OnMouseDown := butTimeDecrMouseDown;
FButHourDecr.OnMouseUp := butTimeDecrMouseUp;
FButMinIncr.Layout := blGlyphBottom;
FButMinIncr.OnMouseDown := butTimeIncrMouseDown;
FButMinIncr.OnMouseUp := butTimeIncrMouseUp;
FButMinDecr.Layout := blGlyphBottom;
FButMinDecr.OnMouseDown := butTimeDecrMouseDown;
FButMinDecr.OnMouseUp := butTimeDecrMouseUp;
FButSecIncr.Layout := blGlyphBottom;
FButSecIncr.OnMouseDown := butTimeIncrMouseDown;
FButSecIncr.OnMouseUp := butTimeIncrMouseUp;
FButSecDecr.Layout := blGlyphBottom;
FButSecDecr.OnMouseDown := butTimeDecrMouseDown;
FButSecDecr.OnMouseUp := butTimeDecrMouseUp;
FButAMPMIncr.Layout := blGlyphBottom;
FButAMPMIncr.OnMouseDown := butTimeIncrMouseDown;
FButAMPMIncr.OnMouseUp := butTimeIncrMouseUp;
FButAMPMDecr.Layout := blGlyphBottom;
FButAMPMDecr.OnMouseDown := butTimeDecrMouseDown;
FButAMPMDecr.OnMouseUp := butTimeDecrMouseUp;
FPnlEditTime.BevelOuter := bvLowered;
FPnlEditTime.BorderStyle := bsNone;
FPnlEditTime.Color := clWindow;
FPnlEditTime.TabOrder := 0;
FButOK.Visible := False;
FButOk.ParentFont := False;
FButOK.OnClick := butOKClick;
FButCancel.Visible := False;
FButCancel.ParentFont := False;
FButCancel.OnClick := butCancelClick;
FBevel.Height := 2;
FBevel.Style := bsRaised;
////ShowMessage('TtsDateTime Create Step 5-17');
FTxtHour.Top := 1;
FTxtHour.BorderStyle := bsNone;
FTxtHour.Ctl3D := False;
FTxtHour.MaxLength := 2;
FTxtHour.ParentCtl3D := False;
FTxtHour.TabOrder := 0;
FTxtHour.OnExit := txtHourExit;
FTxtHour.OnKeyDown := txtHourKeyDown;
FTxtHour.OnKeyPress := txtHourKeyPress;
FTxtHour.OnChange := txtHourChange;
FTxtMinute.Top := 1;
FTxtMinute.BorderStyle := bsNone;
FTxtMinute.Ctl3D := False;
FTxtMinute.MaxLength := 2;
FTxtMinute.ParentCtl3D := False;
FTxtMinute.TabOrder := 1;
FTxtMinute.OnExit := txtMinuteExit;
FTxtMinute.OnKeyDown := txtMinuteKeyDown;
FTxtMinute.OnKeyPress := txtMinuteKeyPress;
FTxtMinute.OnChange := txtMinuteChange;
FTxtSeconds.Top := 1;
FTxtSeconds.BorderStyle := bsNone;
FTxtSeconds.Ctl3D := False;
FTxtSeconds.MaxLength := 2;
FTxtSeconds.ParentCtl3D := False;
FTxtSeconds.TabOrder := 2;
FTxtSeconds.OnExit := txtSecondsExit;
FTxtSeconds.OnKeyDown := txtSecondsKeyDown;
FTxtSeconds.OnKeyPress := txtSecondsKeyPress;
FTxtSeconds.OnChange := txtSecondsChange;
FTxtAMPM.Top := 1;
FTxtAMPM.BorderStyle := bsNone;
FTxtAMPM.Ctl3D := False;
FTxtAMPM.ParentCtl3D := False;
FTxtAMPM.ReadOnly := True;
FTxtAMPM.TabOrder := 3;
FTxtAMPM.OnKeyDown := txtAMPMKeyDown;
FTxtAMPM.OnKeyPress := txtAMPMKeyPress;
FLblSep1.Color := FTxtHour.Color;
FLblSep1.AutoSize := False;
FLblSep1.Top := FTxtHour.Top;
FLblSep1.Width := 3;
FLblSep2.Color := FTxtHour.Color;
FLblSep2.AutoSize := False;
FLblSep2.Top := FTxtHour.Top;
FLblSep2.Width := 3;
end;
procedure TtsDateTime.InitMonthCombo;
var
I: Integer;
begin
FComboMonth.Col[1].Combo.Grid.StoreData := False;
FComboMonth.Col[1].Combo.Grid.StoreData := True;
for I := 1 to 12 do
FComboMonth.Col[1].Combo.Grid.Cell[1, I] := LongMonthNames[I];
SetComboValue;
end;
function TtsDateTime.ButYearSizeChanged: Boolean;
begin
Result := (FButYearIncr.Height <> FOldButYearIncrSize) or
(FButYearDecr.Height <> FOldButYearDecrSize);
end;
function TtsDateTime.ButTimeSizeChanged: Boolean;
begin
Result := (FButHourIncr.Height <> FOldButHourIncrSize) or
(FButHourDecr.Height <> FOldButHourDecrSize);
end;
procedure TtsDateTime.SaveButtonHeights;
begin
FOldButYearIncrSize := FButYearIncr.Height;
FOldButYearDecrSize := FButYearDecr.Height;
FOldButHourIncrSize := FButHourIncr.Height;
FOldButHourDecrSize := FButHourDecr.Height;
end;
function TtsDateTime.CalcGridRows: Integer;
begin
if ShowSingleMonth then
begin
if ShowDayNames <> sdnNone then Result := 8
else Result := 7;
end
else
Result := Min(Max(CalendarRows, 1), tsMaxCalendarRows);
end;
procedure TtsDateTime.SetComboValue;
begin
//ShowMessage('TtsDateTime Create Step 6d3b-1');
FComboMonth.Cell[1, 1] := FComboMonth.Col[1].Combo.Grid.Cell[1, FDisplayMonth];
//ShowMessage('TtsDateTime Create Step 6d3b-2');
FComboMonth.RefreshData(roNone, rpNone);
end;
procedure TtsDateTime.BuildGridData;
begin
CheckMinMaxDate(FDisplayRowInMonth, FDisplayMonth, FDisplayYear);
BuildGridRows(FDisplayRowInMonth, FDisplayMonth, FDisplayYear);
end;
procedure TtsDateTime.RefreshControls;
begin
////ShowMessage('TtsDateTime Create Step 6d3a');
FDateGrid.RefreshData(roBoth, rpNone);
////ShowMessage('TtsDateTime Create Step 6d3b');
SetComboValue;
////ShowMessage('TtsDateTime Create Step 6d3c');
if FTxtYear.Text <> IntToStr(FDisplayYear) then FTxtYear.Text := IntToStr(FDisplayYear);
end;
procedure TtsDateTime.RefreshDates;
begin
if not VarIsEmpty(FSelectedDate) then SetSelectedDate(FSelectedDate);
CheckCurDateTime(True);
end;
procedure TtsDateTime.RefreshData(CheckDates: Boolean);
begin
//ShowMessage('TtsDateTime Create Step 6d1');
BuildGridData;
//ShowMessage('TtsDateTime Create Step 6d2');
if CheckDates then RefreshDates;
//ShowMessage('TtsDateTime Create Step 6d3');
RefreshControls;
//ShowMessage('TtsDateTime Create Step 6d4');
end;
procedure TtsDateTime.CheckRefreshData(CheckDates: Boolean);
begin
if IsUpdating then Exit;
RefreshData(CheckDates);
end;
function TtsDateTime.GetPrevDay(CurDate: TDateTime): TDateTime;
begin
Result := CurDate - 1;
if (DayOfWeek(Result) = 1) and not SelectSunday then Result := Result - 1;
if (DayOfWeek(Result) = 7) and not SelectSaturday then Result := Result - 1;
end;
function TtsDateTime.GetNextDay(CurDate: TDateTime): TDateTime;
begin
Result := CurDate + 1;
if (DayOfWeek(Result) = 7) and not SelectSaturday then Result := Result + 1;
if (DayOfWeek(Result) = 1) and not SelectSunday then Result := Result + 1;
end;
function TtsDateTime.GetValidDate(Value: Variant): TDateTime;
var
Direction: Integer;
NewDate: TDateTime;
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -