trichview.support
Re: How to use this component? |
Author |
Message |
Sergey Tkachenko |
Posted: 07/20/2003 22:48:12 > Thanks Sergey. > > I am at the absolute beginners level, so please excuse my questions. I guess > they are pretty naive:) I'll try to help as much as I can. Besides, there are demos from where you can paste a code or from which you can make a base for your project. > > Now, if I make these styles Normal - Bold - Underline what if the user > clicks both the btnBold and the btnUnderline, do I have to make a fourth > style "BoldAndUnderline"? This is may be a solution, but it is imperfect. If the selection has text of multiple formatting, after calling ApplyTextStyle all the selected text will have the same formatting (normal or bold or underline or bold-underline). If it satisfies you, and a number of formatting that you want to use is limited (and you can add all of them at design time), you can use this method. Otherwise, use either RichViewActions (the simplest way, writing code is not necessary, highly recommended for a beginner) or the method like in the "Editor 2" demo. If you'll decide to use RichViewActions (http://www.trichview.com/resources/actions/), just skip the rest of this posting. I'll try to explain the latter. == Implementing Bold, Italic and Underline buttons without RichViewActions == You need to do the following things: - create speed buttons "Bold", "Italic", "Underline", etc. Set GroupIndex of these buttons to different integer nonzero values, and AllowAllUp to True (after this, these buttons will work as switches). Call them btnBold, btnItalic, btnUnderline. - define constants const TEXT_BOLD = 1; TEXT_ITALIC = 2; TEXT_UNDERLINE = 3; - in OnClick of "bold" button write procedure TForm1.btnBoldClick(Sender: TObject); begin rve.ApplyStyleConversion(TEXT_BOLD); end; The same for other buttons - process RichViewEdit.OnStyleConversion (just copy the code from here, assuming that rvs is TRVStyle linked to the editor rve) procedure TForm1.rveStyleConversion(Sender: TCustomRichViewEdit; StyleNo, UserData: Integer; AppliedToText: Boolean; var NewStyleNo: Integer); var FontInfo: TFontInfo; begin FontInfo := TFontInfo.Create(nil); try FontInfo.Assign(rvs.TextStyles[StyleNo]); case UserData of TEXT_BOLD: if btnBold.Down then FontInfo.Style := FontInfo.Style+[fsBold] else FontInfo.Style := FontInfo.Style-[fsBold]; TEXT_ITALIC: if btnItalic.Down then FontInfo.Style := FontInfo.Style+[fsItalic] else FontInfo.Style := FontInfo.Style-[fsItalic]; TEXT_UNDERLINE: if btnUnderline.Down then FontInfo.Style := FontInfo.Style+[fsUnderline] else FontInfo.Style := FontInfo.Style-[fsUnderline]; end; NewStyleNo := rvs.TextStyles.FindSuchStyle(StyleNo,FontInfo,RVAllFontInfoProperties); if NewStyleNo=-1 then begin rvs.TextStyles.Add; NewStyleNo := rvs.TextStyles.Count-1; rvs.TextStyles[NewStyleNo].Assign(FontInfo); rvs.TextStyles[NewStyleNo].Standard := False; end; finally FontInfo.Free; end; end; - process RichViewEdit.OnCurTextStyleChange: procedure TForm1.rveCurTextStyleChanged(Sender: TObject); var fi: TFontInfo; begin fi := rvs.TextStyles[rve.CurTextStyleNo]; btnBold.Down := fsBold in fi.Style; btnItalic.Down := fsItalic in fi.Style; btnUnderline.Down := fsUnderline in fi.Style; end; More advanced example is in Demos\Delphi\Editors\Editor 2\ In order to save documents created by this method or by RichViewActions, you need to change values of some properties. Right click the editor in Delphi, choose "Settings" in the context menu, set "Allow adding styles dynamically". |
Powered by ABC Amber Outlook Express Converter