Solved

Child controls display order in a composite control

Posted on 2008-06-20
11
607 Views
Last Modified: 2013-12-25
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



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

Open in new window

0
Comment
Question by:hqdev
  • 6
  • 5
11 Comments
 
LVL 3

Expert Comment

by:JayeshKitukale
ID: 21832534
The attached code does not work, can you attach zipped complete code that works?
In the above snippet
Public Class ctlHeader
is not derieved from anywhere?
0
 

Author Comment

by:hqdev
ID: 21832930
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.
0
 

Author Comment

by:hqdev
ID: 21832939
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.
0
 
LVL 3

Expert Comment

by:JayeshKitukale
ID: 21832964
I have VS2008 too. But if you look at the code you have pasted the ctlHeader is not derived from anything!!!
0
 

Author Comment

by:hqdev
ID: 21832994
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!
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 3

Expert Comment

by:JayeshKitukale
ID: 21833001
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)!!!
0
 
LVL 3

Expert Comment

by:JayeshKitukale
ID: 21833015
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!
0
 

Author Comment

by:hqdev
ID: 21833023
Wow, thats weird, on my side the buttons are created under the picture!
I'll start from scrach, to see if it works.
0
 

Author Comment

by:hqdev
ID: 21833098
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!!
0
 
LVL 3

Expert Comment

by:JayeshKitukale
ID: 21836209
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.
0
 

Accepted Solution

by:
hqdev earned 0 total points
ID: 21882717
I found a workaround, I placed panels on top of my pictures with the same background color as the picture and create the buttons in those. It's not perfect but it works.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now