Any C developers able to convert this code to vb.net?

  • Thread starter Thread starter Luke R
  • Start date Start date
L

Luke R

It would be much appreciated... Im not familiar enough with C in order to
convert it myself...
thanks

using System;
using System.Windows.Forms;

public class HourGlass : IDisposable {
public HourGlass() {
Enabled = true;
}
public void Dispose() {
Enabled = false;
}
public static bool Enabled {
get { return Application.UseWaitCursor; }
set {
if (value == Application.UseWaitCursor) return;
Application.UseWaitCursor = value;
Form f = Form.ActiveForm;
if (f != null && f.Handle != null) // Send WM_SETCURSOR
SendMessage(f.Handle, 0x20, f.Handle, (IntPtr)1);
}
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp,
IntPtr lp);
}

You can use it either directly by assigning HourGlass.Enabled or like this:

private void button1_Click(object sender, EventArgs e) {
using (new HourGlass()) {
// Do something that takes time...
System.Threading.Thread.Sleep(2000);
}
}
 
It's actually C#.
The conversion is (via Instant VB):

Imports System
Imports System.Windows.Forms

Public Class HourGlass
Implements IDisposable
Public Sub New()
Enabled = True
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
Enabled = False
End Sub
Public Shared Property Enabled() As Boolean
Get
Return Application.UseWaitCursor
End Get
Set(ByVal value As Boolean)
If value = Application.UseWaitCursor Then
Return
End If
Application.UseWaitCursor = value
Dim f As Form = Form.ActiveForm
If Not f Is Nothing AndAlso Not f.Handle Is Nothing Then ' Send
WM_SETCURSOR
SendMessage(f.Handle, &H20, f.Handle, CType(1, IntPtr))
End If
End Set
End Property
<System.Runtime.InteropServices.DllImport("user32.dll")> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As
Integer, ByVal wp As IntPtr, ByVal lp As IntPtr) As IntPtr
End Function
End Class

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Using TempHourGlass As HourGlass = New HourGlass()
' Do something that takes time...
System.Threading.Thread.Sleep(2000)
End Using
End Sub

--
David Anton
www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Python
Instant C#
Instant VB
Instant C++
Instant Python
C++ to C# Converter
C++ to VB Converter
 
Awesome thanks for that.

David Anton said:
It's actually C#.
The conversion is (via Instant VB):

Imports System
Imports System.Windows.Forms

Public Class HourGlass
Implements IDisposable
Public Sub New()
Enabled = True
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
Enabled = False
End Sub
Public Shared Property Enabled() As Boolean
Get
Return Application.UseWaitCursor
End Get
Set(ByVal value As Boolean)
If value = Application.UseWaitCursor Then
Return
End If
Application.UseWaitCursor = value
Dim f As Form = Form.ActiveForm
If Not f Is Nothing AndAlso Not f.Handle Is Nothing Then ' Send
WM_SETCURSOR
SendMessage(f.Handle, &H20, f.Handle, CType(1, IntPtr))
End If
End Set
End Property
<System.Runtime.InteropServices.DllImport("user32.dll")> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As
Integer, ByVal wp As IntPtr, ByVal lp As IntPtr) As IntPtr
End Function
End Class

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Using TempHourGlass As HourGlass = New HourGlass()
' Do something that takes time...
System.Threading.Thread.Sleep(2000)
End Using
End Sub

--
David Anton
www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Python
Instant C#
Instant VB
Instant C++
Instant Python
C++ to C# Converter
C++ to VB Converter


Luke R said:
It would be much appreciated... Im not familiar enough with C in order to
convert it myself...
thanks

using System;
using System.Windows.Forms;

public class HourGlass : IDisposable {
public HourGlass() {
Enabled = true;
}
public void Dispose() {
Enabled = false;
}
public static bool Enabled {
get { return Application.UseWaitCursor; }
set {
if (value == Application.UseWaitCursor) return;
Application.UseWaitCursor = value;
Form f = Form.ActiveForm;
if (f != null && f.Handle != null) // Send WM_SETCURSOR
SendMessage(f.Handle, 0x20, f.Handle, (IntPtr)1);
}
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr
wp,
IntPtr lp);
}

You can use it either directly by assigning HourGlass.Enabled or like
this:

private void button1_Click(object sender, EventArgs e) {
using (new HourGlass()) {
// Do something that takes time...
System.Threading.Thread.Sleep(2000);
}
}
 
Back
Top