How to change ListView background image layout?

Go To StackoverFlow.com

0

I've tried to find a way to change the layout of the background image on the ListView control. I've searched around but haven't got any straight answer.

I can see that there is a ListView property BackgroundImageLayout which is supposed to do the job. But when i change it nothing really happens beside that the BackgroundImageLayoutChanged event is triggered.

How it is possible to change the BackgroundImageLayout on the ListView control? Is there any possible workaround to achive my goal?

PS.: I know about 3rd party controls that 'fix' this problem, but I'm looking for a solution that would do the task without any additional components.

2012-04-04 18:51
by Tom


2

ListView is a native Windows control. Yes, it does support a background image, the LVM_SETBKIMAGE message takes care of it. It however doesn't support the boilerplate Winforms BackgroundImage support, notable lacking is BackgroundImageLayout, the property that Winforms implements for the Control class and implements when the ControlStyles.UserPaint is turned on. It is not for native Windows controls, they paint themselves.

The guy that wrote the Winforms wrapper class for ListView did the next best thing, he added a new property to the ListView class called BackgroundImageTile. A layout option that the native Windows control does implement. Which leaves you with just the two layout options that the native control supports. Tile or don't tile.

That same guy did some pretty heroic things to make the Winforms wrapper class behave reasonably. The code is filled with hacks to work around the native control's quirks. Awesome work. His life would have been a lot easier if the Windows team guy would have the luxury to make the Winforms guy's life easier. But it doesn't work that way, ListView has been around a lot longer than Winforms. And wasn't designed that well from the getgo, Microsoft had pretty significant growing pains around that time.

Fast forward and change the rules so you don't depend on legacy code: WPF, Silverlight, WinRT.

2012-04-04 22:30
by Hans Passant


1

According to the MSDN, 'ListView.BackgroundImageLayout Property':

"The API supports the .NET Framework infrastructure and is not intended to be used directly from your code."

and

This property has no effect on the layout of the background image of the ListView control, therefore it is not shown in the designer or by IntelliSense.

Use the BackgroundImage property to set the background image. See msdn for more info:

That is unless you have something fancy you are trying to do with it?

EDIT: As per a previous thread HERE: the short answer is that you can't. =(

If you desparately want it, try creating a blank image that is the dimensions of your ListView. Add to this image YOUR image and add at it a position that is in the middle. There may be something similar in nature to this in under Bitmaps or Images.

2012-04-04 18:59
by ImGreg
I just want to "center" the background image of the ListView control. Is there any possibility oto achive that - Tom 2012-04-04 19:30
No luck with "ListView.BackgroundImageLayout = ImageLayout.Center;" I assume - ImGreg 2012-04-04 19:33
Unfortunetly not : - Tom 2012-04-04 21:24
Bad news Tom, see my edit. = - ImGreg 2012-04-04 21:37
Ads