We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Richedit and trackbar

Medium Priority
Last Modified: 2013-11-22

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.
Watch Question

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.
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
This is in the OnChange of the RxSlider....

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

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);
    How_Much_To_Scroll : Integer;
{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);

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

That's for vertical scrolling////

Viktor Ivanov


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.


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);
 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;

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.

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.