⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tsdatetime.pas

📁 企业进销存管理系统
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    begin
        if Canvas.TextWidth(LongMonthNames[I]) > Width then
            Width := Canvas.TextWidth(LongMonthNames[I]);
    end;

    FComboMonth.ClientWidth := Round(Width * 1.3) + FComboMonth.DefaultButtonWidth;
    FComboMonth.DefaultColWidth := FComboMonth.ClientWidth + 1;
    FComboMonth.Col[1].Combo.Grid.Col[1].Width := FComboMonth.Width - FComboMonth.DefaultButtonWidth - 1;
    FComboMonth.Col[1].Combo.Grid.DefaultRowHeight := TextHeight + 2;

    ComboHeight := Max(MinEditControlHeight, TextHeight + 1);
    if ComboHeight mod 2 <> 0 then ComboHeight := ComboHeight + 1;
    FComboMonth.ClientHeight := ComboHeight;
    FComboMonth.DefaultRowHeight := FComboMonth.ClientHeight + 1;
    FComboMonth.DefaultButtonHeight := FComboMonth.DefaultRowHeight - (2 * FComboMonth.ButtonEdgeWidth) - 1;
    FComboMonth.Col[1].Combo.Grid.Font := FCOmboMonth.Font;

    BitmapCombo := TBitmap.Create;
    try
        BitMapCombo.LoadFromResourceName(HInstance,'TSCLNDRCOMBO');
        FComboMonth.CreateDefaultCombo(BitmapCombo, clNone, FComboMonth.DefaultButtonWidth, FComboMonth.DefaultButtonHeight);
    finally
        BitmapCombo.Free;
    end;

    FComboBevel.Width := FComboMonth.Width + 2;
    FComboBevel.Height := FComboMonth.Height + 2;
end;

procedure TtsDateTime.PositionYearEdit(TextHeight: Integer);
begin
    FPnlEditYear.ClientHeight := Max(MinEditControlHeight, FComboMonth.Height + 2);
    if FPnlEditYear.Height mod 2 <> 0 then FPnlEditYear.Height := FPnlEditYear.Height + 1;
    FTxtYear.ClientHeight := TextHeight;
    FTxtYear.Top := (FPnlEditYear.Height - FTxtYear.Height) div 2;
    FTxtYear.ClientWidth := Round(Canvas.TextWidth('0000') * 1.1);
    FPnlEditYear.ClientWidth := FTxtYear.Width + 8;
end;

procedure TtsDateTime.PositionScrollBar;
begin
    FDateScrollBar.Height := FPnlCalendar.Height - 2;
    FDateScrollBar.Top := FPnlCalendar.Top + 1;
    FDateScrollBar.Left := FPnlCalendar.Width + FPnlCalendar.Left + 4;
    if GetSystemMetrics(SM_CXVSCROLL) > 0 then
        FDateScrollBar.Width := GetSystemMetrics(SM_CXVSCROLL);
end;

procedure TtsDateTime.PositionYearButtons;
begin
    FButYearIncr.Height := (FPnlEditYear.Height) div 2;
    FButYearDecr.Height := FButYearIncr.Height;
    FButYearIncr.Top := FPnlEditYear.Top;
    FButYearDecr.Top := FButYearIncr.Top + FButYearIncr.Height;
    FButYearIncr.Width := Round(FButYearIncr.Height * 1.7);
    FButYearDecr.Width := Round(FButYearIncr.Height * 1.7);
end;

procedure TtsDateTime.PositionTimeButtons(TxtOffset, AMPMWidth, AMPMOffset,
                                          ButHeight, ButWidth,
                                          ButIncrTop, ButDecrTop: Integer);
