Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Richedit and trackbar

Posted on 1998-08-19
5
Medium Priority
?
596 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 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

636 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