Click here to Skip to main content
15,884,177 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Outlook Addin Instance Creation problem... Pin
dcdhingra21-Jul-09 5:03
dcdhingra21-Jul-09 5:03 
GeneralRe: Outlook Addin Instance Creation problem... Pin
Jay Royall21-Jul-09 5:23
Jay Royall21-Jul-09 5:23 
GeneralRe: Outlook Addin Instance Creation problem... Pin
dcdhingra21-Jul-09 5:32
dcdhingra21-Jul-09 5:32 
GeneralRe: Outlook Addin Instance Creation problem... Pin
dcdhingra23-Jul-09 20:45
dcdhingra23-Jul-09 20:45 
Questionhow to convert ascii to hexa using vb? Pin
jellybeansss20-Jul-09 23:59
jellybeansss20-Jul-09 23:59 
AnswerRe: how to convert ascii to hexa using vb? Pin
Luc Pattyn21-Jul-09 2:22
sitebuilderLuc Pattyn21-Jul-09 2:22 
AnswerRe: how to convert ascii to hexa using vb? Pin
Gideon Engelberth21-Jul-09 3:24
Gideon Engelberth21-Jul-09 3:24 
Questioncode conversion Pin
MA Awan20-Jul-09 23:55
MA Awan20-Jul-09 23:55 
I’ve converted code for text justification from C# to VB Express 2005

C# version:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
public class AdvRichTextBox : RichTextBox
{ public new TextAlign SelectionAlignment
    {
        get
        {
            PARAFORMAT fmt = new PARAFORMAT();
            fmt.cbSize = Marshal.SizeOf( fmt );
            
            // Get the alignment.
            SendMessage( new HandleRef( this, Handle ),
                         EM_GETPARAFORMAT,
                         SCF_SELECTION, ref fmt );
            
            // Default to Left align.
            if ( ( fmt.dwMask & PFM_ALIGNMENT ) == 0 )
                return TextAlign.Left;
            
            return ( TextAlign )fmt.wAlignment;
        }
        
        set
        {
            PARAFORMAT fmt = new PARAFORMAT();
            fmt.cbSize = Marshal.SizeOf( fmt );
            fmt.dwMask = PFM_ALIGNMENT;
            fmt.wAlignment = ( short )value;
            
            // Set the alignment.
            SendMessage( new HandleRef( this, Handle ),
                         EM_SETPARAFORMAT,
                         SCF_SELECTION, ref fmt );
        }
    }
    
    /// <summary>
    /// This member overrides
    /// <see cref="Control"/>.OnHandleCreated.
    /// </summary>
    protected override void OnHandleCreated( EventArgs e )
    {
        base.OnHandleCreated( e );
        
        // Enable support for justification.
        SendMessage( new HandleRef( this, Handle ),
                     EM_SETTYPOGRAPHYOPTIONS,
                     TO_ADVANCEDTYPOGRAPHY,
                     TO_ADVANCEDTYPOGRAPHY );
    }
    
    private int updating = 0;
    private int oldEventMask = 0;
    
    // Constants from the Platform SDK.
    private const int EM_SETEVENTMASK = 1073;
    private const int EM_GETPARAFORMAT = 1085;
    private const int EM_SETPARAFORMAT = 1095;
    private const int EM_SETTYPOGRAPHYOPTIONS = 1226;
    private const int WM_SETREDRAW = 11;
    private const int TO_ADVANCEDTYPOGRAPHY = 1;
    private const int PFM_ALIGNMENT = 8;
    private const int SCF_SELECTION = 1;
    
    // It makes no difference if we use PARAFORMAT or
    // PARAFORMAT2 here, so I have opted for PARAFORMAT2.
    [StructLayout( LayoutKind.Sequential )]
    private struct PARAFORMAT
    {
        public int cbSize;
        public uint dwMask;
        public short wNumbering;
        public short wReserved;
        public int dxStartIndent;
        public int dxRightIndent;
        public int dxOffset;
        public short wAlignment;
        public short cTabCount;
        [MarshalAs( UnmanagedType.ByValArray, SizeConst = 32 )]
        public int[] rgxTabs;
        
        // PARAFORMAT2 from here onwards.
        public int dySpaceBefore;
        public int dySpaceAfter;
        public int dyLineSpacing;
        public short sStyle;
        public byte bLineSpacingRule;
        public byte bOutlineLevel;
        public short wShadingWeight;
        public short wShadingStyle;
        public short wNumberingStart;
        public short wNumberingStyle;
        public short wNumberingTab;
        public short wBorderSpace;
        public short wBorderWidth;
        public short wBorders;
    }
    
