Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Simple question about PictureBoxes

Posted on 2009-04-08
5
Medium Priority
?
545 Views
Last Modified: 2012-05-06
:  Ok, well, I have a trial subscription, but I googled a bunch on this, and nothing that I found worked. Perhaps the experts exchange model is the best for solutions, as required by the workplace.

I am dynamically adding buttons to an inherited form class (the class inherits "form", is maximized, has a background and a picturebox on it to make it look nice ... as simple as it gets).... anyway, I am dynamically adding buttons, and the buttons always show behind the picturebox, even as I use bringToFront, and even if I do this AFTER adding to the control array (after me.controls.add).

I think I'm missing something very fundamental here, but I didn't plan on spending three hours trying to get a label on top of a picturebox, so I'm asking for help.

Thanks
0
Comment
Question by:jj_30
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 2

Author Comment

by:jj_30
ID: 24098203
I cant see my code and it's making me thing that it's missing. Here it is...

Public Class Main 
    Private Sub FormSpecific()
        Me.lblPassword.Parent = Me.picField
        Me.lblPassword.Location = New Point(10, 4)  'relative positioning to the parent
        Me.lblPassword.BringToFront()
        Me.lblPassword.BackColor = Color.Transparent
        Me.picField.BackColor = Color.Transparent
        Me.picField.SendToBack()
 
        For i As Integer = 0 To Me.Controls.OfType(Of GlassButton).Count - 1
            Me.Controls.Item(i).BringToFront()
        Next
    End Sub
    Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        FormSpecific()
 
        'Go to db, get users
        Dim objDataTable As New DataTable
        objDataTable = dbReader("SELECT * FROM TblUsers ORDER BY UserID")
 
        Me.KeyPreview = True
 
        'Dad, mom, etc. Now put some buttons on the main form.
        For i As Integer = 0 To objDataTable.Rows.Count - 1
            With objDataTable(i)
                'draw buttons
                Dim currButton As New GlassButton
                currButton.Text = objDataTable.Rows(i)(1)
                currButton.AvailableOption = IIf(.Item("UserEnabled") = 1, True, False)
 
                Dim currButtonLoc As New Point
                currButtonLoc.X = xStart
                currButtonLoc.Y = yStart + i * (currButton.Height + nButtonSpacing * 2) 'top and bottom margins nButtonSpacing ea.
                currButton.Location = currButtonLoc
 
                Me.Controls.Add(currButton)
            End With
        Next i
 
    End Sub
 
End Class

Open in new window

0
 
LVL 11

Accepted Solution

by:
bmatumbura earned 500 total points
ID: 24098432
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 24098907
This jumps out at me:

        For i As Integer = 0 To Me.Controls.OfType(Of GlassButton).Count - 1
            Me.Controls.Item(i).BringToFront()
        Next

The "i" value is simply going from 0 to Count -1...BUT the there is NO correlation between "i" and the corresponding returned controls position in the Items() collection:

            Me.Controls.Item(i).BringToFront() ' <----- it doesn't make sense to use "i" here

I think you actually wanted this:

        For Each gb As GlassButton In Me.Controls.OfType(Of GlassButton)()
            gb.BringToFront()
        Next

0
 
LVL 2

Author Closing Comment

by:jj_30
ID: 31568076
Why, yes ...   it does help.

Thanks
0
 
LVL 2

Author Comment

by:jj_30
ID: 24100016
Hm, the OfType enumeration doesn't seem to work like I thought. It's linq-related.

me.controls.oftype(of GlassButton) returns something that's hard to parse.

It has <>3__source, <>7__wrapa5, etc. ... Perhaps a little advanced for me today.

Thanks for your help though!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

722 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