hqdev
asked on
Child controls display order in a composite control
Hi experts,
I'm builduig a custom control. This control will be a header consisting of images and button collection.
So far it's working great, except that my buttons are created under the graphics and I don't know how to display them in front.
I've tried using the controls property BringToFront but it gives me strange behavior and doesn't move the display order.
I've attach the code.
In the designer I have to picture box and I want the buttons to appear in front of them.
Thanks for any help
I'm builduig a custom control. This control will be a header consisting of images and button collection.
So far it's working great, except that my buttons are created under the graphics and I don't know how to display them in front.
I've tried using the controls property BringToFront but it gives me strange behavior and doesn't move the display order.
I've attach the code.
In the designer I have to picture box and I want the buttons to appear in front of them.
Thanks for any help
Imports System.ComponentModel
Imports System.Collections
Imports System.Configuration
Public Class ctlHeader
'Collection pour les boutons
Private _HDItems As New ITCollection
<Description(""), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public ReadOnly Property HDItems() As ITCollection
Get
Return _HDItems
End Get
End Property
Private Sub ctl_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim intBt As Integer = 0
For Each hd As HDItem In _HDItems
Dim bt As New Button
bt.Text = hd.Text
bt.Name = "bt_" & intBt
bt.Width = 100
bt.Top = 50
bt.Left = 10 + (intBt * 110)
Me.Controls.Add(bt)
intBt = intBt + 1
Next
End Sub
End Class
<DesignTimeVisible(False), ToolboxItem(False)> Public Class HDMenu
'Inherits Infragistics.WebUI.UltraWebNavigator.Item
Public Enum mnuType
TopMenu
SubMenu
End Enum
Dim _fullpath As String
Dim _leveltype As String
Public Overridable Property Fullpath() As String
Get
Return _fullpath
End Get
Set(ByVal Value As String)
_fullpath = Value
End Set
End Property
End Class
'Définition des propriétés des items
<DesignTimeVisible(False), ToolboxItem(False)> Public Class HDItem
Inherits Control
Public Enum enuType
HeaderButton
AppButton
End Enum
Dim _key As String
Dim _image As String
Dim _imageHover As String
Dim _disabled As Boolean
Dim _main As Boolean
Dim _fullpath As String
Dim _MenuName As String
Dim _Link As String
Dim _ID As String
Dim _ittype As enuType
Dim _ToolTip As String
Dim _Name As String
Dim _sep As Boolean
Dim _btns As String
Dim _postback As Boolean
<Category("Item"), Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> Public Property ID() As String
Get
Return _ID
End Get
Set(ByVal Value As String)
_ID = Value
End Set
End Property
''' <summary>
''' ...
''' </summary>
<Category("Item")> Public Property Key() As String
Get
Return _key
End Get
Set(ByVal Value As String)
_key = Value
End Set
End Property
''' <summary>
''' ...
''' </summary>
<Category("Button")> Public Overridable Property Image() As String
Get
Return _image
End Get
Set(ByVal Value As String)
_image = Value
End Set
End Property
''' <summary>
''' ...
''' </summary>
<Category("Button")> Public Overridable Property ImageHover() As String
Get
Return _imageHover
End Get
Set(ByVal Value As String)
_imageHover = Value
End Set
End Property
''' <summary>
''' ...
''' </summary>
<Category("Item")> Public Property Disabled() As Boolean
Get
Return _disabled
End Get
Set(ByVal Value As Boolean)
_disabled = Value
End Set
End Property
''' <summary>
''' ...
''' </summary>
<Category("Item"), Browsable(False)> Public Overridable Property FullPath() As String
Get
Return _fullpath
End Get
Set(ByVal Value As String)
_fullpath = Value
End Set
End Property
''' <summary>
''' ...
''' </summary>
<Category("Item"), Browsable(False)> Public Overridable Property MenuName() As String
Get
Return _MenuName
End Get
Set(ByVal Value As String)
_MenuName = Value
End Set
End Property
''' <summary>
''' ...
''' </summary>
<Category("Item")> Public Overridable Property Link() As String
Get
Return _Link
End Get
Set(ByVal Value As String)
_Link = Value
End Set
End Property
''' <summary>
''' ...
''' </summary>
<Category("Item")> Public Overridable Property ITType() As enuType
Get
Return _ittype
End Get
Set(ByVal Value As enuType)
_ittype = Value
End Set
End Property
''' <summary>
''' ...
''' </summary>
<Category("Item")> Public Overloads Property Name() As String
Get
Return _Name
End Get
Set(ByVal Value As String)
_Name = Value
End Set
End Property
''' <summary>
''' ...
''' </summary>
<Category("Item")> Public Property ToolTip() As String
Get
Return _ToolTip
End Get
Set(ByVal Value As String)
_ToolTip = Value
End Set
End Property
''' <summary>
''' ...
''' </summary>
<Category("Item")> Public Property Separator() As Boolean
Get
Return _sep
End Get
Set(ByVal Value As Boolean)
_sep = Value
End Set
End Property
''' <summary>
''' ...
''' </summary>
<Category("Item")> Public Property BtnScript() As String
Get
Return _btns
End Get
Set(ByVal Value As String)
_btns = Value
End Set
End Property
''' <summary>
''' ...
''' </summary>
<Category("Item")> Public Property NoPostBack() As Boolean
Get
Return _postback
End Get
Set(ByVal value As Boolean)
_postback = value
End Set
End Property
End Class
'Définition des boutons d'entete
Public Class HDbutton
Inherits HDItem
Public Sub New()
MyBase.New()
Me.ITType = HDItem.enuType.HeaderButton
End Sub
<Browsable(False)> _
Overrides Property FullPath() As String
Get
Return ""
End Get
Set(ByVal Value As String)
End Set
End Property
<Browsable(False)> _
Overrides Property menuname() As String
Get
Return ""
End Get
Set(ByVal Value As String)
End Set
End Property
<Browsable(False)> _
Overrides Property link() As String
Get
Return ""
End Get
Set(ByVal Value As String)
End Set
End Property
End Class
'Définition des boutons d'application
Public Class APbutton
Inherits HDItem
Public Sub New()
MyBase.New()
Me.ITType = HDItem.enuType.AppButton
End Sub
<Browsable(False)> _
Overrides Property FullPath() As String
Get
Return ""
End Get
Set(ByVal Value As String)
End Set
End Property
<Browsable(False)> _
Overrides Property menuname() As String
Get
Return ""
End Get
Set(ByVal Value As String)
End Set
End Property
<Browsable(False)> _
Overrides Property link() As String
Get
Return ""
End Get
Set(ByVal Value As String)
End Set
End Property
End Class
'Définition des collections de boutons et de menu avec les méthodes
Public Class ITCollection
Inherits CollectionBase
Default Public ReadOnly Property Item(ByVal pageIndex As Integer) As HDItem
Get
Return MyBase.List(pageIndex)
End Get
End Property
Public Sub Add(ByVal page As HDItem)
MyBase.List.Add(page)
End Sub
Public Function IndexOf(ByVal page As HDItem) As Integer
Return MyBase.List.IndexOf(page)
End Function
Public Function IndexOf(ByVal key As String) As Integer
Dim myItem As HDItem
Dim i As Single = 0
While (i < MyBase.List.Count)
myItem = MyBase.List.Item(i)
If (myItem.Key = key) Then
Return i
End If
i += 1
End While
Return -1
End Function
End Class
Public Class HDMenus
Inherits CollectionBase
Default Public ReadOnly Property Item(ByVal pageIndex As Integer) As HDMenu
Get
Return MyBase.List(pageIndex)
End Get
End Property
Public Sub Add(ByVal page As HDMenu)
MyBase.List.Add(page)
End Sub
Public Function IndexOf(ByVal page As HDMenu) As Integer
Return MyBase.List.IndexOf(page)
End Function
End Class
Public Class HDButtons
Inherits CollectionBase
Default Public ReadOnly Property Item(ByVal pageIndex As Integer) As HDbutton
Get
Return MyBase.List(pageIndex)
End Get
End Property
Public Sub Add(ByVal page As HDbutton)
MyBase.List.Add(page)
End Sub
Public Function IndexOf(ByVal page As HDbutton) As Integer
Return MyBase.List.IndexOf(page)
End Function
Public Sub Remove(ByVal page As HDbutton)
MyBase.List.Remove(page)
End Sub
End Class
Public Class APButtons
Inherits CollectionBase
Default Public ReadOnly Property Item(ByVal pageIndex As Integer) As APbutton
Get
Return MyBase.List(pageIndex)
End Get
End Property
Public Sub Add(ByVal page As APbutton)
MyBase.List.Add(page)
End Sub
Public Function IndexOf(ByVal page As APbutton) As Integer
Return MyBase.List.IndexOf(page)
End Function
Public Sub Remove(ByVal page As APbutton)
MyBase.List.Remove(page)
End Sub
End Class
ASKER
I can't, the system doesn't allow vb project files in the zip.
It's a copy of my code that works on my system.
Maybe it's because I use VS2008.
To test it do the following:
Just create a new class library project, add a user control named ctlHeader.vb and copy my code in the code behind part of the control.
In the control's designer, add a picturebox with any image in it.
You'll see that the buttons are created under the picture when you add buttons in the hDitems collection.
It's a copy of my code that works on my system.
Maybe it's because I use VS2008.
To test it do the following:
Just create a new class library project, add a user control named ctlHeader.vb and copy my code in the code behind part of the control.
In the control's designer, add a picturebox with any image in it.
You'll see that the buttons are created under the picture when you add buttons in the hDitems collection.
ASKER
To test the control, you'll have to add a windows form application to the solution, drag a ctlHeader control on the form, and add buttons at design time in the HDItems collection.
I have VS2008 too. But if you look at the code you have pasted the ctlHeader is not derived from anything!!!
ASKER
I know, it doesn't have to be derived from something when it's a use control.
If you create a new user control, you'll only see the following.
Public Class UserControl1
End Class
It woks on my side!
If you create a new user control, you'll only see the following.
Public Class UserControl1
End Class
It woks on my side!
I tried what you mean and it appears to work as it should. I see the buttons in front of the picture (picture is in the background as expected)!!!
actually I added
Public Class ctlHeader Inherits UserControl
without which it does not work.
Actually in your code you need to check the partial class which actually derives from uerscontrol.
if you want to see, copy the code you have pasted above in a new project and make it work as you suggested. It will not work!
Public Class ctlHeader Inherits UserControl
without which it does not work.
Actually in your code you need to check the partial class which actually derives from uerscontrol.
if you want to see, copy the code you have pasted above in a new project and make it work as you suggested. It will not work!
ASKER
Wow, thats weird, on my side the buttons are created under the picture!
I'll start from scrach, to see if it works.
I'll start from scrach, to see if it works.
ASKER
I just started a new project, and did exactly what I said in my post to create the control and it works.
Maybe it's because I use the "Windows Form Control Library" template for my controls project .
Oh, and I still have the same display order problem in my new project!!
Maybe it's because I use the "Windows Form Control Library" template for my controls project .
Oh, and I still have the same display order problem in my new project!!
Ok, just for your information, every control you create has to derive from UserControl. To see, do this:
In the Solution Explorer, click on the second toolbar button(Show All Files) at the top, you will see additional file under your control class file, open it to see the inherits statement.
In the Solution Explorer, click on the second toolbar button(Show All Files) at the top, you will see additional file under your control class file, open it to see the inherits statement.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In the above snippet
Public Class ctlHeader
is not derieved from anywhere?