473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Determining a Control's Properties on MouseHover Event

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!

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.SqlClient
Imports System.io
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)
frmProduct.UcSinglePictureViewer1.Hide()
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)

'MsgBox(pb.Name)


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

.BringToFront()

.Show()
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
frmProduct.UcFileStripViewer1.Controls.RemoveAt(0)
Loop


'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
conn.Open()

cmd.ExecuteNonQuery()

'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
frmProduct.UcFileStripViewer1.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.UcFileStripViewer1.Controls.Add(lblPb)
End With

Offset = Offset + 10
Pass += 1

'MsgBox(dr(1).ToString)
End While

'Close Connection
conn.Close()




End Sub

End Class
Apr 13 '08 #1
1 2467
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!

Thanks!
Greg
Apr 13 '08 #2

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

Similar topics

3
by: Ian Ornstein | last post by:
I am coding a windows form. The form has several labels and I hoped to use one click event because the processing to be done is very similar. I just tried this: void lblDayNoClick(object sender,...
2
by: Garrett | last post by:
Need any help in determining which groups have been given security access to a folder. Searched DirectoryServices to no avail... Any Help?
15
by: Tinus | last post by:
Hello all, I've created a custom control that draws a monthly schedule (using the Draw function in C#). Basically it draws 31 boxes and writes the day number in every box. This works...
5
by: Smoke | last post by:
What i want to do, is, in the Activate Event of my form, determine which is the mouse possition, or, maybe even easy, just determine if the mouse is over my form. I need to do two differents things...
6
by: Jan Warning | last post by:
Hi, how can I determine (at run time) the type of an Object and how can I use the obtained result to do a type conversion with CType? I tried something like: dim myType as type myType =...
6
by: Jack | last post by:
Hello, I've noticed through searching this group's previous posts that one can get the item the mouse is over in a listview control but I did not see how to get the subitem the mouse is over. Is...
2
by: bretth | last post by:
In a VB.Net Windows Forms application, I have a user control that handles mouse events. Another section of code programmatically adds a label to the control. I would like label to ignore all...
3
by: Marc | last post by:
Hi, I create buttons dynamically at runtime in my application. I want to open a messgae box when the user hovers over a button.how can i do this? i need something like the below(which doesnt...
1
by: johnson.bj | last post by:
I have a relatively minor problem that has been bugging me for a long time. I have created a user control which consists of a few panels and labels. What I want to do with this user control is to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.