Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's wrong with this word wrap? 1

Status
Not open for further replies.

AP81

Programmer
Apr 11, 2003
740
AU
I have a stringgrid which performs a word-wrap (and does it quite well), however ampersands (&) do not appear in the cell. Then if I click on the cell, it appears. Any ideas on how the solve this problem?

Here is the code:
Code:
procedure TfrmMain.sgInvoiceDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  S: String;
  drawrect :trect;
begin
  //create a word break if a line exceeds column width
  S:= sgInvoice.Cells[ACol, ARow ];
  If Length(S) > 0 Then
    begin
      drawrect := rect;
      DrawText(sgInvoice.canvas.handle,
               Pchar(S), Length(S), drawrect,
               dt_calcrect or dt_wordbreak); // or dt_left );
    If (drawrect.bottom - drawrect.top) >
       (sgInvoice.RowHeights[ARow]) then
      sgInvoice.RowHeights[ARow] := (drawrect.bottom - drawrect.top)
    // changing the row height fires the event again
    else
      begin
        drawrect.Right := rect.right;
        drawrect.Left := rect.Left + 2;
        drawrect.Top := rect.Top + 2;
        sgInvoice.canvas.fillrect( drawrect );
        DrawText(sgInvoice.canvas.handle,
                 Pchar(S), Length(S), drawrect,
                 dt_wordbreak); // or dt_left);
      end;
  end;       
end;




------------------------------------
There's no place like 127.0.0.1
------------------------------------
 
Hi AP81,

include DT_NOPREFIX to dt_wordbreak to avoid processing of prefix character. this is explained in windows SDK :

Turns off processing of prefix characters. Normally, DrawText interprets the mnemonic-prefix character & as a directive to underscore the character that follows, and the mnemonic-prefix characters && as a directive to print a single &. By specifying DT_NOPREFIX, this processing is turned off.

cheers

--------------------------------------
What You See Is What You Get
 
Thanks! Problem fixed. I have tried many things to resolve this, but never would have found that out.

Thanks again.




------------------------------------
There's no place like 127.0.0.1
------------------------------------
 
Hey guys, how did you come across DrawText anyway? Doing a search for it in help (Delphi 4) has brought up a fragmented reference to it, but a proper description of it is not there. Your code works beautifully in D4 so the functionality exists, and it is the sort of thing I would find pretty useful, so if you know where I can get a full explanation I'd be most grateful.
 
msdn.microsoft.com...

--------------------------------------
What You See Is What You Get
 
I did not think that Win calls could look so integrated with Delphi!

Many thanks
 
yo do now! [spin]

--------------------------------------
What You See Is What You Get
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top