Retreiving Parent container size

  • Thread starter Thread starter Francois Soucy
  • Start date Start date
F

Francois Soucy

Hi all!
I've created a personal control. This control is mainly a panel with some
other stuff in. I want to know if it's possible to know the size of the
container of this control? I mean that my control can be put on a form or a
panel. I want to know the size of the container without knowing what will be
exactly. It' possible?

Thank a lot
 
Hi Francois,

Guess what! Every Control has a Container property. Hurray!!

But it's useless for what you want. :-(

Yet they have a Parent property, too, and this is <just> what you want.
:-)

And as Parent will be a Control, it'll have a Size and a ClientSize.

Ha! Now we're talking!! ;-))

Have you looked at the Help page for the Control class? There are <loads>
of properties to play with.

Regards,
Fergus
 
Maybe it's to late in the nite and I can't see anything... But I'could not
find any parent property! I show you what i've done:

Class TrapBox
Public Class IconBox
Inherits Panel
Private Marge As Integer = 10 ' Margin
Private Largeur As Integer = 10

Private Position As Integer
Private icon As New TrapBox.Icon(Image)
Private Label As New TrapBox.Label(Texte)

Sub New(ByVal Texte As String, ByVal Image As Image)

'TODO Enlever le back Color a la fin...
Me.BackColor = System.Drawing.Color.Aqua 'Only for debuging
purpose... Remove at end
Me.Controls.AddRange(New System.Windows.Forms.Control() {icon,
Label})

'Location for icon box
Me.Position = (Me.Size.Width - Me.icon.Size.Width) / 2
If Me.Position < 0 Then Me.Position = 0
Me.icon.Location = New Drawing.Point(Me.Position, Me.Marge)

' Location for text label
Me.Position = (Me.Size.Width - Me.Label.Size.Width) / 2
If Me.Position < 0 Then Me.Position = 0
Label.Location = New System.Drawing.Point(Me.Position, Me.Marge
+ Me.icon.Size.Height + (Me.Marge / 2))

'######################################
'### THERE No parent property for me.(...) ###
Me.Size = New System.Drawing.Size( '???' , Me.Marge +
Me.icon.Size.Height + Me.Label.Size.Height + Me.Marge)
End Sub
......
End Class
End Class

#### End snip ###

I know that how my control is created may cause my probleme. i call it this
way in my form.

Dim Toto As New System.Drawing.Bitmap("test.ico")
Dim Pan As New TrapBox.IconBox("Hi this is a test?", Toto)

Me.Controls.AddRange(New System.Windows.Forms.Control() {Pan})
Pan.Location = New Drawing.Point(0, 0)
' I don't want to size (width) the control there. He MUST be the same size
(width) than the parent...
 
Hi Francois,

It's not too late - your VS options have got the Parent property switched
off in the Intellisense. Type it in regardless and it will work. In fact
Intellisense will kick in as soon as you type the '.' after Parent.

In Tools/Options there's a Text Editor section click on that to get the
subsections and then click on Basic. You'll see an option Hide Advanced
Members. For you there will be a tick. This means that various methods that
you might want to use will be hidden by the Intellisense. They will still be
available if you type them but they won't show automatically. It's a question
of whether you want to see the whole list and have to do more scrolling, or do
you want to have to remember which methods are 'advanced'.

As I suggested, have a look at the Help for the Control Class - if it
gives a method there but you can't see it with Intellisense, believe the Help
and try it anyway.

Regards,
Fergus
 
Hi Francois,

Did Fergus's suggestion works for you?
If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
No no! sorry! I was to busy with Halloween and my kid! This solution worked
fine for me! I was able to see parent container size and also it give me a
way to find a anwser of how to trap some parent event in my control :)
Thank!

Francois
 
Back
Top