Mark Kramer
Mark Kramer

Reputation: 3214

Toggling panel visibility isn't working when they are stacked

I have a form that has two views. These views are controlled by radio buttons on top of the form.

Here is the program:

http://dl.dropbox.com/u/41629841/DataCalculator/DataCalc1.PNG

Notice how the Radio button for Number Converter is selected.

Here is what it looks like when you select the Text Converter radio button:

http://dl.dropbox.com/u/41629841/DataCalculator/DataCalc2.PNG

That isn't right. I have it set to hide the panel containing the number converter and show the one containing the text converter when you click that one. It hides the number converter but doesn't show the text converter.

Here is a picture of the text converter panel:

http://dl.dropbox.com/u/41629841/DataCalculator/DataCalc4.PNG

Here is the relevant code:

Private Sub frmCalculator_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    rdoNumberConverter.Checked = True
End Sub

Private Sub rdoTextConverter_Click(sender As Object, e As System.EventArgs) Handles rdoTextConverter.Click
    pnlTextConverter.Visible = True
    pnlNumberConverter.Visible = False
End Sub

Private Sub rdoNumberConverter_Click(sender As Object, e As System.EventArgs) Handles rdoNumberConverter.Click
    pnlNumberConverter.Visible = True
    pnlTextConverter.Visible = False
End Sub

Everything seems right and I can't figure out why the text converter doesn't show up. I've determined that it has something to do with the fact that both of the panels are right on top of each other because when I move them apart, the visibility toggling works perfectly.

Here are the supporting pictures:

http://dl.dropbox.com/u/41629841/DataCalculator/DataCalc5.PNG http://dl.dropbox.com/u/41629841/DataCalculator/DataCalc6.PNG

So how do I make it work when they are on top of each other?

I tried using BringToFront() and SendToBack() to make sure the visible panel is in the front and it didn't make a difference.

Upvotes: 1

Views: 4598

Answers (2)

geodosch
geodosch

Reputation: 61

The issue is the panels becoming embedded, as pointed out by @LarsTech. This occurs if you use the GUI to move them to the same location.

If you want to overlap them at design time, create the second panel in a different location. Then in the Properties of the panel in the final location, copy the Location, and paste it into the Location property of the second panel. This will move it to the proper location in the Designer without embedding one into another. This can be repeated for as many additional panels as needed.

Upvotes: 0

LarsTech
LarsTech

Reputation: 81610

Make sure the TextConverter panel isn't "inside" the NumberConverter panel.

From the designer, move them into different places so that they do not overlap at all.

Then in code, move them into place:

textConverterPanel.Location = numConvertPanel.Location

Your visible, not visible toggling should work then.

Upvotes: 4

Related Questions