Example 15 : Rich edit drag & drop and print + enhanced row/column moveWith the new rich text capabilities, you can now drag and drop rich text between cells in a TAdvStringGrid as well as all rich edit controls, MS Word, MS Excel, Outlook etc... TAdvStringGrid can now print cells with rich text content as well. For those not wanting to enable rich text drag and drop, it is as simple as setting the property TAdvStringGrid.OleDropRTF to false.
This demo also shows the new enhanced column move interface. Now, arrows indicate the position where the moved column will be placed. The arrow color can be set through the public property ArrowColor. This enhanced column move is enabled when the property EnhRowColLMove is true and goColMoving is true in Options.
Once again, all this functionality is available with a few lines of code. Most code goes into the initialization of the rich text cells in the formcreate event hander. Here is an example of how to specify a rich text cell programmatically. After constructing the rich text through the richedit property, the rich text is transferred to the cell with the method : richtocell(acol,arow,richedit).
with advstringgrid1 do begin richedit.text := 'Rich text'; richedit.selstart := 0; richedit.sellength := 4; richedit.selattributes.Color := clRed; richedit.selattributes.Style := [fsBold]; richedit.selstart := 5; richedit.sellength := 4; richedit.selattributes.Color := clBlue; richedit.selattributes.Style := [fsItalic]; richtocell(0,1,richedit); end;
When the properties OleDropTarget and OleDropSource are set true, cells can be dragged by clicking on its borders to other cells within the grid or to MS Word, MS Excell, rich edit controls etc...
Printing the grid with rich text content is simply invoking the Print method. For a pagepreview, an extra form is constructed:
procedure TForm1.Button1Click(Sender: TObject); var pagepreview:TPagepreview; begin pagepreview:=TPagepreview.Create(self,advstringgrid1); try pagepreview.Showmodal; finally pagepreview.Free; end; end;
In this preview form, a paintbox painting routine handles the preview :
if prevctrl is TAdvStringGrid then (prevctrl as TAdvStringGrid).printpreview(paintbox1.Canvas,paintbox1.ClientRect);
Delphi project & source files for downloading included in the main demos distribution for Delphi.