Hi,

Let's say I have a form full of objects and want to make all of them (or half of them, whatever) invisible. Is there a short way to do that without a need of setting visible to false individually to each object?

If you are talking about design time... then,... Drag mouse over all the controls you want to make visible = false. OR, you could put these controls in a frame, picture box, or other container control.

If at runtime..., then,... Same advice. Put the controls in a picture box and set its visiblity = false.

But then there is also this way...

Dim C As Control
For Each C In Me.Controls
  C.Visible = False
Next C

Good Luck

like this

form1.visible = false
image1.visible = false
command1.visible = false

If you are talking about design time... then,... Drag mouse over all the controls you want to make visible = false. OR, you could put these controls in a frame, picture box, or other container control.

If at runtime..., then,... Same advice. Put the controls in a picture box and set its visiblity = false.

But then there is also this way...

Dim C As Control
For Each C In Me.Controls
  C.Visible = False
Next C

Good Luck

I was talking about runtime, sorry didn't make that clear before.
That code you wrote works like a charm, and it would be the best solution for me, except one problem.. I've got quite a lot objects in my form and some of them doesn't have "visible" property, like Timer for instance. And I also want to leave couple of objects visible, but I guess I can't make that happen this way?

I'm sorry, spoke too quickly.. I added "on error resume next" in that cycle, and everything works fine. As concerns those other few objects which I want to leave visible..well, I can put some lines after "For...Next" in the code to set their visibility back to "true". Or maybe there is a way to exclude, let's say, a frame with all it's objects?

Yes it is possible by testing the C.Container.Name = "Frame1" or ...

Dim C As Control

For Each C In Me.Controls
  If C.Container.Name <> "Frame1" And C.Name <> "Frame1" Then
    C.Visible = False
  End If
Next C

As for a timer control...
If C.Name <> "Timer1" Then

But then again, you could add the timer to the frame and then not need to check to see if c.name = "timer1" within the For Each loop.

Good Luck

That's just perfect, exactly what I was looking for. Thank you once again!

Oh, noticed one thing - this code also hides the whole menu line at the top, how do I prevent that?

Figured it out already, problem solved, don't bother :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.