Windows Develop Bookmark and Share   
 index > Windows Forms Designer > on button click change mouse cursor
 

on button click change mouse cursor

I am after the mouse cursor to change image when i click on a picture box, not sure if i can run private subs under private sub button_click.
i am using vb 2008 windows form aplication
new to programming, cant find answer in help
please help
thanks in advance
darren76  Thursday, July 16, 2009 1:34 AM
Hi darren76,

It is unclear to me whether you want to change the image of PictureBox or the cursor of the mouse.
Here is the code for both
Public Class Form1
Private imgList As ImageList
Private current As Integer

Public Sub New()
InitializeComponent()

Me.PictureBox1.Cursor = Cursors.PanEast

imgList = New ImageList()
imgList.ImageSize = New Size(100, 100)
Dim imgFile1 = "D:\a.jpg"
Dim imgFile2 = "D:\b.jpg"
Dim img As Image = Image.FromFile(imgFile1)
imgList.Images.Add(img)

img = Image.FromFile(imgFile2)
imgList.Images.Add(img)

PictureBox1.Image = imgList.Images(0)
current = 0
End Sub

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
current = current + 1
PictureBox1.Image = imgList.Images(current Mod 2)
End Sub
End Class

The sample has only two picture, I store them in an ImageList, each time you click the PictureBox, the image will change to another one.

As for the mouse cursor, I have set it to Cursors.PanEast. Does it what you need?

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
  • Marked As Answer bydarren76 Friday, July 17, 2009 3:47 PM
  •  
Kira Qian  Friday, July 17, 2009 8:21 AM
Hi darren76,

It is unclear to me whether you want to change the image of PictureBox or the cursor of the mouse.
Here is the code for both
Public Class Form1
Private imgList As ImageList
Private current As Integer

Public Sub New()
InitializeComponent()

Me.PictureBox1.Cursor = Cursors.PanEast

imgList = New ImageList()
imgList.ImageSize = New Size(100, 100)
Dim imgFile1 = "D:\a.jpg"
Dim imgFile2 = "D:\b.jpg"
Dim img As Image = Image.FromFile(imgFile1)
imgList.Images.Add(img)

img = Image.FromFile(imgFile2)
imgList.Images.Add(img)

PictureBox1.Image = imgList.Images(0)
current = 0
End Sub

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
current = current + 1
PictureBox1.Image = imgList.Images(current Mod 2)
End Sub
End Class

The sample has only two picture, I store them in an ImageList, each time you click the PictureBox, the image will change to another one.

As for the mouse cursor, I have set it to Cursors.PanEast. Does it what you need?

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
  • Marked As Answer bydarren76 Friday, July 17, 2009 3:47 PM
  •  
Kira Qian  Friday, July 17, 2009 8:21 AM

You can use google to search for other answers

Custom Search

More Threads

• Suppress components to be shown in toolbox
• back color problem
• Error message when switchign between designer and code view
• more on system date
• How can I save or change application settings?
• My app run low and vs too
• IPersistComponentSettings
• Custom Control
• Custom form transparency problem
• Developing a Keyboard component