Solved

Richedit and trackbar

Posted on 1998-08-19
5
561 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
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 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