    [DllImport( "user32", CharSet = CharSet.Auto )]
    private static extern int SendMessage( HandleRef hWnd,
                                           int msg,
                                           int wParam,
                                           int lParam );
    
    [DllImport( "user32", CharSet = CharSet.Auto )]
    private static extern int SendMessage( HandleRef hWnd,
                                           int msg,
                                           int wParam,
                                           ref PARAFORMAT lp );
}

/// <summary>
/// Specifies how text in a <see cref="AdvRichTextBox"/> is
/// horizontally aligned.
/// </summary>
public enum TextAlign
{
    /// <summary>
    /// The text is aligned to the left.
    /// </summary>
    Left = 1,
    
    /// <summary>
    /// The text is aligned to the right.
    /// </summary>
    Right = 2,
    
    /// <summary>
    /// The text is aligned in the center.
    /// </summary>
    Center = 3,
    
    /// <summary>
    /// The text is justified.
    /// </summary>
    Justify = 4
}

}


VB Version
Imports System
Imports System.Windows.Forms
Imports System.Runtime.InteropServices


'<Designer("System.Windows.Forms.Design.ParentControlDesigner, SystemDesign", GetType(IDesigner))> _

<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


It was working in C# but in vb it gives error that “AccessViolationException was unhandled” at the following line
SendMessage(New HandleRef(Me, Handle), _
EM_SETPARAFORMAT, _
SCF_SELECTION, fmt)

Plz can anyone tell me what's the problem
AnswerRe: code conversion Pin
0x3c021-Jul-09 0:12
0x3c021-Jul-09 0:12 
GeneralRe: code conversion Pin
Gideon Engelberth21-Jul-09 3:29
Gideon Engelberth21-Jul-09 3:29 
GeneralRe: code conversion Pin
MA Awan21-Jul-09 16:55
MA Awan21-Jul-09 16:55 
GeneralRe: code conversion Pin
MA Awan21-Jul-09 18:39
MA Awan21-Jul-09 18:39 
Questionhow to insert Apostrophe or Single Quote key access DB through dynamic string? Pin
JC.KaNNaN20-Jul-09 20:58
JC.KaNNaN20-Jul-09 20:58 
AnswerRe: how to insert Apostrophe or Single Quote key access DB through dynamic string? Pin
Christian Graus20-Jul-09 21:55
protectorChristian Graus20-Jul-09 21:55 
QuestionSending SMS Through VB 6 Pin
jayachandra.c20-Jul-09 20:47
jayachandra.c20-Jul-09 20:47 
AnswerRe: Sending SMS Through VB 6 Pin
Christian Graus20-Jul-09 21:54
protectorChristian Graus20-Jul-09 21:54 
QuestionCould not Focus Cell In DataGridView Pin
rhtbhegade20-Jul-09 20:38
rhtbhegade20-Jul-09 20:38 
AnswerRe: Uppercase in datagridview cell Pin
Sreyas M N12-Nov-09 18:49
Sreyas M N12-Nov-09 18:49 
AnswerRe: Could not Focus Cell In DataGridView Pin
Sreyas M N12-Nov-09 19:17
Sreyas M N12-Nov-09 19:17 
QuestionImporting CSV files without header Pin
Astitva2320-Jul-09 12:37
Astitva2320-Jul-09 12:37 
QuestionDifference between Scripting.Drive and DriveInfo: One works to detect external usb device, one doesn't Pin
babybass20-Jul-09 8:15
babybass20-Jul-09 8:15 
AnswerRe: Difference between Scripting.Drive and DriveInfo: One works to detect external usb device, one doesn't Pin
Alan N20-Jul-09 9:55
Alan N20-Jul-09 9:55 
GeneralRe: Difference between Scripting.Drive and DriveInfo: One works to detect external usb device, one doesn't Pin
babybass20-Jul-09 10:57
babybass20-Jul-09 10:57 
QuestionTriplesDES error Pin
TheMrProgrammer20-Jul-09 7:10
TheMrProgrammer20-Jul-09 7:10 
AnswerRe: TriplesDES error Pin
Luc Pattyn20-Jul-09 7:54
sitebuilderLuc Pattyn20-Jul-09 7:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.