?
Solved

How to generate a cursor for a mousepointer in runtime

Posted on 2004-04-30
10
Medium Priority
?
352 Views
Last Modified: 2010-04-24
Hi,

I would like to generate a mousecursor in runtime.  (I don't have the .cur -file: it has to be created in runtime)
0
Comment
Question by:dekeyzer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 27

Expert Comment

by:planocz
ID: 10958865
do you want a mouse cursor on all of the form or per control or want?
I need just a little more info.
thanks
0
 

Author Comment

by:dekeyzer
ID: 10958875
all of the form.
0
 
LVL 27

Expert Comment

by:planocz
ID: 10958988
Hi dekeyzer,

Here is an example that I got from Microsoft.
If you do a search on the net you can find free cur and ani files to use.
that is the only way that i know of using  extern curs.

Imports System.IO
Namespace Microsoft.Samples
    Public Class ctlCursors
        Inherits System.Windows.Forms.Form

        Private Const cursorColored As String = "harrow.cur"
        Private Const cursorAnimated As String = "dinosaur.ani"
#Region " Windows Form Designer generated code "
        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call
        End Sub
        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents DefaultOption As System.Windows.Forms.RadioButton
        Friend WithEvents CursorOption As System.Windows.Forms.RadioButton
        Friend WithEvents LoadOption As System.Windows.Forms.RadioButton
        Friend WithEvents CursorGroup As System.Windows.Forms.GroupBox
        Friend WithEvents AnimatedOption As System.Windows.Forms.RadioButton
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.CursorGroup = New System.Windows.Forms.GroupBox
            Me.AnimatedOption = New System.Windows.Forms.RadioButton
            Me.LoadOption = New System.Windows.Forms.RadioButton
            Me.CursorOption = New System.Windows.Forms.RadioButton
            Me.DefaultOption = New System.Windows.Forms.RadioButton
            Me.CursorGroup.SuspendLayout()
            Me.SuspendLayout()
            '
            'CursorGroup
            '
            Me.CursorGroup.Controls.Add(Me.AnimatedOption)
            Me.CursorGroup.Controls.Add(Me.LoadOption)
            Me.CursorGroup.Controls.Add(Me.CursorOption)
            Me.CursorGroup.Controls.Add(Me.DefaultOption)
            Me.CursorGroup.Location = New System.Drawing.Point(24, 16)
            Me.CursorGroup.Name = "CursorGroup"
            Me.CursorGroup.Size = New System.Drawing.Size(232, 160)
            Me.CursorGroup.TabIndex = 0
            Me.CursorGroup.TabStop = False
            Me.CursorGroup.Text = "Cursor"
            '
            'AnimatedOption
            '
            Me.AnimatedOption.Location = New System.Drawing.Point(24, 120)
            Me.AnimatedOption.Name = "AnimatedOption"
            Me.AnimatedOption.Size = New System.Drawing.Size(160, 24)
            Me.AnimatedOption.TabIndex = 3
            Me.AnimatedOption.Text = "&Animated Cursor"
            '
            'LoadOption
            '
            Me.LoadOption.Location = New System.Drawing.Point(24, 88)
            Me.LoadOption.Name = "LoadOption"
            Me.LoadOption.Size = New System.Drawing.Size(160, 24)
            Me.LoadOption.TabIndex = 2
            Me.LoadOption.Text = "&Load Cursor"
            '
            'CursorOption
            '
            Me.CursorOption.Location = New System.Drawing.Point(24, 56)
            Me.CursorOption.Name = "CursorOption"
            Me.CursorOption.Size = New System.Drawing.Size(160, 24)
            Me.CursorOption.TabIndex = 1
            Me.CursorOption.Text = "&Cursor Object"
            '
            'DefaultOption
            '
            Me.DefaultOption.Checked = True
            Me.DefaultOption.Location = New System.Drawing.Point(24, 24)
            Me.DefaultOption.Name = "DefaultOption"
            Me.DefaultOption.Size = New System.Drawing.Size(160, 24)
            Me.DefaultOption.TabIndex = 0
            Me.DefaultOption.TabStop = True
            Me.DefaultOption.Text = "&Default"
            '
            'MainForm
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(376, 238)
            Me.Controls.Add(Me.CursorGroup)
            Me.Name = "MainForm"
            Me.Text = "Colored Cursors"
            Me.CursorGroup.ResumeLayout(False)
            Me.ResumeLayout(False)

        End Sub
#End Region
        Private Sub DefaultOption_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles DefaultOption.CheckedChanged
            Me.Cursor = Cursors.Default
        End Sub
        Private Sub CursorOption_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles CursorOption.CheckedChanged
            Dim filename As String

            If CursorOption.Checked Then
                Me.Cursor = Cursors.WaitCursor
                'causes an error
                'filename = Path.Combine(Application.StartupPath, cursorColored)
                'Me.Cursor = New Cursor(filename)
            End If
        End Sub
        Private Sub LoadOption_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles LoadOption.CheckedChanged
            Dim filename As String

            If LoadOption.Checked Then
                filename = Path.Combine(Application.StartupPath, cursorColored)
                Me.Cursor = CursorFactory.Create(filename)
            End If
        End Sub
        Private Sub AnimatedOption_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles AnimatedOption.CheckedChanged
            Dim filename As String

            If AnimatedOption.Checked Then
                filename = Path.Combine(Application.StartupPath, cursorAnimated)
                Me.Cursor = CursorFactory.Create(filename)
            End If
        End Sub
    End Class
End Namespace
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:planocz
ID: 10959071
If you look at C:\WINDOWS\Cursors on your computer you will find a good selection..
0
 

Author Comment

by:dekeyzer
ID: 10959156
The problem is that we want to design our cursor in runtime as a result of what the user draws. He can really draw ANYTHING!  So even with a million cur-files in the  C:\WINDOWS\Cursors-folder, we don't have enough.

Thanks!

0
 
LVL 27

Assisted Solution

by:planocz
planocz earned 600 total points
ID: 10959338
Here is a link you might want to look at...
Iam still searching for you..

http://www.webtropy.com/articles/art9-1.asp?f=CreateCursor
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10959676
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Resources/Cursors/UsingCursors.asp

This Microsoft sample contains code which can create cursor from bitmap. You can create managed Bitmap object, get HBITMAP from it, convert HBITMAP to HCURSOR using Win32 code from this sample, and create Cursor from HCURSOR using constructor Public Sub New(IntPtr).

0
 
LVL 48

Accepted Solution

by:
AlexFM earned 900 total points
ID: 10959700
0
 

Author Comment

by:dekeyzer
ID: 10995962
Hi,

I found the solution, thanks for your help !
        Dim img As Bitmap
        Dim fr_bm As New Bitmap(100, 100)
        Dim wc As New System.Net.WebClient
        Dim gr As Graphics = Graphics.FromImage(fr_bm)
        gr.Clear(System.Drawing.Color.Empty)
        gr.draw.... (everthing you want)
        fr_bm.Save("c:\test.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
        img = New Bitmap(wc.OpenRead("c:\test.bmp"))
        Me.Cursor = New Cursor(img.GetHicon)
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10996051
Very nice. Bitmap.GetHicon Method - this is a bridge betweenBbitmap and Cursor. You may replace also file with MemoryStream if you want.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question