|
Hello everyone!
Is it possible to store and retrieve cursor images using an ImageList control? (The images stored in the ImageList are bitmaps.)
Since both the cursor and icon formats work for a mouse cursor, I have pulled the bitmaps out of the ImageList control and converted them to the icon format. But that is as far as I have been able to get. Below is my attempt to get this to work.
(Also, I have tried storing the icons in the ImageList as Icons but it looks like you can only pull the icon images out of the list as bitmaps or other non-icon image types).
Private Sub Grid_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Grid.DoubleClick
1.Dim objMStream As New IO.MemoryStream() 2.Dim objIcon As Icon 3.Dim objBitmap As New Bitmap(ImageList.Images(Grid.Columns("ImageIndex").Value)) 4.Dim IP As IntPtr = objBitmap.GetHicon
5.objIcon = Icon.FromHandle(IP) 6.objIcon.Save(objMStream) 7.gobjCursor = New Cursor(objMStream) //gobjCursor is my global cursor object 8.DestroyIcon(IP)
End Sub
The app stops running on #7 and produces the following error: Invalid image format. The image file may be corrupt.
THE FUNCTIONALITY I AM TRYING TO ACHIEVE: The user selects a tickmark from a list of bitmap images i.e. checkmarks, pluses, and other various symbols)poulating a grid. When the user clicks on a row, the mouse changes to the selected image. With the new mouse cursor, the user moves to and clicks on one of any various other controls populating the form (textboxes, comboboxes, datetimepickers and numericupdowns--each control has an invisible picturebox to its right). When the user clicks on one of the four "valid" controls, the picturebox is populated with the cursor's equivalent bitmap image and the cursor returns to the default arrow.
I can't embed cursor files into the app because I need to allow the app's users the ability to add their own custom tickmark bitmaps.
I would appreciate any help! Sorry about hitting the forum so often lately with questions but looking through help files, VB Books and Newsgroups has produced no answers, a weekend at work, and a now annoyed wife. Good thing Valentines Day is coming up! :)
(I will post the corrected code here, if what I am trying to acheive is possible.)
Thanks -Charles
|