tags:

views:

180

answers:

3

What's the equivalence of vb6.0 frame control in .Net? panel or groupbox?

I recall that using frame in vb6.0 and disable it (frame1.Enabled = False) did not change its fore color of controls within it .

+1  A: 

Have you looked at the System.Windows.Forms.GroupBox?

This page could be of use to you. It explains the transition from the VB6 Frame control to the newer .NET controls.

CesarGon
yeah, but as I said above, when we disable a groupbox in .Net, all fore color controls within it change to grey. This is not exactly when we did the same in vb6.0
odiseh
Just updated my answer with a useful link. :-)
CesarGon
Thank you, but it seems that both of them are not exactly frame. Because when I disable them all controls (labels, textboxes,...) within them change their fore colors to grey.
odiseh
Maybe a System.Windows.Forms.Panel control would be better suited then.
CesarGon
System.Windows.Forms.Panel control also sets all its children to grey when it is disabled. Also that link about transition from VB6 `Frame` to .NET controls unfortunately doesn't mention this difference in behaviour.
MarkJ
A: 

I think it should be Panel

Nasser Hadjloo
+1  A: 

It is considered a crime against usability to not make a control appear disabled when it is disabled. Nothing quite like the sight of user banging away on the mouse button to try to get the program to do what she thinks is possible.

Windows Forms doesn't support it, but you can fake it. You could display an image of the enabled controls, overlapping the disabled ones. Add a new class to your project and paste the code shown below. Compile. Drop the control from the top of the toolbox onto your form and add controls to it. Try it out by having a button toggle the Enabled property.

Public Class MyPanel
  Inherits Panel

  Private mFakeIt As PictureBox

  Public Shadows Property Enabled() As Boolean
    Get
      Return MyBase.Enabled
    End Get
    Set(ByVal value As Boolean)
      If value Then
        If mFakeIt IsNot Nothing Then mFakeIt.Dispose()
        mFakeIt = Nothing
      Else
        mFakeIt = new PictureBox()
        mFakeIt.Size = Size
        mFakeIt.Location = Location
        Dim bmp = new Bitmap(Width, Height)
        Me.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height))
        mFakeIt.Image = bmp
        Me.Parent.Controls.Add(mFakeIt)
        Me.Parent.Controls.SetChildIndex(mFakeIt, 0)
      End If
      MyBase.Enabled = value
    End Set
  End Property
End Class

Please don't use this.

Hans Passant
+1 Ingenious! Might need to do a little more work if the form was resizable...
MarkJ