Results 1 to 4 of 4

Thread: [RESOLVED] [2005] Load all system Cursors into Combo

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    384

    Resolved [RESOLVED] [2005] Load all system Cursors into Combo

    Hello again everyone!

    Is it possible to use a For loop to load all the system cursors / VB.NET cursors into a combobox. I tried the following (which obviously couldn't work - but it's based on a similar way I load all the system fonts - FontFamilies)

    Code:
            Dim cC As Cursor
            For Each cC In Me.System.Windows.Forms.Cursor
                cboCursors.Items.Add(cC.Name)
            Next
    Any advice?

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: [2005] Load all system Cursors into Combo

    With a little Reflection...
    Code:
    Imports System.Reflection
    
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            For Each p As PropertyInfo In GetType(Cursors).GetProperties
                If (p.PropertyType Is GetType(Cursor)) Then
                    ComboBox1.Items.Add(p.Name)
                End If
            Next
    
        End Sub
    
    End Class
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    384

    Re: [2005] Load all system Cursors into Combo

    WOW! Thanx!!

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    384

    Re: [2005] Load all system Cursors into Combo

    OOPs, I forgot, how would I set the cursor from this loaded list?
    Just made anrray - duh!

    Code:
        Private CurseInt As Integer 'keeps track of selected item
        Private CursorArray() As Cursor 'cursor array
    
    'In Form Load
     ReDim CursorArray(cboCursors.Items.Count)
            CursorArray(0) = Cursors.AppStarting
            CursorArray(1) = Cursors.Arrow
            CursorArray(2) = Cursors.Cross
            CursorArray(3) = Cursors.Default
            CursorArray(4) = Cursors.Hand
            CursorArray(5) = Cursors.Help
            CursorArray(6) = Cursors.HSplit
    'etc.  until all 28 cursors are stored in the array
    
    'in combo selectedindexchanged event
     CurseInt = (cboCursors.SelectedIndex) 'if sel > -1
    
    'then in button
    Me.Cursor = CursorArray(CurseInt)
    It works, but isn't there perhaps an easier way?
    Last edited by GrimmReaper; May 8th, 2007 at 10:04 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width