Sign in Join
Wiki copytemporary

TCalendarDialog/zh CN: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: TCalendarDialog/zh CN

OldNewLine
1+**TCalendarDialog** ![](/wiki-images/5/55/Tcalendardialog.png) 就是能帮你选择日期的一个控件而已. 在 [[Dialogs tab]] 的 [[Component Palette]].
2+
3+<figure>
4+<img src="component-TCalendarDialog.png" title="component-TCalendarDialog.png" />
5+<figcaption>component-TCalendarDialog.png</figcaption>
6+</figure>
7+
8+Execute [[Method|方法]] 来显示对话框. 选择日期后返回 [[True|true]] , 未选择就返回[[False|false]] .
9+
10+## 样例
11+
12+1. 菜单中选择 工程/新建工程…
13+2. 添加 TCalendarDialog 控件 ![](/wiki-images/5/55/Tcalendardialog.png) 到 [[TForm|窗体]].\
14+ 位置随意,因为此控件为不显示控件 [[runtime|run time]] 仅编辑状态可见. \<br \\\> ![](/wiki-images/7/72/Component_Palette_Dialogs.png) \<br \\\> 在 [[Dialogs tab]] 的 [[Component Palette|component palette]]\
15+3. 添加 [[TButton|button]] ![](/wiki-images/b/b2/Tbutton.png) 到窗体.
16+4. [[IDE Window: Object Inspector|对象查看器]] 中查看按钮的事件,在OnClick事件右侧点击 ... 按钮,添加对应的代码。
17+5. 完成代码:
18+
19+``` pascal
20+procedure TForm1.Button1Click(Sender: TObject);
21+var
22+ dt:tdatetime;
23+ calendarSettings:TDisplaySettings;
24+begin
25+ dt:= now;
26+ CalendarDialog1.Date := dt;
27+ calendarSettings:= [dsShowWeekNumbers,dsStartMonday];
28+ CalendarDialog1.Title:='Select a date';
29+ CalendarDialog1.DisplaySettings:= calendarSettings;
30+ if CalendarDialog1.Execute then
31+ begin
32+ dt:= CalendarDialog1.Date;
33+ ShowMessage( 'The selected date is '+FormatDateTime( 'yyyy-mm-dd',dt ));
34+ end
35+ else
36+ ShowMessage( 'Today is '+FormatDateTime( 'yyyy-mm-dd',dt ));
37+end;
38+```
39+
40+## 参考资料
41+
42+- [[doc:lcl/dialogs/tcalendardialog.html|TCalendarDialog doc]]
43+- [[TDBDateTimePicker]]
44+- [[TDateTimePicker]]
45+- [[TDateEdit]]
46+- [[TTimeEdit]]
47+- [[TDateTime]]
48+
49+---
50+*From the Free Pascal wiki, page "TCalendarDialog/zh CN", as it stood on 2020-05-03 after a change by TyphonFinger, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history