Drag Bitmap tutorial/code anywhere?

R

Robinson

Hi,

Can anyone point me towards a good drag/drop tutorial that allows me to
create/render my own drag-cursor (i.e. for instance, if I wish to drag a
list item, I can render the list item at the cursor location as the user
drags it around the screen). Has anyone successfully done this in VB.NET?
How does it perform? Any pitfalls?

Thanks,



Robin
 
P

Peter Proost

Hi this sample shows how to create a cutsom cursor, haven't tested it with
dragging and dropping.

Dim myCur As Cursor()
Dim g As Graphics
Dim cur As Cursor

g = TextBox1.CreateGraphics
Dim myBmp As New Bitmap(CInt(g.MeasureString(TextBox1.Text,
TextBox1.Font).Width), 20)
g = Graphics.FromImage(myBmp)
g.Clear(Color.Red)
g.DrawString(TextBox1.Text, TextBox1.Font, Brushes.White, 2, 2)
g.Dispose()
Dim ptrCur As IntPtr = myBmp.GetHicon
cur = New Cursor(ptrCur)
Cursor.Current = cur

hope this helps,

Greetz, Peter
 
R

Robinson

Peter Proost said:
Hi this sample shows how to create a cutsom cursor, haven't tested it with
dragging and dropping.

Dim myCur As Cursor()
Dim g As Graphics
Dim cur As Cursor

g = TextBox1.CreateGraphics
Dim myBmp As New Bitmap(CInt(g.MeasureString(TextBox1.Text,
TextBox1.Font).Width), 20)
g = Graphics.FromImage(myBmp)
g.Clear(Color.Red)
g.DrawString(TextBox1.Text, TextBox1.Font, Brushes.White, 2, 2)
g.Dispose()
Dim ptrCur As IntPtr = myBmp.GetHicon
cur = New Cursor(ptrCur)
Cursor.Current = cur

hope this helps,

Greetz, Peter
--

Thanks for that Peter. I also found some samples like this one:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=3855&lngWId=10.
I'm going to give it a try this afternoon.



Robin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top