Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Vb.Net Aero ListView , make your listview look better (ctrl + source) simple tut

Ok..

since we all love the listview control in VS, but if your like me, hate the way it looks (does it not look like it fell out of win 95'?) then this VERY simple control will soon become a quick replacement.

lets start by checking out the differences in the standard listview and the "Areo listview":

[img]http://img691.imageshack.us/img691/926/715201121245pm.png[/img]

^^
on the left is the standard listview, but on the right is our new areo listview. both of them are set to simply display something in detail mode, with some garbage that is being displayed.

so, what has change?
well, if the image dont say it all, then i will tell you, ..
The appearance!

our new one (the one on the right) looks like it fits into windows vista / 7 more, and dont look 10 years old.

lets do another example:

[img]http://img24.imageshack.us/img24/9227/715201121906pm.png[/img]

this time i did it with pictures...(dont that just look better ?)

ok, thats all for the demo, and you might be thinking that this is some custom drawn listview. well, no, its not.

starting with windows vista you can now apply the windows themes (areo) to different controls found around the windows environment.
since i use a listview (alot) this is one control class that i made and have always loaded it up when i need a listview.

dude, shutup and show some code!
ok, ok

lets start.

make a new class and call it something close to what the control is. (AreoListView)
then import "System.Runtime.InteropServices"
make it "inherit" a listview

you will need to declare this api:
Code
<DllImport("uxtheme", CharSet:=CharSet.Unicode)> _
  Public Shared Function SetWindowTheme(ByVal hWnd As IntPtr, _
    ByVal textSubAppName As String, _
    ByVal textSubIdList As String) As Integer
    End Function

now, we will add an event handler for when the handle is created we can go ahead and use our api to make it look "pretty"

Code
Private Sub AreoListView_HandleCreated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.HandleCreated
  SetWindowTheme(Me.Handle, "explorer", Nothing)
    End Sub

so the api call is basically like this..
me.handle (the handle to the control to change)
"explorer" (this is just a marker that windows uses, its not that important)
nothing (this is the pram for the theme(anything other than "nothing, 0, nill" will force it back to the old way and defeat the whole point of the ctrl))

now, one issue that i always hate with listviews, are that they flicker when they are being updated.. lets solve this now..
Code
Sub New()
  Me.DoubleBuffered = True
    End Sub

ah, much better.

ok so close the class and debug your app, close it, then check the toolbox for your new control.

done!

now you can use a listview that fits with windows vista / 7 a little better than that ugly solid blue selections.

just incase anyone is wondering about XP, this will not crash on an xp box, but also, it wont do anything.

anyway, here is my whole class for the control:

Code
Imports System.Runtime.InteropServices

Public Class AreoListView

    Inherits ListView

    <DllImport("uxtheme", CharSet:=CharSet.Unicode)> _
  Public Shared Function SetWindowTheme(ByVal hWnd As IntPtr, _
    ByVal textSubAppName As String, _
    ByVal textSubIdList As String) As Integer
    End Function

    Sub New()
  Me.DoubleBuffered = True
    End Sub

    Private Sub AreoListView_HandleCreated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.HandleCreated
  SetWindowTheme(Me.Handle, "explorer", Nothing)
    End Sub
End Class

so, i hope that everyone enjoyed themselves and can use this in making your programs a little more pleasing to the eye.
thanks for the share, nathan it looks great
Nice release, haven't seen you in a long time!
Nice share m8 :D, i found this for some days ago on a site, im using it for my admin client

P.S i think this is what Leaf admin client uses ;)
Nice release. ;)

Thanks.
(Jul 15, 2011 12:14 PM)RBH Wrote:  Nice release, haven't seen you in a long time!

im still around.

(Jul 15, 2011 12:21 PM)Emilnerd Wrote:  Nice share m8 :D, i found this for some days ago on a site, im using it for my admin client

P.S i think this is what Leaf admin client uses ;)

yeah, i mean, its not like a HUGE secret or anything... but i just thought i would post it up.

P.S. ... i never checked out "leaf" so... ok.
That looks really cool.
Big thanks for sharing!
(Jul 15, 2011 01:14 PM)nathan72389 Wrote:  im still around.

yeah, i mean, its not like a HUGE secret or anything... but i just thought i would post it up.

P.S. ... i never checked out "leaf" so... ok.

Well, thanks for posting :)

I wonder why there's no property for this by microsoft as default.

Shame on them, good share anyhow.
Probably coding some useless shit.
(Jul 15, 2011 02:20 PM)ubbelol Wrote:  I wonder why there's no property for this by microsoft as default.

Shame on them, good share anyhow.

the funny thing, (and i may be off)

i think delphi 09', 10' or w/e the 2nd to latest ide (and xe) did have this as a property.

idk why M$ didnt include it, seems to me, if it dont f-up on XP and lower,m then just make it a default in the framework.
Yet again, something else awesome from nathan!
Pretty nice as always. Thanks for the share.
(Jul 15, 2011 04:29 PM)Xenon Wrote:  Pretty nice as always. Thanks for the share.

thanks man, like i said, its not a big secret, but +1 (not rep wise) for the post count.
(Jul 15, 2011 02:30 PM)nathan72389 Wrote:  the funny thing, (and i may be off)

i think delphi 09', 10' or w/e the 2nd to latest ide (and xe) did have this as a property.

idk why M$ didnt include it, seems to me, if it dont f-up on XP and lower,m then just make it a default in the framework.

Actually what do this look like on < XP? ;o
Probably coding some useless shit.
(Jul 16, 2011 02:35 AM)ubbelol Wrote:  Actually what do this look like on < XP? ;o

I believe it looks regular on XP. =)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by nathan72389Dec 4, 2021 10:27 AM 7 940 Dec 4, 2021 10:27 AM
Last Post: zatt
[Python] by f4keg0dNov 11, 2019 04:32 AM 4 460 Nov 11, 2019 04:32 AM
Last Post: f4keg0d
[.NET] by markzuckerbergJun 4, 2018 01:57 PM 17 368 Jun 4, 2018 01:57 PM
Last Post: markzuckerberg