Results 1 to 4 of 4

Thread: Panel Control not displaying Pictureboxes

  1. #1

    Thread Starter
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Panel Control not displaying Pictureboxes

    Trying to make a panel control that automaticly generates a thumbnail for the pictures added to it.

    I cant seem to find anything wrong with the code I have except that it only displays the first picturebox added, it does add the other ones to the panels controls but they are not shown although there visible properties are true.

    can anyone tell me why this is happening???

    {cThumbnail.vb is attached (also was throughly debuged and works properly)}

    pnl is a panel control on the user control


    VB Code:
    1. Public Class ThumbPanel
    2.     Inherits System.Windows.Forms.UserControl
    3.  
    4. #Region " Windows Form Designer generated code "
    5.  
    6.     Public Sub New()
    7.         MyBase.New()
    8.  
    9.         'This call is required by the Windows Form Designer.
    10.         InitializeComponent()
    11.  
    12.         'Add any initialization after the InitializeComponent() call
    13.  
    14.     End Sub
    15.  
    16.     'UserControl1 overrides dispose to clean up the component list.
    17.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    18.         If disposing Then
    19.             If Not (components Is Nothing) Then
    20.                 components.Dispose()
    21.             End If
    22.         End If
    23.         MyBase.Dispose(disposing)
    24.     End Sub
    25.  
    26.     'Required by the Windows Form Designer
    27.     Private components As System.ComponentModel.IContainer
    28.  
    29.     'NOTE: The following procedure is required by the Windows Form Designer
    30.     'It can be modified using the Windows Form Designer.  
    31.     'Do not modify it using the code editor.
    32.     Friend WithEvents pnl As System.Windows.Forms.Panel
    33.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    34.         Me.pnl = New System.Windows.Forms.Panel
    35.         Me.SuspendLayout()
    36.         '
    37.         'pnl
    38.         '
    39.         Me.pnl.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
    40.                     Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
    41.         Me.pnl.AutoScroll = True
    42.         Me.pnl.Location = New System.Drawing.Point(0, 0)
    43.         Me.pnl.Name = "pnl"
    44.         Me.pnl.Size = New System.Drawing.Size(496, 152)
    45.         Me.pnl.TabIndex = 0
    46.         '
    47.         'ThumbPanel
    48.         '
    49.         Me.Controls.Add(Me.pnl)
    50.         Me.Name = "ThumbPanel"
    51.         Me.Size = New System.Drawing.Size(232, 152)
    52.         Me.ResumeLayout(False)
    53.  
    54.     End Sub
    55.  
    56. #End Region
    57.  
    58.     Public Event Thumbnail_SingleClicked(ByRef ctrlControl As Control)
    59.     Public Event Thumbnail_DoubleClicked(ByRef ctrlControl As Control)
    60.  
    61.     'Properties
    62.     'Thumbnail Properties
    63.     Private m_ThumbMaxWidth As Long
    64.     Private m_ThumbMaxHeight As Long
    65.     'Spacing Settings
    66.     Private m_ThumbSpaceWidth As Long ' How much distance between Thumbnails
    67.     Private m_ThumbSpaceHeight As Long ' how much distance between Rows
    68.  
    69.     Public Property MaxThumbnailWidth() As Long
    70.         Get
    71.             Return m_ThumbMaxWidth
    72.         End Get
    73.         Set(ByVal Value As Long)
    74.             m_ThumbMaxWidth = Value
    75.         End Set
    76.     End Property
    77.  
    78.     Public Property MaxThumbnailHeight() As Long
    79.         Get
    80.             Return m_ThumbMaxHeight
    81.         End Get
    82.         Set(ByVal Value As Long)
    83.             m_ThumbMaxHeight = Value
    84.         End Set
    85.     End Property
    86.  
    87.     Public Property ThumbSpaceWidth() As Long
    88.         Get
    89.             Return m_ThumbSpaceWidth
    90.         End Get
    91.         Set(ByVal Value As Long)
    92.             m_ThumbSpaceWidth = Value
    93.         End Set
    94.     End Property
    95.  
    96.     Public Property ThumbSpaceHeight() As Long
    97.         Get
    98.             Return m_ThumbSpaceHeight
    99.         End Get
    100.         Set(ByVal Value As Long)
    101.             m_ThumbSpaceHeight = Value
    102.         End Set
    103.     End Property
    104.  
    105.     'Methods
    106.  
    107.     Public Function AddImage(ByRef imgImage As Image) As Long
    108.         'Returns ControlID
    109.         Dim Thumb As New cThumbnail
    110.  
    111.         With Thumb
    112.             .MaxThumbnailHeight() = m_ThumbMaxHeight
    113.             .MaxThumbnailWidth() = m_ThumbMaxWidth
    114.             .SourceImage() = imgImage
    115.             .GenerateThumbnail()
    116.  
    117.             pnl.Controls.Add(GetPictureBox(.ThumbnailImage))
    118.             CType(pnl.Controls.Item(pnl.Controls.Count - 1), Windows.Forms.PictureBox).Image = .ThumbnailImage
    119.             pnl.Controls.Item(pnl.Controls.Count - 1).Update()
    120.         End With
    121.     End Function
    122.  
    123.     Private Function GetPictureBox(ByRef imgImage As Image) As PictureBox
    124.         Dim pic As New PictureBox
    125.  
    126.         With pic
    127.             .BorderStyle = BorderStyle.FixedSingle
    128.             .SizeMode = PictureBoxSizeMode.CenterImage
    129.             .Height = m_ThumbMaxHeight
    130.             .Width = m_ThumbMaxWidth
    131.             NewTopLeft(.Top, .Left)
    132.             .Image = imgImage
    133.             .Visible = True
    134.         End With
    135.  
    136.         'Create Handlers
    137.  
    138.         AddHandler pic.Click, New System.EventHandler(AddressOf SingleClicked)
    139.         AddHandler pic.DoubleClick, New System.EventHandler(AddressOf DoubleClicked)
    140.  
    141.         Return pic
    142.     End Function
    143.  
    144.     Private Function NewTopLeft(ByRef lngNewTop As Long, ByRef lngNewLeft As Long)
    145.         Dim ctrl As Control
    146.  
    147.         If pnl.Controls.Count = 0 Then
    148.             'No pictures have been added yet!
    149.             lngNewTop = m_ThumbSpaceHeight
    150.             lngNewLeft = m_ThumbSpaceWidth
    151.             Exit Function
    152.         End If
    153.  
    154.         ctrl = pnl.Controls.Item(Me.Controls.Count - 1)
    155.  
    156.         lngNewTop = ctrl.Top + ctrl.Height + m_ThumbSpaceHeight
    157.         lngNewLeft = ctrl.Left + ctrl.Width + m_ThumbSpaceWidth
    158.  
    159.         If pnl.Width < (lngNewLeft + m_ThumbMaxWidth) Then
    160.             'we need to go down and all the way to the left
    161.             'so the left is the easiest
    162.             lngNewLeft = m_ThumbSpaceWidth
    163.             lngNewTop = lngNewTop + m_ThumbMaxHeight + m_ThumbMaxHeight
    164.         End If
    165.     End Function
    166.  
    167.     Public Function ClearAll()
    168.         pnl.Controls.Clear()
    169.     End Function
    170.  
    171.     'Picturebox Event Handlers
    172.  
    173.     Private Sub SingleClicked(ByVal sender As Object, ByVal e As System.EventArgs)
    174.         RaiseEvent Thumbnail_SingleClicked(sender)
    175.     End Sub
    176.  
    177.     Private Sub DoubleClicked(ByVal sender As Object, ByVal e As System.EventArgs)
    178.         RaiseEvent Thumbnail_DoubleClicked(sender)
    179.     End Sub
    180.  
    181. End Class
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    a couple of things i notice, first is that i'd change all the Longs to Integers, as Longs aren't really supposed to be run in.net ( although you can use Int64 )
    second thing is, in the following section....
    With pic
    .BorderStyle = BorderStyle.FixedSingle
    .SizeMode = PictureBoxSizeMode.CenterImage
    .Height = m_ThumbMaxHeight
    .Width = m_ThumbMaxWidth
    NewTopLeft(.Top, .Left)
    .Image = imgImage
    .Visible = True
    End With
    have you tried adding the pic to the Panel's Controls before specifying the location ( NewTopLeft(.Top, .Left) ) , then it will use the location of the inside of the panel rather than of the Form.
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    a couple of things i notice, first is that i'd change all the Longs to Integers, as Longs aren't really supposed to be run in.net
    Really, I got alot of code to change then

    Found the source of my problem:

    VB Code:
    1. Private Function NewTopLeft(ByRef lngNewTop As Long, ByRef lngNewLeft As Long)
    2.         Dim ctrl As Control
    3.  
    4.         If pnl.Controls.Count = 0 Then
    5.             'No pictures have been added yet!
    6.             lngNewTop = m_ThumbSpaceHeight
    7.             lngNewLeft = m_ThumbSpaceWidth
    8.             Exit Function
    9.         End If
    10.  
    11.         ctrl = pnl.Controls.Item(Me.Controls.Count - 1)
    12.  
    13.         lngNewTop = ctrl.Top + ctrl.Height + m_ThumbSpaceHeight
    14.         lngNewLeft = ctrl.Left + ctrl.Width + m_ThumbSpaceWidth
    15.  
    16.         If pnl.Width < (lngNewLeft + m_ThumbMaxWidth) Then
    17.             'we need to go down and all the way to the left
    18.             'so the left is the easiest
    19.             lngNewLeft = m_ThumbSpaceWidth
    20.             lngNewTop = lngNewTop + m_ThumbMaxHeight + m_ThumbMaxHeight
    21.         End If
    22.     End Function

    changed to:

    VB Code:
    1. Private Function NewTopLeft(ByRef lngNewTop As Long, ByRef lngNewLeft As Long)
    2.         Dim pic As PictureBox
    3.  
    4.         If pnl.Controls.Count = 0 Then
    5.             'No pictures have been added yet!
    6.             lngNewTop = m_ThumbSpaceHeight
    7.             lngNewLeft = m_ThumbSpaceWidth
    8.             Exit Function
    9.         End If
    10.  
    11.         pic = pnl.Controls.Item(pnl.Controls.Count - 1)
    12.  
    13.         lngNewTop = pic.Top
    14.         lngNewLeft = pic.Left + pic.Width + m_ThumbSpaceWidth
    15.  
    16.         If pnl.Width < (lngNewLeft + m_ThumbMaxWidth) Then
    17.             'we need to go down and all the way to the left
    18.             'so the left is the easiest
    19.             lngNewLeft = m_ThumbSpaceWidth
    20.             lngNewTop = m_ThumbSpaceHeight + pic.Top + pic.Height
    21.         End If
    22.     End Function

    and it works fine!
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  4. #4

    Thread Starter
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    Changed all longs to integers as sugested, added runtime control resizing, BorderStyle, BackgroudImage, Cursor Properties added for panel. Supports SingleClick and Double Click on Thumbnails.

    Anyone got any sugestions or found any bugs?

    Project Attached {VS 2003 format}
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width