By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,002 Members | 1,261 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,002 IT Pros & Developers. It's quick & easy.

Determining a Control's Properties on MouseHover Event

P: 2
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.image 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!


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.SqlClient
Imports System.drawing
Imports System.Windows.Forms.UserControl
Imports System.Windows.Forms.screen

Public Class FindPicturesForFilmStrip

Public pb As New PictureBox

Public Sub pb_MouseLeave(ByVal Sender As Object, ByVal e As System.EventArgs)
End Sub

Public Sub pb_MouseHover(ByVal Sender As Object, ByVal e As System.EventArgs)

Dim pb1 As PictureBox = New PictureBox

'Dim pb As PictureBox = New PictureBox
'Dim Pic As PictureBox = CType(Sender, PictureBox)


With pb1

.Height = 660
.Width = 660

.SizeMode = PictureBoxSizeMode.StretchImage
'.Location = New Point(pb.Width * Pass + Offset, 10)
'.Image = New Bitmap(pb.Image)
'.Name = dr(0).ToString
frmProduct.UcSinglePictureViewer1.Controls.Add(pb1 )

End With

With frmProduct.UcSinglePictureViewer1

'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.PrimaryScreen
Dim scrWidth = scr.Bounds.Width
Dim scrHeight = scr.Bounds.Height

'Calculate center for position of picture viewer user control
.Left = (scrWidth - ucWidth) / 2
'.Top = (scrHeight - ucHeight) / 2


End With

End Sub

Public Sub FindPicturesForFilmStrip()

'read ItemNo variable from frmProduct
Dim ItemNo As String = frmProduct.ItemNo

'Clear picture box controls in film strip viewer for each new record

Do While frmProduct.UcFileStripViewer1.Controls.Count <> 0

'Set SQL Connection
Dim strConn As String = Settings.EuroLuxConn.ToString
Dim conn As New SqlConnection(strConn)
Dim strSProc As String = "uspSelectImagesForFilmStripControl"

'Set SQL cmd object
Dim cmd As New SqlCommand(strSProc, conn)

cmd.CommandType = CommandType.StoredProcedure

'Pass parameter to storedprocedure
With cmd.Parameters
.Add(New SqlParameter("@InvNum", ItemNo))
End With

'Open connection and run stored procedure


'Define and execute data reader to read recordset returned by stored procedure
Dim dr As SqlDataReader = cmd.ExecuteReader

'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 = PictureBoxSizeMode.StretchImage
.Location = New Point(pb.Width * Pass + Offset, 10)
.Image = New Bitmap(dr(1).ToString)
.Name = dr(0).ToString
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)
End With

Offset = Offset + 10
Pass += 1

End While

'Close Connection

End Sub

End Class
Apr 13 '08 #1
Share this Question
Share on Google+
1 Reply

P: 2
As a follow up, I have been able to set a new instance of a control and successfully used the following code to determine the name of a control:

Dim ctrCurr As New Control
ctrCurr = Form.ActiveForm.ActiveControl

The problem is that my pictureboxes are sitting in a panel of a split container control on the form, and all the Name property is returning is the Name of the split container itself. How do I drill down to the level below the split container? I know I'm close!

Apr 13 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.