Doggie Posted March 10, 2003 Share Posted March 10, 2003 As programmers know, you cannot change the Treeview Background Color manually in the options but i've found a good way of doing it in RuntimeFirst of all create a new project and add a treeview control. To do this you need to goto the menu Project > Components and look for Microsoft Windows Common Controls, select it and adds more controls to your toolbox.Once thats done we can add some code For the general declarations, put the followingOption Explicit 'Needed to make sure declared strings etc workPrivate Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long 'Used to set the following tweakPrivate Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long 'Get treeview handlePrivate Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long 'Set handlePrivate Const GWL_STYLE = -16& 'The current style of treeviewPrivate Const TVM_SETBKCOLOR = 4381& 'Set Bground ColorPrivate Const TVM_GETBKCOLOR = 4383& "Get Bground ColorPrivate Const TVS_HASLINES = 2& 'Misc stuff neededDim frmlastForm As Form 'The form usingNow the Form on Load EventPrivate Sub Form_Load() Dim nodX As Node 'Creates nodX as the default Node Set nodX = TreeView1.Nodes.Add(, , "R", "Default Plugins") 'Cut all this out of a prog i doing currently :P Set nodX = TreeView1.Nodes.Add("R", tvwChild, "DP1", "Bios") Set nodX = TreeView1.Nodes.Add("R", tvwChild, "DP2", "Video") Set nodX = TreeView1.Nodes.Add("R", tvwChild, "DP3", "Sound") Set nodX = TreeView1.Nodes.Add("R", tvwChild, "DP4", "CD/DVD") Set nodX = TreeView1.Nodes.Add("R", tvwChild, "DP5", "Controllers") nodX.EnsureVisible ' Make sure it visible TreeView1.Style = tvwTreelinesText ' Style 4. TreeView1.BorderStyle = vbFixedSingle ChangeTreeviewColor 'This will be eventually the event to change the color :)End SubNow we have to make a lil event called ChangeTreeViewColorPrivate Sub ChangeTreeviewColor() Dim lngStyle As Long 'Explained further on Call SendMessage(TreeView1.hWnd, TVM_SETBKCOLOR, 0, ByVal RGB(216, 228, 248)) 'Sends a message setting the color defined in the RGB(x,x,x) color value lngStyle = GetWindowLong(TreeView1.hWnd, GWL_STYLE) 'lngStyle will have the init handle of treeview control Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle - TVS_HASLINES) 'Sets handle Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle) 'Sets handleEnd SubTo make sure it works, call the ChangeTreeviewColor event during the FormLoad event which has already been done Questions, Abuse etc welcome Link to comment Share on other sites More sharing options...
daniel Posted March 17, 2003 Share Posted March 17, 2003 I came across this a while ago too, I didnt know you couldnt change the bg color from the control itself untill i saw it, soo.. any idea on why you cant do it from the control?(its me btw, yeah, me) Link to comment Share on other sites More sharing options...
Doggie Posted March 17, 2003 Author Share Posted March 17, 2003 yep.. gz from msnfanatics .. welcome dude Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now