本文介绍了当用户选择日期时更正datetimepicker上的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户在我的TDateTimePicker中选择一个值时,我想将要设置的值重写为与选定值一起开始的一周。
When a user selects a value in my TDateTimePicker I want to override the to-be-set value to the start of the week that goes with the selected value.
我尝试在OnChange事件中设置它,但是在完成事件之后,最初选择的值将被设置。
I tried setting it in the OnChange event, but then the originally selected value will be set right after I finished the event.
我该怎么做? p>
How would I go about this?
推荐答案
使用ONCloseUp事件 - 此示例适用于我(Delphi 7,WinXP)
use the "ONCloseUp" event - this sample works for me (Delphi 7, WinXP)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, DateUtils, StdCtrls;
type
TForm1 = class(TForm)
dtp1: TDateTimePicker;
btn1: TButton;
edt1: TEdit;
procedure btn1Click(Sender: TObject);
procedure dtp1CloseUp(Sender: TObject);
private
{ Private declarations }
procedure SetDayToMonday();
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.SetDayToMonday;
begin
dtp1.DateTime := dtp1.DateTime - DayOfTheWeek(dtp1.DateTime) + 1;
end;
procedure TForm1.dtp1CloseUp(Sender: TObject);
begin
SetDayToMonday;
end;
end.
- reinhard: - )
--reinhard :-)
这篇关于当用户选择日期时更正datetimepicker上的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!