Week.cpp
上传用户:lulishicai
上传日期:2010-03-01
资源大小:13202k
文件大小:5k
源码类别:

Delphi/CppBuilder

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Week.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "CCALENDR"
  8. #pragma link "CSPIN"
  9. #pragma resource "*.dfm"
  10. TForm1 *Form1;
  11. //---------------------------------------------------------------------------
  12. __fastcall TForm1::TForm1(TComponent* Owner)
  13.         : TForm(Owner)
  14. {
  15. }
  16. //---------------------------------------------------------------------------
  17. void __fastcall TForm1::FormCreate(TObject *Sender)
  18. {
  19. Form1->Edit1->Text="请输入年份";
  20. Form1->Edit2->Text="请输入月份";
  21. Form1->Edit3->Text="请输入日期";
  22. //文本控件的初始化
  23. Form1->CCalendar1->Year=1977;
  24. Form1->CCalendar1->Month=1;
  25. Form1->CCalendar1->Day=19;
  26. //CCalendar控件的初始化
  27. Form1->CCalendar1->Enabled=false;
  28. Form1->Edit1->Enabled=false;
  29. Form1->Edit2->Enabled=false;
  30. Form1->Edit3->Enabled=false;
  31. Form1->CSpinButton1->Enabled=false;
  32. Form1->CSpinButton2->Enabled=false;
  33. Form1->CSpinButton3->Enabled=false;
  34. Form1->Timer1->Enabled=false;
  35. //设置控件的有效状态
  36. }
  37. //---------------------------------------------------------------------------
  38. void __fastcall TForm1::Button1Click(TObject *Sender)
  39. {
  40. Form1->CCalendar1->Enabled=true;
  41. Form1->Edit1->Enabled=true;
  42. Form1->Edit2->Enabled=true;
  43. Form1->Edit3->Enabled=true;
  44. Form1->CSpinButton1->Enabled=true;
  45. Form1->CSpinButton2->Enabled=true;
  46. Form1->CSpinButton3->Enabled=true;
  47. Form1->Timer1->Enabled=true;
  48. //设置控件的有效状态
  49. Form1->CCalendar1->Year=StrToInt(Form1->Edit1->Text);
  50. Form1->CCalendar1->Month=StrToInt(Form1->Edit2->Text);
  51. Form1->CCalendar1->Day=StrToInt(Form1->Edit3->Text);
  52. //查询文本框中显示的日期
  53. }
  54. //---------------------------------------------------------------------------
  55. void __fastcall TForm1::CCalendar1Change(TObject *Sender)
  56. {
  57. Form1->Edit1->Text=IntToStr(Form1->CCalendar1->Year);
  58. Form1->Edit2->Text=IntToStr(Form1->CCalendar1->Month);
  59. Form1->Edit3->Text=IntToStr(Form1->CCalendar1->Day);
  60. //在文本框中显示日期信息
  61. }
  62. //---------------------------------------------------------------------------
  63. void __fastcall TForm1::CSpinButton1DownClick(TObject *Sender)
  64. {
  65. if (StrToInt(Form1->Edit1->Text)>1)
  66. Form1->Edit1->Text=IntToStr(StrToInt(Form1->Edit1->Text)-1);
  67. //年数减一
  68. /*或者用下面的方法:
  69.  Form1->CCalendar1->PrevYear;*/
  70. }
  71. //---------------------------------------------------------------------------
  72. void __fastcall TForm1::CSpinButton1UpClick(TObject *Sender)
  73. {
  74. if (StrToInt(Form1->Edit1->Text)<9999)
  75. Form1->Edit1->Text=IntToStr(StrToInt(Form1->Edit1->Text)+1);
  76. //年数加一
  77. /*或者用下面的方法:
  78.  Form1->CCalendar1->NextYear;*/
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TForm1::CSpinButton2DownClick(TObject *Sender)
  82. {
  83. if (StrToInt(Form1->Edit2->Text)>1)
  84. Form1->Edit2->Text=IntToStr(StrToInt(Form1->Edit2->Text)-1);
  85. //月份减一
  86. /*或者用下面的方法
  87.  Form1->CCalendar1->PrevMonth;*/
  88. }
  89. //---------------------------------------------------------------------------
  90. void __fastcall TForm1::CSpinButton2UpClick(TObject *Sender)
  91. {
  92. if (StrToInt(Form1->Edit2->Text)<12)
  93. Form1->Edit2->Text=IntToStr(StrToInt(Form1->Edit2->Text)+1);
  94. //月份加一
  95. /*或者用下面的方法
  96.  Form1->CCalendar1->NextMonth;*/
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TForm1::CSpinButton3DownClick(TObject *Sender)
  100. {
  101. if (StrToInt(Form1->Edit3->Text)>1)
  102. Form1->Edit3->Text=IntToStr(StrToInt(Form1->Edit3->Text)-1);
  103. //日期减一
  104. }
  105. //---------------------------------------------------------------------------
  106. void __fastcall TForm1::CSpinButton3UpClick(TObject *Sender)
  107. {
  108. if (StrToInt(Form1->Edit3->Text)<31)
  109. Form1->Edit3->Text=IntToStr(StrToInt(Form1->Edit3->Text)+1);
  110. //日期加一
  111. }
  112. //---------------------------------------------------------------------------
  113. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  114. {
  115. Form1->Edit4->Text=TimeToStr(Time());
  116. //动态显示系统时间
  117. }
  118. //---------------------------------------------------------------------------
  119. void __fastcall TForm1::Edit1Change(TObject *Sender)
  120. {
  121. Form1->CCalendar1->Year=StrToInt(Form1->Edit1->Text);
  122. //年数改变
  123. }
  124. //---------------------------------------------------------------------------
  125. void __fastcall TForm1::Edit2Change(TObject *Sender)
  126. {
  127. Form1->CCalendar1->Month=StrToInt(Form1->Edit2->Text);
  128. //月份改变
  129. }
  130. //---------------------------------------------------------------------------
  131. void __fastcall TForm1::Edit3Change(TObject *Sender)
  132. {
  133. Form1->CCalendar1->Day=StrToInt(Form1->Edit3->Text);
  134. //日期改变
  135. }
  136. //---------------------------------------------------------------------------