begin
    FButHourIncr.Height := ButHeight;
    FButHourDecr.Height := ButHeight;
    FButHourIncr.Width := ButWidth;
    FButHourDecr.Width := ButWidth;
    FButHourIncr.Top := ButIncrTop;
    FButHourDecr.Top := ButDecrTop;

    FButMinIncr.Height := ButHeight;
    FButMinDecr.Height := ButHeight;
    FButMinIncr.Width := ButWidth;
    FButMinDecr.Width := ButWidth;
    FButMinIncr.Top := ButIncrTop;
    FButMinDecr.Top := ButDecrTop;

    FButSecIncr.Height := ButHeight;
    FButSecDecr.Height := ButHeight;
    FButSecIncr.Width := ButWidth;
    FButSecDecr.Width := ButWidth;
    FButSecIncr.Top := ButIncrTop;
    FButSecDecr.Top := ButDecrTop;

    FButAMPMIncr.Height := ButHeight;
    FButAMPMDecr.Height := ButHeight;
    FButAMPMIncr.Width := AMPMWidth div 2;
    FButAMPMDecr.Width := AMPMWidth div 2;
    FButAMPMIncr.Top := ButIncrTop;
    FButAMPMDecr.Top := ButDecrTop;

    FButHourDecr.Left := FTxtHour.Left - TxtOffset + 1;
    FButHourIncr.Left := FButHourDecr.Left + FButHourDecr.Width;

    FButMinDecr.Left := FTxtMinute.Left - TxtOffset + 1;
    FButMinIncr.Left := FButMinDecr.Left + FButMinDecr.Width;

    if ShowSeconds then
    begin
        FButSecDecr.Left := FTxtSeconds.Left - TxtOffset + 1;
        FButSecIncr.Left := FButSecDecr.Left + FButSecDecr.Width;

        FButAMPMDecr.Left := FTxtAMPM.Left - AMPMOffset;
        FButAMPMIncr.Left := FButAMPMDecr.Left + FButAMPMDecr.Width;
    end
    else
    begin
        FButAMPMDecr.Left := FTxtAMPM.Left;
        FButAMPMIncr.Left := FButAMPMDecr.Left + FButAMPMDecr.Width;
    end;
end;

function TtsDateTime.GetAMPMWidth: Integer;
begin
    Result := Round(Max(Canvas.TextWidth('AM'), Max(Canvas.TextWidth(TimeAMString), Canvas.TextWidth(TimePMString))) * 1.2);
end;

procedure TtsDateTime.PositionTimeControls(TextHeight: Integer);
var
    TxtWidth, AMPMWidth: Integer;
    TxtOffset, AMPMOffset: Integer;
    ButHeight, ButWidth: Integer;
    ButIncrTop, ButDecrTop: Integer;
    TxtTop: Integer;
    PnlTimeWidth: Integer;
