Solved

Richedit and trackbar

Posted on 1998-08-19
5
535 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now