Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 Customizing the time/date display of the TDateTimePicker


The TDataTimePicker's time display defaults to showing hours, minutes, and seconds. I would prefer not to show seconds, but there doesn't seem to be a way of changing the format. Is there a way?

  

The underlying API control can be customized using the DTM_SETFORMAT window message. Use the Perform message to send this message and its parameters to the control.

Example in C++:

void __fastcall TForm ::Button Click(TObject *Sender) { DateTimePicker ->Perform(DTM_SETFORMAT, NULL, "hh:mm tt"); // will yeild a display without seconds, like this: "8:30 PM" }

Example in Object Pascal:

procedure TForm .Button Click(Sender: TObject); var s: String; begin s := 'hh:mm tt'; DateTimePicker .Perform(DTM_SETFORMAT, DWord(nil) ,DWord(s)); end;

Consult the Windows API documentation here for further information on formatting strings. Note: This technique bypasses the VCL wrapper around the date time picker by sending a message directly to the Windows control. This causes one problem. If you send a message that sets the formatting to show date elements while the Kind property is set to dtkTime (or vice versa), the date elements will display correctly, but the user may not be able to change those elements (or elements will change incorreclty). Therefore, it is suggested that you be sure the elements you display correspond to the control's Kind.

 

  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use