Hi All,
Using VB.Net with SQL Server. I have a form that I create a number of Picture Boxes on dynamically, based on a stored procedure that retrieves a listing of images available for a particular product and populates the picture boxes using the paths found by the stored procedure. Anyway, that part works great.
I have the Picture Boxes set a 231 px wide by 231 px high, and I want to resize these in a separate box when a user hovers over a particular picture. I've used an Event Handler to do this, and I can get a picture box to pop up where I want and in the size I want when the user hovers over. The problem is how to set the picturebox.imag e property. How do you tell what the image property of a particular picturebox is when you hover over it? All picture boxes were created dynamically, and there can be as few as 0 and as many as 60+ picture boxes on the form. I want the user to just be able to hover over any one of them and have a bigger version of the picturebox pop up on the screen. I'll post my code below. Like I said, the pictureboxes are on the form showing the pictures as I want. I can get a place holder to pop up for the bigger pictures. I just need to be able to "read" the image property for the picturebox that the user is hovering over.
Any help would be MUCH appreciated!
Thanks,
Greg
Code (I've left some of my test code in, but commented out. The code works so far except I can't get the large picturebox to populate the image dynamically based on the small picturebox that the user is hovering over):
Imports system.Data.Sql Client
Imports System.io
Imports System.drawing
Imports System.Windows. Forms.UserContr ol
Imports System.Windows. Forms.screen
Public Class FindPicturesFor FilmStrip
Public pb As New PictureBox
Public Sub pb_MouseLeave(B yVal Sender As Object, ByVal e As System.EventArg s)
frmProduct.UcSi nglePictureView er1.Hide()
End Sub
Public Sub pb_MouseHover(B yVal Sender As Object, ByVal e As System.EventArg s)
Dim pb1 As PictureBox = New PictureBox
'Dim pb As PictureBox = New PictureBox
'Dim Pic As PictureBox = CType(Sender, PictureBox)
'MsgBox(pb.Name )
With pb1
.Height = 660
.Width = 660
.SizeMode = PictureBoxSizeM ode.StretchImag e
'.Location = New Point(pb.Width * Pass + Offset, 10)
'.Image = New Bitmap(pb.Image )
'.Name = dr(0).ToString
frmProduct.UcSi nglePictureView er1.Controls.Ad d(pb1)
End With
With frmProduct.UcSi nglePictureView er1
'Find dimensions of picture viewer user control
Dim ucWidth As Integer = .Width
Dim ucHeight As Integer = .Height
'Find dimensions of user's screen
Dim scr As System.Windows. Forms.Screen = System.Windows. Forms.Screen.Pr imaryScreen
Dim scrWidth = scr.Bounds.Widt h
Dim scrHeight = scr.Bounds.Heig ht
'Calculate center for position of picture viewer user control
.Left = (scrWidth - ucWidth) / 2
'.Top = (scrHeight - ucHeight) / 2
.BringToFront()
.Show()
End With
End Sub
Public Sub FindPicturesFor FilmStrip()
'read ItemNo variable from frmProduct
Dim ItemNo As String = frmProduct.Item No
'Clear picture box controls in film strip viewer for each new record
Do While frmProduct.UcFi leStripViewer1. Controls.Count <> 0
frmProduct.UcFi leStripViewer1. Controls.Remove At(0)
Loop
'Set SQL Connection
Dim strConn As String = Settings.EuroLu xConn.ToString
Dim conn As New SqlConnection(s trConn)
Dim strSProc As String = "uspSelectImage sForFilmStripCo ntrol"
'Set SQL cmd object
Dim cmd As New SqlCommand(strS Proc, conn)
cmd.CommandType = CommandType.Sto redProcedure
'Pass parameter to storedprocedure
With cmd.Parameters
.Add(New SqlParameter("@ InvNum", ItemNo))
End With
'Open connection and run stored procedure
conn.Open()
cmd.ExecuteNonQ uery()
'Define and execute data reader to read recordset returned by stored procedure
Dim dr As SqlDataReader = cmd.ExecuteRead er
'Set parameters for placement of picture boxes
Dim Offset As Integer
Offset = 0
Dim Pass As Integer
Pass = 0
'Use data reader to read records
While dr.Read
'Set up variables for making picture boxes and labels
Dim pb As New PictureBox
Dim lblPb As New Label
'Add picture boxes dynamically based on what is found by stored procedure
With pb
.Height = 231
.Width = 231
'.AutoSize = True
.SizeMode = PictureBoxSizeM ode.StretchImag e
.Location = New Point(pb.Width * Pass + Offset, 10)
.Image = New Bitmap(dr(1).To String)
.Name = dr(0).ToString
frmProduct.UcFi leStripViewer1. Controls.Add(pb )
AddHandler pb.MouseHover, AddressOf pb_MouseHover
AddHandler pb.MouseLeave, AddressOf pb_MouseLeave
End With
'Add labels for the picture boxes dynamically
With lblPb
.AutoSize = True
.Text = dr(0).ToString
'Calculate x position to center label under each picture
Dim x As Long
x = pb.Location.X + ((231 - lblPb.Width) / 2)
'x = (pb.Width * Pass) + Offset
.AutoSize = True
.Location = New Point(x, pb.Height + 20)
frmProduct.UcFi leStripViewer1. Controls.Add(lb lPb)
End With
Offset = Offset + 10
Pass += 1
'MsgBox(dr(1).T oString)
End While
'Close Connection
conn.Close()
End Sub
End Class
Using VB.Net with SQL Server. I have a form that I create a number of Picture Boxes on dynamically, based on a stored procedure that retrieves a listing of images available for a particular product and populates the picture boxes using the paths found by the stored procedure. Anyway, that part works great.
I have the Picture Boxes set a 231 px wide by 231 px high, and I want to resize these in a separate box when a user hovers over a particular picture. I've used an Event Handler to do this, and I can get a picture box to pop up where I want and in the size I want when the user hovers over. The problem is how to set the picturebox.imag e property. How do you tell what the image property of a particular picturebox is when you hover over it? All picture boxes were created dynamically, and there can be as few as 0 and as many as 60+ picture boxes on the form. I want the user to just be able to hover over any one of them and have a bigger version of the picturebox pop up on the screen. I'll post my code below. Like I said, the pictureboxes are on the form showing the pictures as I want. I can get a place holder to pop up for the bigger pictures. I just need to be able to "read" the image property for the picturebox that the user is hovering over.
Any help would be MUCH appreciated!
Thanks,
Greg
Code (I've left some of my test code in, but commented out. The code works so far except I can't get the large picturebox to populate the image dynamically based on the small picturebox that the user is hovering over):
Imports system.Data.Sql Client
Imports System.io
Imports System.drawing
Imports System.Windows. Forms.UserContr ol
Imports System.Windows. Forms.screen
Public Class FindPicturesFor FilmStrip
Public pb As New PictureBox
Public Sub pb_MouseLeave(B yVal Sender As Object, ByVal e As System.EventArg s)
frmProduct.UcSi nglePictureView er1.Hide()
End Sub
Public Sub pb_MouseHover(B yVal Sender As Object, ByVal e As System.EventArg s)
Dim pb1 As PictureBox = New PictureBox
'Dim pb As PictureBox = New PictureBox
'Dim Pic As PictureBox = CType(Sender, PictureBox)
'MsgBox(pb.Name )
With pb1
.Height = 660
.Width = 660
.SizeMode = PictureBoxSizeM ode.StretchImag e
'.Location = New Point(pb.Width * Pass + Offset, 10)
'.Image = New Bitmap(pb.Image )
'.Name = dr(0).ToString
frmProduct.UcSi nglePictureView er1.Controls.Ad d(pb1)
End With
With frmProduct.UcSi nglePictureView er1
'Find dimensions of picture viewer user control
Dim ucWidth As Integer = .Width
Dim ucHeight As Integer = .Height
'Find dimensions of user's screen
Dim scr As System.Windows. Forms.Screen = System.Windows. Forms.Screen.Pr imaryScreen
Dim scrWidth = scr.Bounds.Widt h
Dim scrHeight = scr.Bounds.Heig ht
'Calculate center for position of picture viewer user control
.Left = (scrWidth - ucWidth) / 2
'.Top = (scrHeight - ucHeight) / 2
.BringToFront()
.Show()
End With
End Sub
Public Sub FindPicturesFor FilmStrip()
'read ItemNo variable from frmProduct
Dim ItemNo As String = frmProduct.Item No
'Clear picture box controls in film strip viewer for each new record
Do While frmProduct.UcFi leStripViewer1. Controls.Count <> 0
frmProduct.UcFi leStripViewer1. Controls.Remove At(0)
Loop
'Set SQL Connection
Dim strConn As String = Settings.EuroLu xConn.ToString
Dim conn As New SqlConnection(s trConn)
Dim strSProc As String = "uspSelectImage sForFilmStripCo ntrol"
'Set SQL cmd object
Dim cmd As New SqlCommand(strS Proc, conn)
cmd.CommandType = CommandType.Sto redProcedure
'Pass parameter to storedprocedure
With cmd.Parameters
.Add(New SqlParameter("@ InvNum", ItemNo))
End With
'Open connection and run stored procedure
conn.Open()
cmd.ExecuteNonQ uery()
'Define and execute data reader to read recordset returned by stored procedure
Dim dr As SqlDataReader = cmd.ExecuteRead er
'Set parameters for placement of picture boxes
Dim Offset As Integer
Offset = 0
Dim Pass As Integer
Pass = 0
'Use data reader to read records
While dr.Read
'Set up variables for making picture boxes and labels
Dim pb As New PictureBox
Dim lblPb As New Label
'Add picture boxes dynamically based on what is found by stored procedure
With pb
.Height = 231
.Width = 231
'.AutoSize = True
.SizeMode = PictureBoxSizeM ode.StretchImag e
.Location = New Point(pb.Width * Pass + Offset, 10)
.Image = New Bitmap(dr(1).To String)
.Name = dr(0).ToString
frmProduct.UcFi leStripViewer1. Controls.Add(pb )
AddHandler pb.MouseHover, AddressOf pb_MouseHover
AddHandler pb.MouseLeave, AddressOf pb_MouseLeave
End With
'Add labels for the picture boxes dynamically
With lblPb
.AutoSize = True
.Text = dr(0).ToString
'Calculate x position to center label under each picture
Dim x As Long
x = pb.Location.X + ((231 - lblPb.Width) / 2)
'x = (pb.Width * Pass) + Offset
.AutoSize = True
.Location = New Point(x, pb.Height + 20)
frmProduct.UcFi leStripViewer1. Controls.Add(lb lPb)
End With
Offset = Offset + 10
Pass += 1
'MsgBox(dr(1).T oString)
End While
'Close Connection
conn.Close()
End Sub
End Class
Comment