Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 603
  • Last Modified:

Richedit and trackbar

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
hellfire052497
Asked:
hellfire052497
1 Solution
 
MatveyCommented:
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
 
ZifNabCommented:
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
 
viktornetCommented:
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
 
hellfire052497Author Commented:
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
 
ZifNabCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now