Host controls like a groupbox or panel

  • Thread starter Thread starter Mike Stephens
  • Start date Start date
Hi Mike,

Start a new Project. Select Windows Control Library. This will start you
on creating a UserControl.

Don't ask why they have two major names for the same thing! ;-)

Regards,
Fergus
 
Sorry I don't think I made myself clear. I would like to be able to host
controls similar to the group box and panel. I have written my own custom
drawn panel / group box control, its design and function is almost complete.
But I don't know how to get it to host other controls.

Eg... Once I have compiled the control and I am using it in an application,
I would like to be able to add controls to it, similar to the function of
the group box and panel.

I hope this is more explanatory than my previous post.
 
Hi Mike,

Getting clearer :-)

A couple of questions:
1 What does your class inherit from?
2 What happens when you drag a Button, say, onto your MikePanel?

If you can't answer 2) because you haven't got that far, you'll need
to add MikePanel to the ToolBox (right-click menu). Then drag it onto a Form
and drag some more stuff onto it.

I guess I'm still wondering - is this a question of something missing from
your knowledge, or is something going wrong?

Regards,
Fergus
 
1. My class inherits from the UserControl
2. A button, or any other object, is placed ON/OVER my control, not IN it.

If a drag a panel from the tool bar onto a form, and then drag a button onto
that panel the button is placed IN the control. This is the functionality I
am trying to achieve with my control.
 
Hi Mike,

Ha! Now we're right together on it!! :-)

I guess what nobody told you (and I only stumbled across it by accident a
while back, and can't find the MSDN topic again), is that you don't have to
inherit from UserControl when creating your own components. You can extend any
of the Controls or their base classes (sort of).

I took a UserControl that I've already been working with and replaced
Inherits System.Windows.Forms.UserControl
with
Inherits System.Windows.Forms.Panel

I then had to remove/amend a bit of the stuff that I was doing that was
based on it being a UC and make it aware that it had become a Panel.

I also found that it promptly refused to show itself in Design mode (for
itself) but the one that I had put on a Form acted just like any other Panel -
except that it was <mine>! :-))

As for me, so for you - it's now just a question of choosing what you'd
like to inherit from. (I hope).

Regards,
Fergus
 
I have finally managed to achieve it.

The code I was looking for is this part:
<Designer("System.Windows.Forms.Design.ParentControlDesigner,System.Design",
GetType(System.ComponentModel.Design.IDesigner))>





Imports System.ComponentModel

<Designer("System.Windows.Forms.Design.ParentControlDesigner,System.Design",
GetType(System.ComponentModel.Design.IDesigner))> Public Class ctrlTemp
Inherits System.Windows.Forms.UserControl

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'UserControl overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'ctrlTemp
'
Me.BackColor = System.Drawing.SystemColors.ControlLightLight
Me.Name = "ctrlTemp"

End Sub

#End Region

End Class
 
Back
Top