Refresh of control (color)

  • Thread starter Thread starter Morten Snedker
  • Start date Start date
M

Morten Snedker

Me.tvKunder.ForeColor = Color.FromArgb(l)
changes the color of the Treeview control 'tvKunder' immidiately.

Using a loop:
For Each c In Me.Controls
If (TypeOf c Is ListBox) Or (TypeOf c Is TreeView) Then
c.BackColor = Color.FromArgb(l)
c.Refresh()
End If
Next


...won't change the color before restart of application?

I tried refreshing the control in the For-Next and the entire form
outside the For-Next. Didn't help either.


Regards /Snedker
 
Morten said:
Me.tvKunder.ForeColor = Color.FromArgb(l)
changes the color of the Treeview control 'tvKunder' immidiately.

Using a loop:
For Each c In Me.Controls
If (TypeOf c Is ListBox) Or (TypeOf c Is TreeView) Then
c.BackColor = Color.FromArgb(l)
c.Refresh()
End If
Next


..won't change the color before restart of application?

I tried refreshing the control in the For-Next and the entire form
outside the For-Next. Didn't help either.

Your example code isn't actually setting the BackColor of any TreeView
- is your treeview on a panel maybe? When I explicitly set a treeview's
BackColor I see immediate results (and in fact an exception is thrown
if you try to give a treeview a transparent BackColor).

Remember that unlike the VB6 Controls collection, for a VB.NET Form,
Controls only includes the 'top-level' controls (ie not stuff *in a
container control* on the form).
 
On 17 Jun 2005 06:13:34 -0700, "Larry Lard" <[email protected]>
wrote:


That may be it. The treeview actually is on a panel. Should I then
reference the treeview through the panel?
 
Yes, if you know in advance that's where it is then you can find it by
looping through Me.MyPanel.Controls.

In general if you want to iterate over all controls on a form , you
need a recursive solution like this:

'to call do this from somewhere in the form:
IterateControls(Me.Controls)

'this is the recursive proc
Sub IterateControls(cs As ControlCollection)
Dim cIter As Control
For Each cIter In cs
ProcessControl cIter
IterateControls cIter.Controls 'recurse down the hirerachy
Next
End Sub

'this is the processing routine that does whatever to a single control
Sub ProcessControl(c As Control)
'for example:
If TypeOf c Is Treeview Then
c.BackColor = Color.Red
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top