[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to generate a cursor for a mousepointer in runtime

Posted on 2004-04-30
10
Medium Priority
?
354 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

656 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