Use the Delphi tstringgrid control to implement calendar Scheduling

Source: Internet
Author: User

In the ERP implementation scheduling module, we hope to intuitively display the daily ordering of machines. We have been worried That Delphi does not have a proper control, so we can't help it first.

:

Key code for drawing a calendar

 Procedure  Tform1.drawcalender;  VaR  Iday, iprocess, days: integer; row, Col: integer;  Begin // Sgcalender. Days: = Daysinamonth (strtoint (cbbyear. Text), strtoint (cbbmonth. Text); sgcalender. colcount: = Days +1  ; Sgcalender. rowcount: = Machinenumber + 1  ; Sgcalender. rowheights [  0 ]: = 25  ; Sgcalender. colwidths [  0 ]: = 80  ;  For Iday: = 1   To Days Do    Begin Sgcalender. cells [iday,  0 ]: = Inttostr (iday );  End  ;  For Iprocess: = 1   To Machinenumber Do    Begin  Sgcalender. cells [  0 , Iprocess]: = '  Server  ' +Inttostr (iprocess );  End  ;  For Row: = 1   To Machinenumber Do    Begin       For Col: = 1   To Days Do       Begin  Sgcalender. cells [col, row]: = Format ( ' Number of orders: % d  ' + '  |  ' + '  Number of completions: % d  ' + '  |  ' + '  Percent success rate: % d  ' , [Random ( 10000 ), Random ( 10000 ), Random (100  )]);  End  ;  End  ;  End ;

 

Because cell content cannot wrap, you need to process it in drawcell.

Procedure tform1.sgcalenderdrawcell (Sender: tobject; ACOl, Arow: integer; rect: trect; State: tgriddrawstate); var S, item: string; D: tstringgrid; I, num: integer; begin D: = tstringgrid (sender); s: = D. cells [ACOl, Arow]; begin D. canvas. font. assign (D. font); // specifies the font with D. canvas do begin brush. color: = clwindow; // specify the cell color if gdfixed in State then brush. color: = D. fixedcolor; font. color: = clwindowtext; fillrect (rect); with d do begin num: = 0;
// Line feed According to '|' If pos ('|', s)> 0 then begin for I: = 0 to length (s) -1 do begin if s [I] <> '| 'then begin item: = item + s [I]; end else begin rect. top: = rect. top + num * 30; drawtext (canvas. handle, pchar (TRIM (item), length (TRIM (item), rect, dt_left or dt_singleline or dt_vcenter); item: = ''; Inc (Num); end; end; If item <> ''then begin rect. top: = rect. top + 30; drawtext (canvas. handle, pchar (TRIM (item), length (TRIM (item), rect, dt_left or dt_singleline or dt_vcenter); end; end else begin // draw fixed row Col drawtext (canvas. handle, pchar (s), length (s), rect, dt_center or dt_singleline or dt_vcenter); end;

Source code download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.