-1

I create a UserControl with three Panels I add this UserControl in my main Form but i have then the problem that i can't choose which panel to appear in my main form. Exccactly i have this code below to make visible my Panel1

Public Function Pan1()

    Panel3_Paint.Visible = False
    Panel2_Paint.Visible = False
    Panel1_Paint.Visible = True




    Return 0
End Function

So after i click in a stripMenu i tried to appear the first panel with this function in my Form but finally in my main Form appears the third Panel.

i use my function in this way

    Private Sub ClassAToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ClassAToolStripMenuItem.Click

              UserControl11.Visible = True
              Call Pan1()
    End Sub`

I try when i click a specific button in menu to show the appropriate panel That's why i try to do it with this function but i have the problem that in my form appears only the third panel.

My UserControl Code

Public Class UserControl1
Public Sub Panel3_Paint(sender As Object, e As PaintEventArgs) Handles Panel3.Paint

End Sub

Public Sub Panel2_Paint(sender As Object, e As PaintEventArgs) Handles Panel2.Paint

End Sub

Public Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint

End Sub

End Class

I define also my UserControl and Panels in my Form.vb this way

Public UserControl1 As New UserControl
Public Panel1_Paint As New Panel
Public Panel2_Paint As New Panel
Public Panel3_Paint As New Panel
  • Could you precise how you create your UserControl ? – Maxime Porté Aug 01 '15 at 19:48
  • I post above my code of UserControl and also post my code how define my Usercontrol in Form.vb – Nikos Koutantos Aug 01 '15 at 20:35
  • I'm thinking maybe each definition erase the last one. Try declare your panel from Panel3_paint to Panel1_paint instead of Panel1 to Panel3. If the Panel1 open after that, we will have a clue about the problem – Maxime Porté Aug 01 '15 at 21:40
  • It looks like you have public visibility for your panels. I would have them as private, create property's on your UserControl and use them to change the visibility of your panels. – Mark Hall Aug 02 '15 at 00:07
  • Even if i turn Public panels into Private i have the same problem, when i turn UserControl into Visible appear only my third panel – Nikos Koutantos Aug 02 '15 at 16:07
  • @MaximePorté even if i declare to Panel1 to Panel3 i have the same problem .I understand that i have access from my Form only in the UserControl and not in the panels. How can i take acess in the panels properties from my Form? – Nikos Koutantos Aug 02 '15 at 17:25

2 Answers2

0

Without seeing more of your code, I am assuming there may be an issue with the call of the function.

Make sure the function is called in an event. For example, if you add a CommandButton to the Form, you can add the following code to run in case of a click on the button:

Private Sub CommandButton1_Click()

Call Pan1

End Sub

I hope this helps.

Kristo_R
  • 167
  • 1
  • 13
0

So my problem is solved. I can't access in Panel Properties, that's why i create a Public Sub in my UserControl.vb and use it in my Form. This code is written in my UserControl.vb

 Public Sub Pan1()
 Panel3_Paint.Visible = False
Panel2_Paint.Visible = False
Panel1_Paint.Visible = True



End Function

And then i call my Sub in my Form in this way

Private Sub ClassAToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ClassAToolStripMenuItem.Click


    UserControl11.Visible = True
    UserControl11.Pan1()


End Sub