Solved

How to generate a cursor for a mousepointer in runtime

Posted on 2004-04-30
10
343 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

12 Experts available now in Live!

Get 1:1 Help Now