RtfLabel, Version 1.3b (alt)
Hinweis: dies ist nicht die neueste Version!
Datei: Sample/rlsamp.pas
{ rlsamp.pas This file is part of the demo project for the TRtfLabel component: http://flocke.vssd.de/prog/code/pascal/rtflabel/ Copyright (C) 2006 Volker Siebert <flocke@vssd.de> All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. } unit rlsamp; interface {$I Rich3Conf.inc} uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, RtfLabel; type TFormRtfLabelExample = class(TForm) Memo1: TMemo; Panel1: TPanel; ScrollBox1: TScrollBox; CheckBox1: TCheckBox; CheckBox2: TCheckBox; CheckBox3: TCheckBox; CheckBox4: TCheckBox; Button1: TButton; Button2: TButton; OpenDialog1: TOpenDialog; PaintBox1: TPaintBox; Label1: TLabel; ComboBox1: TComboBox; Panel2: TPanel; Label2: TLabel; ComboBox2: TComboBox; procedure ScrollBox1Resize(Sender: TObject); procedure PaintBox1Paint(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure CheckBox4Click(Sender: TObject); procedure CheckBox3Click(Sender: TObject); procedure CheckBox2Click(Sender: TObject); procedure CheckBox1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure ComboBox1Click(Sender: TObject); procedure ComboBox2Click(Sender: TObject); procedure FormShow(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } RtfLabel1: TRtfLabel; procedure CreateLabel; end; var FormRtfLabelExample: TFormRtfLabelExample; implementation {$R *.dfm} uses {$IFDEF RICHEDIT_DEBUG} Debugging, DebugOutputForm, {$ENDIF} RichEditDll; const CDefaultText = '{\rtf1\ansi\ansicpg1252' + '{\colortbl ;\red255\green0\blue128;\red224\green255\blue0;}{'#13#10 + 'Enter your text here, using normal RTF code for markup ' + '(\b bold\b0 , \i italic\i0 , '#13#10 + '\ul underline\ul0 for example), ' + 'then press the {\b {\ul U}pdate} button\par'#13#10 + 'You can also press the {\cf1\b {\ul L}oad} button and ' + 'take a look at some of the sample files or '#13#10 + 'browse your {\fs36 {\super hard}{\sub disk} }and ' + '{\highlight2\b pick some} of your own RTF files...' + '}}'; procedure TFormRtfLabelExample.Button1Click(Sender: TObject); begin OpenDialog1.FileName := ''; if OpenDialog1.Execute then begin RtfLabel1.LoadFromFile(OpenDialog1.FileName); try // Text may be too long under Windows 95/98/ME Memo1.Lines.Text := RtfLabel1.Caption; except MessageBeep(MB_ICONSTOP); end; end; end; procedure TFormRtfLabelExample.Button2Click(Sender: TObject); begin RtfLabel1.Invalidate; RtfLabel1.Caption := Memo1.Lines.Text; end; procedure TFormRtfLabelExample.CheckBox1Click(Sender: TObject); begin RtfLabel1.Transparent := CheckBox1.Checked; end; procedure TFormRtfLabelExample.CheckBox2Click(Sender: TObject); begin RtfLabel1.Wordwrap := CheckBox2.Checked; if RtfLabel1.Wordwrap then RtfLabel1.Width := ScrollBox1.ClientWidth; end; procedure TFormRtfLabelExample.CheckBox3Click(Sender: TObject); begin if CheckBox3.Checked then RtfLabel1.Padding.Rect := Rect(4, 4, 4, 4) else RtfLabel1.Padding.Rect := Rect(0, 0, 0, 0); end; procedure TFormRtfLabelExample.CheckBox4Click(Sender: TObject); begin RtfLabel1.AutoSize := CheckBox4.Checked; if not RtfLabel1.AutoSize then begin RtfLabel1.Width := ScrollBox1.ClientWidth; RtfLabel1.Height := ScrollBox1.ClientHeight; end; end; procedure TFormRtfLabelExample.ComboBox1Click(Sender: TObject); begin RtfLabel1.Zoom := StrToIntDef(ComboBox1.Items[ComboBox1.ItemIndex], 100); end; procedure TFormRtfLabelExample.ComboBox2Click(Sender: TObject); var k: Integer; v: TRichEditVersion; begin k := ComboBox2.ItemIndex; v := TRichEditVersion(Integer(ComboBox2.Items.Objects[k])); if v in UseRichEditVersions then exit; UseRichEditVersions := [v]; CreateLabel; end; procedure TFormRtfLabelExample.CreateLabel; var c: string; l: TRtfLabel; begin if RtfLabel1 <> nil then c := RtfLabel1.Caption else c := CDefaultText; l := TRtfLabel.Create(Self); with l do begin Parent := ScrollBox1; Left := 0; Top := 0; Color := clYellow; ParentFont := False; Font.Name := 'Times New Roman'; Font.Size := 12; Transparent := True; AutoSize := False; if RtfLabel1 <> nil then begin Width := RtfLabel1.Width; Height := RtfLabel1.Height; end; Caption := c; end; FreeAndNil(RtfLabel1); RtfLabel1 := l; CheckBox1Click(CheckBox1); CheckBox2Click(CheckBox2); CheckBox3Click(CheckBox3); CheckBox4Click(CheckBox4); ComboBox1Click(ComboBox1); end; procedure TFormRtfLabelExample.FormCreate(Sender: TObject); var a: TRichEditVersions; v, v1: TRichEditVersion; s: string; begin if Screen.Fonts.IndexOf('Tahoma') >= 0 then Font.Name := 'Tahoma'; {$IFDEF RICHEDIT_DEBUG} RichEditDebugOutputProc := DebugOutputLine; {$ENDIF} Constraints.MinWidth := (ComboBox2.Left + ComboBox2.Width) + (ClientWidth - Panel2.Left) + Width - ClientWidth; Constraints.MinHeight := ScrollBox1.Top + 48 + Height - ClientHeight; Icon.Assign(Application.Icon); ComboBox1.ItemIndex := ComboBox1.Items.IndexOf(' 100'); a := AvailableRichEditModules; v1 := rvNone; for v := Low(TRichEditVersion) to High(TRichEditVersion) do if v in a then with RichEditModules[v] do begin //if v1 = rvNone then // uncomment to pick the smallest version available v1 := v; s := Format('%d.%d', [Version div 10, Version mod 10]); ComboBox2.Items.AddObject(s, Pointer(Ord(v))); end; UseRichEditVersions := [v1]; v := GetRichEditModule; with RichEditModules[v] do s := Format('%d.%d', [Version div 10, Version mod 10]); ComboBox2.ItemIndex := ComboBox2.Items.IndexOf(s); UseRichEditVersions := [v]; Memo1.Lines.Text := CDefaultText; CreateLabel; end; procedure TFormRtfLabelExample.FormShow(Sender: TObject); begin {$IFDEF RICHEDIT_DEBUG} DebugOutputLine('TFormRtfLabelExample.FormShow'); frmDebugOutputForm.Visible := True; {$ENDIF} end; procedure TFormRtfLabelExample.PaintBox1Paint(Sender: TObject); var X, Y, W, H: Integer; begin W := PaintBox1.ClientWidth; H := PaintBox1.ClientHeight; PaintBox1.Canvas.Pen.Color := RGB(224, 224, 244); X := 10; while X < W do begin PaintBox1.Canvas.MoveTo(X, 0); PaintBox1.Canvas.LineTo(X, H); inc(X, 10); end; Y := 10; while Y < H do begin PaintBox1.Canvas.MoveTo(0, Y); PaintBox1.Canvas.LineTo(W, Y); inc(Y, 10); end; end; procedure TFormRtfLabelExample.ScrollBox1Resize(Sender: TObject); begin if not RtfLabel1.AutoSize then begin RtfLabel1.Width := ScrollBox1.ClientWidth; RtfLabel1.Height := ScrollBox1.ClientHeight; end else if RtfLabel1.Wordwrap then RtfLabel1.Width := ScrollBox1.ClientWidth; end; end. |