Solved

Richedit and trackbar

Posted on 1998-08-19
5
568 Views
Last Modified: 2013-11-22
hi,

is it possible to replace the Richedit scrollbars, with a Slider? (I'm planning to use the RXSlider), basically I want the slider to become visible once the text goes out of the window (vertically) and then the distance between the slider is divided with the amount of lines in the text. How do I do this? Example appreciated.
0
Comment
Question by:hellfire052497
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Expert Comment

by:Matvey
ID: 1337279
Menawhile just the theory I have in mind:

-You hide all the scrollbars TRichEdit has.
-Put sliders instead. Nothing automatic for this - just draw them in the place the scrollbars were.
-In your slider OnScroll even, send WM_SCROLL to the background RichEdit.
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 200 total points
ID: 1337280
Ok, here some code to hit you on the road :

LOT's still have to be changed!!!

1. Algorithem to move scrollbar isn't well_thought!!!
2. ...
3. ...
4. Sleep tight!

Put a panel on the form, in panel add a richedit and an rxslider :

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  RXSlider, StdCtrls, ComCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    RxSlider1: TRxSlider;
    Button1: TButton;
    RichEdit1: TRichEdit;
    procedure FormCreate(Sender: TObject);
    procedure RxSlider1Change(Sender: TObject);
    procedure RichEdit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
    OldPosition : Longint;
    fMaxValue : longint;
    fCurPos : longint;
    ByHand : Boolean;
    function GetMaxValue:Longint;
    function GetCurPos:Longint;
  public
    { Public declarations }
    property MaxValue : Longint read GetMaxValue;
    property CurPos : longint read GetCurPos;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

function TForm1.GetCurPos: Longint;
begin
 { I'm totally not sure of this algorithem !!!! It's late }
 { And I can hardly think now }
 result :=  richedit1.SelStart div richedit1.Font.size;
end;

function TForm1.GetMaxValue:Longint;
begin
 { I'm totally not sure of this algorithem !!!! It's late }
 { And I can hardly think now, why div 2??? I don't know! }

 {PUT HERE A CORRECT ALGORITHEM!!!! THIS IS NOT WEL_THOUGHT}

 Result := Richedit1.Lines.Count - ((Richedit1.Height div Richedit1.Font.size) div 2);
end;

procedure TForm1.FormCreate(Sender: TObject);
var i: integer;
begin
 for i:=1 to 17 do Richedit1.lines.Add('Line'+IntToStr(i));
 panel1.Height := 233;
 panel1.width := 241;
 RxSlider1.Width := 32;
 RxSlider1.Orientation := soVertical;
 RxSlider1.ALign := alRight;
 RichEdit.Scrollbars := ssNone;
 RichEdit1.Align := alClient;
 RxSlider1.MinValue := 1;
 RxSlider1.Increment := 1;
 RxSlider1.MaxValue := Maxvalue;
 RxSlider1.Value := RxSlider1.MaxValue;
 OldPosition := RxSlider1.MaxValue;
end;

procedure TForm1.RxSlider1Change(Sender: TObject);
begin
 { USE HERE CORRECT ALGORITHEM TO CHECK IF SCROLL IS NEEDED!}
 if not ByHand then begin
  if (OldPosition <> RxSlider1.MinValue) AND (OldPosition > RxSlider1.Value) then
    sendmessage(richedit1.Handle, WM_VSCroll,1,0);   {DOWN}
  if (OldPosition <> RxSlider1.MaxValue+RxSlider1.MinValue) AND (OldPosition < RxSlider1.Value) then
   sendmessage(richedit1.Handle, WM_VSCroll,0,1);   {UP}
 end;
  OldPosition := RxSlider1.Value;
end;

procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 ByHand := True;
 if KEY = VK_DOWN then
  if (CurPos <> RichEdit1.Lines.Count) and
   (CurPos > (Richedit1.Lines.count-MaxValue)) then
   RxSlider1.Value := RxSlider1.Value-RxSlider1.Increment;
 if KEY = VK_UP then
  if (CurPos <> 0) and
   (CurPos < MaxValue) then
   RxSlider1.Value := RxSlider1.Value+RxSlider1.Increment;
 ByHand := false;
end;

end.

Goodluck with it!

Zif.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337281
This is in the OnChange of the RxSlider....

procedure TForm1.RxSlider1Change(Sender: TObject);
begin
    SendMessage(RichEdit1.Handle,WM_VSCROLL,RXSlider1.Value, 0);
end;

The RXSlider1.Value maybe won't be exact so you'll have to think of a way so that it scrolls right...
something like this....

procedure TForm1.RxSlider1Change(Sender: TObject);
var
    How_Much_To_Scroll : Integer;
begin
{This is the key on how much to scroll}
    How_Much_To_Scroll := RXSlider1.Value div RichEdit1.Lines.Count - 1;

    SendMessage(RichEdit1.Handle,WM_VSCROLL, How_Much_To_Scroll, 0);
end;

If you want to scroll back i guess the value has to be -How_Much_To_Scroll

That's for vertical scrolling////

Regards,
Viktor Ivanov
0
 

Author Comment

by:hellfire052497
ID: 1337282
hi there,

Zifnabs response is the only one that makes it work, but it is far from Complete, for example when adding text the slider doesn't jump to the bottom, so when scrolling down, it goes in blank territory, going up you can forget. And when scrolling in richedit the slider remains in the same position.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1337283
hellfire,

sorry for responding so lately, you're correct about it, it isn't finished... that's because I hadn't much time when I made it.

Correct about adding text : that's not in the source.

BUT about scrolling in richedit... this should be in it!!!
(PS. Only arrow up and down, not page-up, page down..)

This is the code for respons of the scrollbar when scrolling in richedit...

procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 ByHand := True;
 if KEY = VK_DOWN then
  if (CurPos <> RichEdit1.Lines.Count) and
   (CurPos > (Richedit1.Lines.count-MaxValue)) then
   RxSlider1.Value := RxSlider1.Value-RxSlider1.Increment;
 if KEY = VK_UP then
  if (CurPos <> 0) and
   (CurPos < MaxValue) then
   RxSlider1.Value := RxSlider1.Value+RxSlider1.Increment;
 ByHand := false;
end;


I guess, you've pasted the code in an unit... but have you assigned the keydown event of the richedit to the procedure above? this should work, because I tried it out myself.

Zif.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question