Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Listbox with textured background

Posted on 1999-06-29
20
Medium Priority
?
401 Views
Last Modified: 2010-04-06
I need a listbox component with a texture as background. The full area of the listbox should be painted with the texture (also if the listbox have no item).
I think I have to draw the text of the listbox items transparent in OnDrawItem via SetBGMode(Canvas.Handle, Transparent).

BTW: Perhaps overwrite wm_paint or wm_erasebackground is a good starting point?
I think, flicker could be a problem.
0
Comment
Question by:bengore
[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
  • 9
  • 8
  • 3
20 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 300 total points
ID: 1385328
Use the OnCustomDraw event. In this event you can draw the background you want then allow the items to draw over the top of it...

Cheers,

Raymond.

0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1385329
Oh - this is a D4 thing...
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385330
0
Technology Partners: 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!

 

Author Comment

by:bengore
ID: 1385331
Hello Raymond,

I am not a comonent expert. Thats why I dont understand your answer. TListbox has no OnCustomDraw methode which I can override!? Can you give me a source example?
0
 

Author Comment

by:bengore
ID: 1385332
Hello Epsylon,

this component draw the backgound bitmap only in the area where listbox items are. That means: if the listbox has none (or 1,2 items) then the background image fill not the whole clientrect of the listbox.

Ben
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385333
Sorry Ben, I have been looking for components on all popular Delphi sites and that was the only freeware component I could find. I tried it myself today and I was disappointed too.
There are some shareware components available but I don't think that's what you want.

Epsylon.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1385334
bengore: Which version of Delphi are you using?

Cheers,

Raymond.
0
 

Author Comment

by:bengore
ID: 1385335
I am using Delphi 4.
I have tried to override the WMPaint methode. but I dont know if this is the right way.
I think, I am not the only one whho are interesting in such a listbox component with texture background. But I can not find any good piece of source (dejanews.com,...).

Ben
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1385336
In D4 the TListView component has an OnCustomDraw event. Simply write an event handler for it, much like you would for OnClick etc.

Cheers,

Raymond.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385337
ListBox, Raymond. ListBox!
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385338
You should really look at this site:

http://www.tmssoftware.com

The components are free for non-commercial applications.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385339
By the way: Full sources are included!
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1385340
Aaarrgghh! I hate it when the parser messes it up :-(

I think you should reject my answer as it is WRONG!

Yes, I think intercepting either wm_paint or wm_erasebkground (sp?) is the place to start.

The best approach is probably to make it work, then worry about the flicker - but you're right, flicker is likely to be a problem.

Here's something very simple to get you started.. It just draws a red rectangle on the OnPaint message. You will probably need to override DrawItem and add a property to hold the bitmap for the background to this properly...

Cheers,

Raymond.

unit ListBox2;

interface

uses
  classes, stdctrls, messages;

type
  TBGListbox = class(TListBox)
    procedure Paint(var Msg : TMessage); message WM_PAINT;
  end;

procedure Register;

implementation

uses
  graphics;

{ TBGListbox }

procedure TBGListbox.Paint(var Msg : TMessage);
begin
  canvas.brush.color := clred;
  canvas.fillrect(rect(0, 0, 100, 100));
  Inherited;
end;


procedure Register;

begin
  RegisterComponents('Ripple', [TBGListBox]);
end;

end.


0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385341
I see that TSectionListBox supports backgrounds it is not a ListBox anymore. Great component though. The items are stored into expandable sections. It's more like a TreeView.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385342
Raymond, does the flicker stop when you set the DoubleBuffered property to true?
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1385343
Hard to say Epsylon - TListBox doesn't has a doublebuffered property! (at least in D4.03 it doesn't).

Cheers,

Raymond.

0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385344
TWinControl has a DoubleBuffered property and TListBox (or TCustomListBox) does not hide it.

But I tried it with your example and it messes up completely. Next to that I think scrolling is a problem too.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1385345
epsylon: I didn't say it was any good - just that it was a starting point!

Take a look at TListBox - there is no DoubleBuffered property (which is odd since I exzpect it to be there...)

Cheers,

Raymond.

0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385346
It's not visible in the object inspector but you can access using code....
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1385347
Seems to be pretty much the same with or without doublebuffering...

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

715 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