Solved

Owner Draw Scroll Bar

Posted on 2000-02-23
12
1,656 Views
Last Modified: 2013-11-23
Hi,

need to implement a scroll bar, which have another look than a Windows one (with other bitmaps as buttons and background). The one in Delphi has no Canvas. Any ideas?

Thanks.
0
Comment
Question by:shtern
[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
  • 8
  • 4
12 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 2551517

http://torry.rimini.com/vcl/sizers/ramscrbr.zip

{A nice enhanced  ScrollBar component. Support for                                          Delphi 3 (D5 compatible) has now been added. Knows                                              several drawing styles (Standard -                                               just like windows' scrollbar, Gradient -                                               Draws a nice gradient of two colors,                                               Rainbow - Draws a HSB pallette).                                               Buttons can be bitmaps or original                                               windows' arrows. Some additional                                               features have been introduced.                                               Supports hint display. Very nice if you                                               want to make your apps look a bit                                              nicer.}

I guess there are more around.

Or you could create your own scrollbar component.
0
 

Author Comment

by:shtern
ID: 2551621
I've seen ramscrbr, and the problem is it can not draw bitmap on its background, only gradient/HSB. Or does it?
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 2551724
argh, looks like, I thought you only were looking for bitmaps as buttons!

Zif.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:ZifNab
ID: 2551730
mmm, but with the source this could be implemented not?
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 2551746
look what I found on the net :-)

How To Create a Scroll Box with Bitmap Background

It's simple to create it.

1. Create a new object inherits from TScrollBox
2. We need two variables,
  TBitmap variable to save bitmap
  TCanvas variable to draw bitmap on scrollbox
3. Define a BackBitmap property on published area so the property
  can change from Object Inspector.
4. Inherits the WM_PAINT message handler
5. Define a Painting procedure to draw bitmap.
6. Override PaintWindow procedure for paint scrollbox.

the object type is

type
 TMyScrollBox = Class(TScrollBox) (* an object inherited from TScrollbox *)
 private
   FNHBitmap: TBitmap; (* TBitmap variable to save bitmap *)
   FNHCanvas: TCanvas; (* TCanvas variable to draw bitmap *)
   procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
     (* Override the WM_PAINT message handler *)
   procedure SetBitmap(Value: TBitmap);
     (* procedure to set bitmap. Used by BackBitmap property *)
 protected
   procedure Painting; (* procedure to draw bitmap *)
   procedure PaintWindow(DC: HDC); override; (* Procedure to paint window *)
 published
   property BackBitmap: TBitmap read FNHBitmap write SetBitmap;
     (* BackBitmap Property *)
 public
   constructor Create(Owner: TComponent); override;
     (* Constructor to create object *)
   destructor Destroy; override;
     (* Destructor to destroy object *)
 end;

6. Constructor to create object.
  At this procedure, create the TCanvas variable as TControlCanvas.
  The TControlCanvas is an object inherited from TCanvas that can be used to
  draw on Control Surface.
  Set the property Control on this variable to Self.

     constructor TMyScrollBox.Create(Owner: TComponent);
     begin
       inherited Create(Owner);
       FNHBitmap := TBitmap.Create;
       FNHCanvas := TControlCanvas.Create; (* Create as a TControl Canvas *)
       TControlCanvas(FNHCanvas).Control := Self;
       (* Set the Control property so you can draw on the scrollbox surface. *)
     end;

7. Procedure Painting
  This procedure is used to draw on the scrollbox surface.
  You must use the vertical scrollbar position and horizontal scrollbar position
  to draw the bitmap, and repeat drawing for tiling bitmap.

9. Message trapping
  When the scrollbox get WM_PAINT message, then the message will be handled by
  WMPaint procedure. The WMPaint procedure calls PaintHandler, so the control's
  background will be painted by calling PaintWindow and any child controls too
  by calling PaintControls.
  The Painting procedure is called by PaintWindow.

You can copy this source, save as NScroll.pas, and install to your component palette.


(* Source Code *)

unit NScroll;

interface
uses
 SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
 Forms;

type
 TMyScrollBox = Class(TScrollBox)
 private
   FNHBitmap: TBitmap;
   FNHCanvas: TCanvas;
   procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
   procedure SetBitmap(Value: TBitmap);
 protected
   procedure Painting;
   procedure PaintWindow(DC: HDC); override;
 published
   property BackBitmap: TBitmap read FNHBitmap write SetBitmap;
 public
   constructor Create(Owner: TComponent); override;
   destructor Destroy; override;
 end;

procedure Register;

implementation

constructor TMyScrollBox.Create(Owner: TComponent);
begin
 inherited Create(Owner);
 FNHBitmap := TBitmap.Create;
 FNHCanvas := TControlCanvas.Create;
 TControlCanvas(FNHCanvas).Control := Self;
end;

destructor TMyScrollBox.Destroy;
begin
 FNHBitmap.Destroy;
 FNHCanvas.Destroy;
 inherited Destroy;
end;

procedure TMyScrollBox.SetBitmap(Value : TBitMap);
begin
 FNHBitmap.Assign(Value);
 invalidate;
end;

procedure TMyScrollBox.WMPaint(var Message: TWMPaint);
begin
 PaintHandler(Message);
end;

procedure TMyScrollBox.PaintWindow(DC: HDC);
begin
 FNHCanvas.Handle := DC;
 try
   Painting;
 finally
   FNHCanvas.Handle := 0;
 end;
end;

procedure TMyScrollBox.Painting;
var FDrawHeight, FDrawWidth: Integer;
 Row, Column, xl, xt, xw, xh: Integer;
 xdl, xdt: Integer;
 xRect: TRect;
 i: integer;
 xhdl: Word;
begin
 if (FNHBitmap.width <> 0) and (FNHBitmap.Height <> 0) then begin
   xRect := ClientRect;
   FDrawHeight := xRect.Bottom - xRect.Top;
   FDrawWidth := xRect.Right - xRect.Left;
   xdl := (HorzScrollBar.Position mod FNHBitmap.Width);
   xdt := (VertScrollBar.Position mod FNHBitmap.Height);
   for Row := 0 to (FDrawHeight div FNHBitmap.Height)+1 do begin
     for Column := 0 to (FDrawWidth div FNHBitmap.Width)+1 do begin
       xl := Column*FNHBitmap.Width+xRect.Left-xdl;
       xt := Row*FNHBitmap.Height+xRect.Top-xdt;
       xw := FNHBitmap.Width;
       if (FDrawWidth - xl+xRect.Left) < xw then xw := (FDrawWidth - xl+xRect.Top);
       xh := FNHBitmap.Height;
       if (FDrawHeight - xt+xRect.Top) < xh then xh := (FDrawHeight - xt+xRect.Top);
       FNHCanvas.CopyRect(Rect(xl, xt, xl+xw, xt+xh), FNHBitmap.Canvas, Rect(0, 0, xw, xh));
     end;
   end;
 end;
end;

{}
procedure Register;
begin
 RegisterComponents('KPC', [TMyScrollBox]);
end;


end.  

 
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 2551752
seems not that difficult at all!

Is this what you want?

Zif.
0
 

Author Comment

by:shtern
ID: 2551957
sorry, ZifNab, maybe, I was inexact. What I need is the scroll bar itself to have on its "background" a bitmap, so there, where ramscrbr has a gradient. The scroll bar must be absolute "not-Windows", I already have an picture how it should look: buttons, slider and the bar itself.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 2552010
arrgh, no you're correct. I forgot that the question was about the Scrollbar and not TScrollbox. That happens when you do too much things at the same time.

Mmm, since ramscrbr can show a gradient, it shouldn't be that difficult to change the src-code of that component to allow a bitmap.

Zif.
0
 

Author Comment

by:shtern
ID: 2552131
Yes, but there is no source code. Sure, if it will be really needed, I'll write it itself, but I don't like the idea: time is always the problem.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 2552574
looks you can buy the source code... but when it's for a commercial application... then the price is rather high...
0
 

Author Comment

by:shtern
ID: 2553791
OK, ZifNab. Thanx for all, seems I have to write it myself. However, I think I should give you the points for this code for scroll box because I can use it too. Provide it as answer, and you become the points.
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 100 total points
ID: 2555226
Eugh, sorry that I couldn't help you more and thanks for the points :-)

To answer :

There exist a scrollbar component which does this partially :

 - http://torry.rimini.com/vcl/sizers/ramscrbr.zip 

The question is answered because shtern could also use the code for the scroll-box with a bitmap : see comments above.

Regards, Zif.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month6 days, 21 hours left to enroll

622 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