Hi, I'm a beginner at VB.NET and I want to know how to change the appearance of a form when you click a button. Basically, I have a table that holds information. The user can choose between this table view or a preview. If he chooses preview, the table will disappear and the information will be displayed in labels. This is a basic idea of what I'm trying to do. The problem is I don't know if I should remove the table/label when switching screens, hide it, or reposition it. What should I do?

- To change form appearance you need to work with GDI, basically Graphics class read on msdn.com
- You've list of all controls in this.Controls, you add\remove controls..

No, I'm wondering how to do that on like a button click, not with the drag and drop stuff... like the first screen is set up. Then when the program is running you click a button and one control (the table) disappears and another control (a label) appears. I'm sorry if my question is very basic, but I don't know how to do this...

Here's the basic idea you're looking for

Private m_ViewState As Boolean

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  '
  If m_ViewState Then
    DataGridView1.Visible = True
    DataGridView1.Enabled = True
    ' Hide label(s)
    Label1.Visible = False
  Else
    DataGridView1.Visible = False
    DataGridView1.Enabled = False
    ' Show label(s)
    Label1.Visible = True
  End If
  m_ViewState = Not m_ViewState

End Sub

You may also consider using tab control with two tabs. One tab for the table view and the second tab for the label view.

Need to create\remove a control at runtime?

Here's the basic idea you're looking for

Private m_ViewState As Boolean

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  '
  If m_ViewState Then
    DataGridView1.Visible = True
    DataGridView1.Enabled = True
    ' Hide label(s)
    Label1.Visible = False
  Else
    DataGridView1.Visible = False
    DataGridView1.Enabled = False
    ' Show label(s)
    Label1.Visible = True
  End If
  m_ViewState = Not m_ViewState

End Sub

You may also consider using tab control with two tabs. One tab for the table view and the second tab for the label view.

Ok, thanks. But what if there was a project where there were more than two controls that needed to be made invisible? The form would look very crowded and hard to use. Is there another way to do this in that case? I know you could use tabs, but at times that's not the best way to go...

Collect the controls related to each other, put them in GroupBox, you can do anything with the GroupBox(Invisible, Enabled, etc...) and would reflect to the controls contained inside..

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.