begin
    TxtWidth := Round(Canvas.TextWidth('00') * 1.6);
    if TxtWidth mod 2 <> 0 then TxtWidth := TxtWidth + 1;
    TxtWidth := Max(22, TxtWidth);

    AMPMWidth := GetAMPMWidth;
    if AMPMWidth mod 2 <> 0 then AMPMWidth := AMPMWidth + 1;
    AMPMWidth := Max(22, AMPMWidth);
    AMPMOffset := 0;

    FTxtHour.ClientWidth := Round(Canvas.TextWidth('00') * 1.0);
    FTxtMinute.ClientWidth := FTxtHour.ClientWidth;

    if ShowSeconds then
    begin
        FTxtSeconds.ClientWidth := FTxtHour.ClientWidth;
        FTxtSeconds.Visible := True;
        FButSecIncr.Visible := True;
        FButSecDecr.Visible := True;
        FLblSep2.Visible := True;
    end
    else
    begin
        FTxtSeconds.Width := 0;
        FTxtSeconds.Visible := False;
        FButSecIncr.Visible := False;
        FButSecDecr.Visible := False;
        FLblSep2.Visible := False;
    end;

    if FFormat24Hour then
    begin
        FTxtAMPM.Visible := False;
        FTxtAMPM.Width := 0;
        FButAMPMIncr.Visible := False;
        FButAMPMDecr.Visible := False;
    end
    else
    begin
        FTxtAMPM.Visible := True;
        FButAMPMIncr.Visible := True;
        FButAMPMDecr.Visible := True;
        FTxtAMPM.ClientWidth := GetAMPMWidth;
        AMPMOffset := (AMPMWidth - FTxtAMPM.Width) div 2;
        FTxtAMPM.MaxLength := Max(Length(TimeAMString), Length(TimePMString));
    end;

    FLblSep1.Caption := TimeSeparator;
    FLblSep2.Caption := TimeSeparator;

    FTxtHour.ClientHeight := TextHeight;
    FTxtMinute.Height := FTxtHour.Height;
    FTxtSeconds.Height := FTxtHour.Height;
    FTxtAMPM.Height := FTxtHour.Height;
    FLblSep1.Height := FTxtHour.Height;
    FLblSep2.Height := FTxtHour.Height;

    if DateTimeDisplay = dtTime then
        FPnlEditTime.Height := Max(MinEditControlHeight + 4, TextHeight + 1)
    else
        FPnlEditTime.Height := Max(FPnlEditYear.Height, FTxtHour.Height + 2);
    TxtTop := (FPnlEditTime.Height - FTxtHour.Height) div 2;
    FTxtHour.Top := TxtTop;
    FTxtMinute.Top := TxtTop;
    FTxtSeconds.Top := TxtTop;
    FTxtAMPM.Top := TxtTop;
    FLblSep1.Top := Max(1, TxtTop - 1);
    FLblSep2.Top := Max(1, TxtTop - 1);

    TxtOffset := (TxtWidth - FTxtHour.Width) div 2;
    FTxtHour.Left := 1 + TxtOffset;
    FTxtMinute.Left := FTxtHour.Left + TxtWidth + 4;

    if ShowSeconds then
    begin
        FTxtSeconds.Left := FTxtMinute.Left + TxtWidth + 4;
        FTxtAMPM.Left := FTxtSeconds.Left + TxtWidth + 4 + AMPMOffset;
    end
    else
        FTxtAMPM.Left := FTxtMinute.Left + TxtWidth + 4;

    ButHeight := Round(FPnlEditTime.Height * 0.6);
    ButWidth := TxtWidth div 2;
    ButIncrTop := FPnlEditTime.Top + FPnlEditTime.Height + 2;
    ButDecrTop := ButIncrTop;

    FPnlTime.ClientHeight := FPnlEditTime.Height + ButHeight + 3;
    FLblSep1.Left := (FTxtHour.Left + FTxtHour.Width + FTxtMinute.Left - 1) div 2;
    FLblSep2.Left := 1 + FLblSep1.Left + FLblSep1.Width + TxtWidth;

    PositionTimeButtons(TxtOffset, AMPMWidth, AMPMOffset, ButHeight, ButWidth, ButIncrTop, ButDecrTop);

    if FTxtAMPM.Visible then
        PnlTimeWidth := FTxtAMPM.Left + AMPMWidth - AMPMOffset + 3
    else if ShowSeconds then
        PnlTimeWidth := FTxtSeconds.Left + TxtWidth - TxtOffset + 3
    else
        PnlTimeWidth := FTxtMinute.Left + TxtWidth - TxtOffset + 3;

    FPnlEditTime.Width := PnlTimeWidth;
    FPnlTime.Width := PnlTimeWidth;
end;

procedure TtsDateTime.SetButtonGlyphs(ButtonHeight: Integer);
var
    Bitmap: TBitmap;
    Glyph: TBitmap;
