Solved

How to generate a cursor for a mousepointer in runtime

Posted on 2004-04-30
10
347 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 27

Assisted Solution

by:planocz
planocz earned 200 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 300 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now