Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

code conversion from C# to VB.NET

Status
Not open for further replies.

kulfanumber

Programmer
Jun 24, 2009
21
PK
I need to convert this code frm C# to VB 2005
[DllImport( "user32", CharSet = CharSet.Auto )]
private static extern int SendMessage( HandleRef hWnd,
int msg,
int wParam,
int lParam );
 
Code:
Imports System.Runtime.InteropServices

<DllImport("user32", CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As HandleRef, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
   ' code
End Function
 
Thnx alot. I hav one more problem in code conversion. I hav to convert this code too
SendMessage( new HandleRef( this, Handle ),
EM_GETPARAFORMAT,
SCF_SELECTION, ref fmt );
 
Code:
SendMessage(New HandleRef(Me, Handle), EM_GETPARAFORMAT, SCF_SELECTION, fmt)
 
I hav used this but when i run my program it gives accessviolationexception at this line
 
The code which i hav written is below

Imports System
Imports System.Windows.Forms
Imports System.Runtime.InteropServices

<Serializable()> _
Public Class RichTextBoxEx
Inherits RichTextBox

Enum TextAlign
Left = 1
Right = 2
Center = 3
Justify = 4
End Enum

<DllImport("user32", CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As HandleRef, _
ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function

<DllImport("user32", CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As HandleRef, _
ByVal msg As Integer, ByVal wParam As Integer, ByVal lp As PARAFORMAT) As Integer
End Function


<StructLayout(LayoutKind.Sequential)> _
Private Structure PARAFORMAT
Public cbSize As Integer
Public dwMask As UInteger
Public wNumbering As Short
Public wReserved As Short
Public dxStartIndent As Integer
Public dxRightIndent As Integer
Public dxOffset As Integer
Public wAlignment As Short
Public cTabCount As Short
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=32)> _
Public rgxTabs() As Integer

' PARAFORMAT2 from here onwards.
Public dySpaceBefore As Int32
Public dySpaceAfter As Int32
Public dyLineSpacing As Int32
Public sStyle As Short
Public bLineSpacingRule As Byte
Public bOutlineLevel As Byte
Public wShadingWeight As Short
Public wShadingStyle As Short
Public wNumberingStart As Short
Public wNumberingStyle As Short
Public wNumberingTab As Short
Public wBorderSpace As Short
Public wBorderWidth As Short
Public wBorders As Short
End Structure

Private updating As Int32 = 0
Private oldEventMask As Int32 = 0

'Constants from the Platform SDK.
Private Const EM_SETEVENTMASK As Integer = 1073
Private Const EM_GETPARAFORMAT As Integer = 1085
Private Const EM_SETPARAFORMAT As Integer = 1095
Private Const EM_SETTYPOGRAPHYOPTIONS As Integer = 1226
Private Const WM_SETREDRAW As Integer = 11
Private Const TO_ADVANCEDTYPOGRAPHY As Integer = 1
Private Const PFM_ALIGNMENT As Integer = 8
Private Const SCF_SELECTION As Integer = 1

Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)

MyBase.OnHandleCreated(e)

'Enable support for justification.
SendMessage(New HandleRef(Me, Handle), _
EM_SETTYPOGRAPHYOPTIONS, _
TO_ADVANCEDTYPOGRAPHY, _
TO_ADVANCEDTYPOGRAPHY)
End Sub

Public Overloads Property SelectionAlignment() As TextAlign

Get

Dim fmt As PARAFORMAT = New PARAFORMAT()
fmt.cbSize = Marshal.SizeOf(fmt)

' Get the alignment.
SendMessage(New HandleRef(Me, Handle), _
EM_GETPARAFORMAT, _
SCF_SELECTION, fmt)

' Default to Left align.
If ((fmt.dwMask & PFM_ALIGNMENT) = 0) Then
Return TextAlign.Left
End If
If fmt.wAlignment = 1 Then
Return TextAlign.Left
ElseIf fmt.wAlignment = 2 Then
Return TextAlign.Right
ElseIf fmt.wAlignment = 3 Then
Return TextAlign.Center
ElseIf fmt.wAlignment Then
Return TextAlign.Justify
End If
End Get
Set(ByVal value As TextAlign)

Dim fmt As PARAFORMAT = New PARAFORMAT()
fmt.cbSize = Marshal.SizeOf(fmt)
fmt.dwMask = PFM_ALIGNMENT
fmt.wAlignment = CShort(value)

' Set the alignment.
SendMessage(New HandleRef(Me, Handle), _
EM_SETPARAFORMAT, _
SCF_SELECTION, fmt)
End Set
End Property
End Class

I hav shifted it from C# and it was working fine in C#
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top