question

Hobbyistprogrammer-7674 avatar image
0 Votes"
Hobbyistprogrammer-7674 asked JackJJun-MSFT edited

Position a panel inside Groupbox

Hallo,

I have group box and inside this groupbox i have tow panels called pnl1, pnl2 . on button click i want to hide pnl1 and want to position pnl2 in the position of pnl1 but when i do it it positions relative to the form not relative or inside Groupbox. Anyidea how to position it right?

i also tried pnl2.location =pnl1.location

still it is not working

thanks

dotnet-visual-basic
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I assume this is for WPF. It helps to add a tag for the UI when relevant.

0 Votes 0 ·

Hallo,

I already have a tab control ,in that tab control i have various group boxes and one group box has 1 panel and i want to position it . is it possible to reposition this panel inside groupbox?

Thanks

0 Votes 0 ·

I think the last answer is good. If we drag the panel inside the Groupbox in the designer, then we could use the code panel1.Location to set the position relative to the Groupbox directly.

0 Votes 0 ·
SimpleSamples avatar image
0 Votes"
SimpleSamples answered

Perhaps you can use a TabControl instead. See Tab Control In WPF for an article about it.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered

Another idea is to use a TabLayoutPanel. Panels are colored to see things actual work.

 Public Class Form1
     Private Sub SwapOutButton_Click(sender As Object, e As EventArgs) Handles SwapoutButton.Click
    
         Dim p1 = TableLayoutPanel1.Controls.OfType(Of Panel).
                 FirstOrDefault(Function(control) control.Name = "Panel1")
    
         If p1 IsNot Nothing Then
             TableLayoutPanel1.Controls.Remove(p1)
             TableLayoutPanel1.SetColumn(Panel2,0)
             Panel2.Dock = DockStyle.Fill
         End If
    
     End Sub
 End Class

112781-swapout.png



swapout.png (69.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DewayneBasnett-7583 avatar image
0 Votes"
DewayneBasnett-7583 answered

A before picture

113006-before.jpg

The after picture

113043-after.jpg

The code

     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
         Panel1.Visible = False
         Panel2.Location = Panel1.Location
     End Sub




before.jpg (17.2 KiB)
after.jpg (15.3 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.