Fraïssé
Fraïssé

Reputation: 166

VB.NET how to change appearance of a panel based on which button is pressed?

I know this question as been asked before many times. My question is similar to show one panel after button is clicked and other panel when second button is clicked in the same frame

I had a panel in designers. I want it to show a set of controls when I click on button_1 and another controls when I click on button_2. I do not want to achieve this via tab changer (because the little tab on the top which is not ideal)

How do I implement this in visual studio using VB.NET?

Upvotes: 0

Views: 2292

Answers (3)

Herbert Yeo
Herbert Yeo

Reputation: 111

You can use .BringToFront() property. In visible property, you need to set the other to false, but if you use .BringToFront property no need to set the other controls to visible false. I've assumed that the panels are overlapped.

Upvotes: 2

Jens
Jens

Reputation: 6375

You wrote that you do not want to use a Tabcontrol because you don't want the tab headers to be visible. However a Tabcontrol is pretty ideal for this kind of application. You can hide the tab headers by using this derived control instead.

Public Class TablessControl
    Inherits System.Windows.Forms.TabControl
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        ' Hide tabs by trapping the TCM_ADJUSTRECT message
        If (m.Msg = Convert.ToInt32("0x1328", 16) And Not DesignMode) Then
            m.Result = CType(1, IntPtr)
        Else
            MyBase.WndProc(m)
        End If
    End Sub
End Class

Disclaimer: This code is from another answer on SO from some time ago and not my code. It works great however and I will try to find the corresponding answer. Source: Hide Tab Header on C# TabControl

Put the code in your project and compile once. You will then have the control in your toolbox and can use it exactly like the normal tab control. At runtime the header buttons are hidden automatically.

Upvotes: 1

tezzo
tezzo

Reputation: 11105

You can use two Panels (one for each set of controls) and modify their .Visible property on Button click.

Upvotes: 1

Related Questions