begin
    if ButTimeSizeChanged or ButYearSizeChanged then
    begin
        Bitmap := TBitmap.Create;
        Glyph := TBitmap.Create;
        try
            Glyph.Height := ButtonHeight div 2;
            if Glyph.Height mod 2 <> 1 then Glyph.Height := Glyph.Height - 1;
            Glyph.Width := Glyph.Height;

            Bitmap.Width := 5;
            Bitmap.Height := 5;

            Bitmap.Canvas.Brush.Style := bsSolid;
            Bitmap.Canvas.Brush.Color := clBtnFace;
            Bitmap.Canvas.FillRect(Rect(0, 0, Bitmap.Width, Bitmap.Height));
            Bitmap.Canvas.Pen.Color := clBtnText;
            Bitmap.Canvas.Pen.Width := 1;
            Bitmap.Canvas.MoveTo(0, 2);
            Bitmap.Canvas.LineTo(5, 2);

            Glyph.Canvas.StretchDraw(Rect(0, 0, Glyph.Width, Glyph.Height), Bitmap);
            if ButYearSizeChanged then FButYearDecr.Glyph.Assign(Glyph);
            if ButTimeSizeChanged then
            begin
                FButHourDecr.Glyph.Assign(Glyph);
                FButMinDecr.Glyph.Assign(Glyph);
                FButSecDecr.Glyph.Assign(Glyph);
                FButAMPMDecr.Glyph.Assign(Glyph);
            end;

            Bitmap.Canvas.MoveTo(2, 0);
            Bitmap.Canvas.LineTo(2, 5);

            Glyph.Canvas.StretchDraw(Rect(0, 0, Glyph.Width, Glyph.Height), Bitmap);
            if ButYearSizeChanged then FButYearIncr.Glyph.Assign(Glyph);
            if ButTimeSizeChanged then
            begin
                FButHourIncr.Glyph.Assign(Glyph);
                FButMinIncr.Glyph.Assign(Glyph);
                FButSecIncr.Glyph.Assign(Glyph);
                FButAMPMIncr.Glyph.Assign(Glyph);
            end;
        finally
            Bitmap.Free;
            Glyph.Free;
        end;

        SaveButtonHeights;
    end;
end;

procedure TtsDateTime.PositionControls;
var
    I, Width, ButtonHeight: Integer;
    TextHeight: Integer;
    ButYearIncrLeft: Integer;
begin
    if not HandleAllocated then Exit;
    if FInPositionControls then Exit;

    FInPositionControls := True;
    try
        ButYearIncrLeft := 0;
        if Assigned(Font) then Canvas.Font.Assign(Font);
        TextHeight := Canvas.TextHeight(LongMonthNames[1]);

        if DateTimeDisplay in [dtDate, dtDateTime] then
        begin
            PositionDateGrid;
            PositionMonthCombo(TextHeight);
            PositionYearEdit(TextHeight);

            FPnlCalendar.Height := FDateGrid.Rows * FDateGrid.RowHeight[1] + 3;
            FPnlCalendar.Top := FPnlEditYear.Height + 4;
            Width := 0;
            for i := 1 to FDateGrid.Cols do
                if (i > 1) or ShowWeekNumbers then Width := Width + FDateGrid.Col[i].Width;
            FPnlCalendar.Width := Width + 5;

            PositionScrollBar;
            PositionYearButtons;

            ButYearIncrLeft := FComboMonth.Left + FComboMonth.Width + 12 + FPnlEditYear.Width + 1;
            FPnlDate.Height := FPnlCalendar.Top + FPnlCalendar.Height;
            FPnlDate.Width := Max(FDateScrollBar.Left + FDateScrollBar.Width + 1, ButYearIncrLeft + FButYearIncr.Width);
        end;

        if DateTimeDisplay in [dtTime, dtDateTime] then
        begin
            GetHourFormat;
            PositionTimeControls(TextHeight);
        end;

        if PopupForm
            then BorderStyle := bsNone
            else BorderStyle := bsSingle;

        if DateTimeDisplay = dtTime then
        begin
            FPnlTime.Top := 4;
            if not PopupForm then FPnlTime.Left := FPnlTime.Top;;
            SetOkButtonPos;
            FPnlTime.Visible := True;
            FPnlDate.Visible := False;
            if FButOk.Visible
                then ClientWidth := Max(Max(FButOk.Left + FButOk.Width + 8, FButCancel.Left + FButCancel.Width + 8), FPnlTime.Width + 12)
                else ClientWidth := FPnlTime.Left * 2 + FPnlTime.Width + 4;

            if PopupForm then FPnlTime.Left := (ClientWidth - FPnlTime.Width) div 2;
            ButtonHeight := FButHourIncr.ClientHeight;
            FTxtHour.SelStart := 0;
            FTxtHour.SelLength := Length(FTxtHour.Text);
        end
        else if DateTimeDisplay = dtDateTime then
        begin
            FPnlDate.Top := 4;
            FPnlDate.Left := FPnlDate.Top;
            FPnlDate.Visible := True;
            FP

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -