Anda di halaman 1dari 4

//localizar no richedit procedure TfrmPrincipal.edtPesquisaChange(Sender: TObject); var iPosIni : integer; begin //Carrega o RichEdit com as propriedades iniciais RichEdit.

SelStart := 0; RichEdit.SelLength := length(RichEdit.Text); RichEdit.SelAttributes.color := clBlack; RichEdit.SelAttributes.style := []; RichEdit.SelAttributes.Size := 8; //Encontra e atribui a posio inicial do texto no RichEdit iPosIni := RichEdit.FindText(edtPesquisa.Text, 0, length(RichEdit.Text), []); // Verifica se o texto foi encontrado if iPosIni >= 0 then begin RichEdit.SelStart := iPosIni; RichEdit.SelLength := length(edtPesquisa.Text); RichEdit.SelAttributes.color := clRed; RichEdit.SelAttributes.style := [fsBold]; RichEdit.SelAttributes.Size := RichEdit.SelAttributes.Size + 16; end; end;

//funo 2 Procedure TForm1.Button1Click(Sender: TObject); var i:integer; begin i:= pos( edit1.text,RichEdit1.Text)-1; RichEdit1.SelStart := i; RichEdit1.SelLength := length(edit1.text); RichEdit1.SelAttributes.Color := ClRed; RichEdit1.SelAttributes.Style := [fsBold]; end;

//visualizar impresso 1 - coloca um QuickRep no seu form 2 - vai nas propriedades do QuickRep em bands e coloque Has Title = true(isso cr ia uma banda titulo pra voc) 3- coloca o componente QRRichText(da banda QReport) dentro da banda title e coloque esse comando em um button QUOTE procedure TForm1.Button1Click(Sender: TObject); Var ms :TMemoryStream; begin ms := TMemoryStream.Create; RichEdit1.Lines.SaveToStream(ms); ms.Position := 0;

QRRichText1.Lines.LoadFromStream(ms); ms.Free; QuickRep1.Preview; end;

//dica2 esse codigo salva o conteudo do seu RichEdit1 em uma variavel MemoryStream e dep ois oQRRichText1 carrega o conteudo dessa variavel, dessa forma o seu teste mant em a formatao!! ps: voc pode colocar o seu QuickRep em um formulario aparte(Fica mais proficional ). Erso, este procedimento (utilizar um TMemoryStream - intermedirio) resolve o "bug " que h no componente TQRRichEdit que ao ser associado a um TRichEdit, herda tambm sua cor (a do fundo) - assim se a cor de fundo do RichEdit clWindow, ao visuali zar, o texto o fundo da rea aparecer nesta cor, independente de voc ter configurado com clWhite a cor do TQRRichEdit. Se isto no for um problema, e seguindo sua sugesto de utilizar outro form para alo jar o QuickReport (digamos, FrmPreviewRTF), ento bastaria apenas criar um procedi mento neste form em que voc recebe o TRichEdit do editor e no corpo do procedimen to atribui o mesmo a propriedade ParentRichEdit do TQRRichEdit. Na visualizao a rea do texto ter a cor da do fundo do RichEdit do editor, mas na impresso este fundo no ser impresso - fica "branco". No evento OnClick do boto preview na tela do editor CODE // estou tambm supondo que o FrmPreviewRTF ser criado em tempo de execuo procedure TEditor.BtnPreviewClick(Sender :TObject); begin FrmPreviewRTF := TFrmPreviewRTF.Create(Self); try FrmPreviewRTF.PreviewRTF(RichEdit1); finally FrmPreviewRTF.Free; end; end; Procedimento no form TFrmPreviewRTF para visualizao do texto CODE type TFrmPreviewRTF = class(TForm) ... public procedure PreviewRTF(RichEdit :TRichEdit); end; ... procedure TFrmPreviewRTF.PreviewRTF(RichEdit :TRichEdit); begin QRRichText1.ParentRichEdit := RichEdit; QuickRep1.Preview;

end; Isabela, algumas dicas com relao a construo do preview no QuickReport.: - Adicione uma banda detalhe sem preocupar-se com sua altura - pode ser mnima; - Coloque o TQRRichEdit nela e o importante que voc ajuste a largura; A altura, p ode deixar mnima, mas habilite a propriedade AutoStretch (True); - Se voc vai configurar margens e similares, voc pode alterar esses parmetros no qu ick sem problemas, mas lembre-se de mudar a largura do TQRRichEdit de acordo com a largura da banda detalhe (para evitar cortes ou erros na formatao); Boa sorte.

//Configurar margens de impresso The TRichEdit Delphi control is a wrapper for a Windows rich text edit control. Rich text edit controls let the user enter (edit, format, print, and save) text that includes font and paragraph formatting. Rich Edit provides a simple Print method allowing you to programmatically print the (formatted) contents of the rich edit to the active printer - with a single line of code. Unfortunately, there's no exposed functionality to set printer margins as you ar e accustomed to in various word processing applications. Set Rich Edit Printing Margins A custom Delphi procedure SetRichEditMargins demonstrate how to print, set the P ageRect property for a TRichEdit with arbitrary margins. The PageRect property s pecifies the dimensions, in pixels, of the logical page size used when printing the contents of a rich text edit control. The first 4 parameters specify the left, right, top and bottom margin in inches (1 IN = 2.54 cm). The last parameter is the rich edit control. (* Set RichEdit margins in Inches (1 in = 2.54 cm) for the active printer *) procedure SetRichEditMargins( const mLeft, mRight, mTop, mBottom: extended; const re : TRichEdit) ; var ppiX, ppiY : integer; spaceLeft, spaceTop : integer; r : TRect; begin // pixels per inch ppiX := GetDeviceCaps(Printer.Handle, LOGPIXELSX) ; ppiY := GetDeviceCaps(Printer.Handle, LOGPIXELSY) ; // non-printable margins spaceLeft := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX) ; spaceTop := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY) ; //calc margins R.Left := Round(ppiX * mLeft) - spaceLeft;

R.Right := Printer.PageWidth - Round(ppiX * mRight) - spaceLeft; R.Top := Round(ppiY * mTop) - spaceTop; R.Bottom := Printer.PageHeight - Round(ppiY * mBottom) - spaceTop; // set margins re.PageRect := r; end; Note: do not mix "printer margins" with the "Margins" property in the VCL. Here's a simple usage example: SetRichEditMargins(1, 1, 0.5, 0.5, richEdit1) ; richEdit1.Print('Printing with margins') ;

Anda mungkin juga menyukai