Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I try to place panel but it is not coming at required position.

Actually My requirement is to place the Panel_B inside the Panel_A exactly at centre position.

VB
Dim xx, yy As Integer
xx = (PANEL_A.Width - Panel_B.Width)
yy = (PANEL_A.Height - Panel_B.Height)
PanelB.Location = New System.Drawing.Point(CInt(xx / 2), CInt(yy / 2))

Please guide.
Posted
Updated 16-Apr-17 23:19pm
v2
Comments
Sandeep Mewara 11-Sep-10 4:34am    
Sentence, Text speak and Code formatting done.

1 solution

VB
Dim panelA As New Panel
Dim panelB As New Panel
panelA.BackColor = Color.White
panelB.BackColor = Color.Black
panelA.Width = 100
panelA.Height = 100
panelB.Width = 50
panelB.Height = 50
Me.Controls.Add(panelA)
panelA.Controls.Add(panelB)

panelB.Top = CInt((panelA.Width - panelB.Width) / 2)
panelB.Left = CInt((panelA.Width - panelB.Width) / 2)


This code will create 2 panels, one centred inside the other.

Run it from a form button or load event, Me.Controls represent the form.
Works fine for me.
 
Share this answer
 
v2
Comments
Jatinder Gupta 11-Sep-10 7:41am    
Thanks sir, it has solved. If your have not objection kindly share your email Id

Regards,

Jatinder gupta.
DaveAuld 11-Sep-10 8:26am    
If you need to email me (don't know why) just look for any message i have posted in the forums, and click the email button!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900