一般討論 Forums Code Formatter

  • Saturday, January 09, 2010 10:39 PM
     
     

    The follow code will format Visual Studio code for presentation in these forums.  Start a new Windows Forms Application and replace the code on Form1 with the code posted here.  The code should post as it is shown here.  Press "F5".  Copy some code from the IDE to the clipboard.  Press the "Paste RTF" button on the form and then the "Copy HTML" button.  Start a thread in the Sandbox forum and paste the code in the Body of the post.

    This is an initial stab at a formatter, which I feel is needed.  I can't decipher most posts containing code.  Any help improving this is welcome.

All Replies

  • Saturday, January 09, 2010 10:56 PM
     
     
    Must be version 0.9.  For instance:

    SW.Write(""Color: " + Clrtbl(I) + ";" + Chr(34) + ">")

    (WriteColor sub)

  • Saturday, January 09, 2010 11:15 PM
     
     
    Imports System.IO
    Imports System.Text
    Public Class Form1
      
    Dim MS As New MenuStrip
      
    Dim WithEvents PasteRTF As New ToolStripButton
      
    Dim WithEvents CopyHTML As New ToolStripButton
      
    Dim RTB As New RichTextBox
      
    Dim DataFile As String = Application.StartupPath + "\Data.txt"
      Private Sub Form1_Load(ByVal sender As ObjectByVal e As EventArgs) Handles Me.Load
        
    If File.Exists(DataFile) Then
          Dim Data() As String = File.ReadAllText(DataFile).Split(","c)
          
    Me.Left = Integer.Parse(Data(0).Substring(3, Data(0).Length - 3))
          
    Me.Top = Integer.Parse(Data(1).Substring(2, Data(1).Length - 2))
          
    Me.Width = 434
          
    Me.Width = Integer.Parse(Data(2).Substring(6, Data(2).Length - 6))
          
    Me.Height = Integer.Parse(Data(3).Substring(7, Data(3).Length - 8))
        
    End If
        Me.Text = "MSDN forums code formatter by johnwein"
        PasteRTF.Text = "Paste RTF"
        CopyHTML.Text = "Copy HTML"
        MS.Items.Add(PasteRTF)
        MS.Items.Add(CopyHTML)
        MS.Parent = 
    Me
        RTB.Parent = Me
        RTB.Dock = DockStyle.Fill
        RTB.BringToFront()
      
    End Sub
      Private Sub PasteRTF_Click(ByVal sender As ObjectByVal e As EventArgs) Handles PasteRTF.Click
        RTB.Clear()
        RTB.Paste(DataFormats.GetFormat(DataFormats.Rtf))
      
    End Sub
      Private Sub CopyHTML_Click(ByVal sender As ObjectByVal e As EventArgs) Handles CopyHTML.Click
        Clipboard.Clear()
        
    Dim Conv As New RtfToHtml
        Clipboard.SetData(DataFormats.Html, Conv.RtfToHtml(RTB.Rtf))
      
    End Sub
      Private Sub Form1_FormClosing(ByVal sender As ObjectByVal e As FormClosingEventArgs) Handles Me.FormClosing
        File.WriteAllText(DataFile, 
    Me.Bounds.ToString)
      
    End Sub
    End
     Class

    Public
     Class RtfToHtml
      
    Dim SR As StringReader
      
    Dim SW As StringWriter
      
    Dim Clrtbl As List(Of String)
      
    Function RtfToHtml(ByVal RtfIn As StringAs String
        SR = New StringReader(RtfIn)
        SW = 
    New StringWriter()
        
    Dim S As String = GetColorTable()
        SW.Write(
    "<span style=" + Chr(34) + "font-family: Courier new; font-size: x-medium" + Chr(34) + "><span>")
        
    Do
          WriteLine(S)
          S = SR.ReadLine
        
    Loop Until S Is Nothing
        SW.Write("</span>")
        
    Return SW.ToString
      
    End Function
      Sub WriteLine(ByVal S As String)
        
    Dim I, J As Integer
        If S(0) = "}" And S.Length = 1 Then Return
        For I = 0 To S.Length - 1
          
    Select Case S(I)
            
    Case "\"c
              Select Case S(I + 1)
                
    Case "{"c"}"c"\"c
                  I += 1
                  SW.Write(S(I))
                  
    Continue For
                Case Else
                  I += 1
                  
    For J = I To S.Length - 1
                    
    If S(J) = " " Or S(J) = "\" Then Exit For
                  Next
                  If S.Substring(I, 2) = "cf" Then WriteColor(S(I + 2))
                  I = 
    If(J < S.Length, If(S(J) = " ", J, J - 1), J)
              
    End Select
            Case "<"c
              SW.Write("&lt;")
            
    Case ">"c
              SW.Write("&gt;")
            
    Case "&"c
              SW.Write("&amp;")
            
    Case " "c
              SW.Write("&nbsp;")
            
    Case Else
              SW.Write(S(I))
          
    End Select
        Next
        SW.Write("<br>" + Environment.NewLine)
      
    End Sub
      Sub WriteColor(ByVal C As Char)
        
    Dim I As Integer
        I = Integer.Parse(C) - 1
        
    If I < 0 Then
          SW.Write("</span><span>")
        
    Else
          SW.Write("</span><span style=" + Chr(34) + "Color: " + Clrtbl(I) + ";" + Chr(34) + ">")
        
    End If
      End Sub
      Function GetColorTable() As String
        Dim I, J As Integer, C, S, S1(), S2() As String
        Clrtbl = New List(Of String)
        
    Do
          S = SR.ReadLine
          
    If S Is Nothing Then Return S
          I = S.IndexOf(
    "{\colortbl")
          
    If I >= 0 Then Exit Do
          I = S.IndexOf("\pard")
          
    If I > 0 Then Return S.Substring(I + 5)
        
    Loop
        S1 = S.Substring(I, S.IndexOf("}"c) - I).Split(";"c)
        
    Dim Clrs() As Integer = {3, 5, 4} 'Length of the colors
        For I = 1 To S1.Length - 2
          S2 = S1(I).Split(
    "\"c)
          C = 
    "#"
          For J = 1 To 3
            C += Hex(
    Integer.Parse(S2(J).Substring(Clrs(J - 1)))).PadLeft(2, "0"c)
          
    Next
          Clrtbl.Add(C)
        
    Next
        Do
          I = S.IndexOf("\pard")
          
    If I > 0 Then Return S.Substring(I + 5)
          S = SR.ReadLine
        
    Loop Until S Is Nothing
        Return S
      
    End Function
    End
     Class

    version 0.2.1

    I should have spent more time in the Sandbox.  I couldn't edit the original code.  Got problems with HTML tags in RTF.  This code should be able to be copied, pasted, compiled and run without errors. I didn't need the posts pointing out the errors in the original code.  If I can delete it I will.
  • Sunday, January 10, 2010 2:07 AM
     
     
    Hi JohnWein,

    What is wrong with using the   button?

    Then selecting Vb.Net from the above ComboBox in the Insert Code window, then select preview if you wish then click on UPDATE.

    Code is inserted where the " | " is when you are editing or adding a post.


    Regards,

    John
  • Sunday, January 10, 2010 2:16 AM
     
     
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
            
    If File.Exists(DataFile) Then
                Dim Data() As String = File.ReadAllText(DataFile).Split(","c)
                
    Me.Left = Integer.Parse(Data(0).Substring(3, Data(0).Length - 3))
                
    Me.Top = Integer.Parse(Data(1).Substring(2, Data(1).Length - 2))
                
    Me.Width = 434
                
    Me.Width = Integer.Parse(Data(2).Substring(6, Data(2).Length - 6))
                
    Me.Height = Integer.Parse(Data(3).Substring(7, Data(3).Length - 8))
            
    End If
            Me.Text = "MSDN forums code formatter by johnwein"
            PasteRTF.Text = "Paste RTF"
            CopyHTML.Text = "Copy HTML"
            MS.Items.Add(PasteRTF)
            MS.Items.Add(CopyHTML)
            MS.Parent =
    Me
            RTB.Parent = Me
            RTB.Dock = DockStyle.Fill
            RTB.BringToFront()
        
    End Sub

    coding for fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
  • Sunday, January 10, 2010 2:17 AM
     
     
    That was a test sorry no sandbox
    coding for fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
  • Sunday, January 10, 2010 2:26 AM
     
     
    I loved the good old look of the code block with alternate row color, like here: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/885d965b-e7a6-4d60-a7a9-0650a22bd857/
    Listing SPEC's is not a review !!! :-)
  • Sunday, January 10, 2010 2:36 AM
     
     
    Well the editor from the  button is ok but the font is too big the old editor had som formatting options didn't it ?
    coding for fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
  • Sunday, January 10, 2010 10:09 AM
     
     
    Found a bug with xaml code sort of I guess . First the standard editor xml formatted .

    Yes.  The code I posted doesn't handle HTML tags.  Would you like to add this feature?
  • Sunday, January 10, 2010 12:45 PM
     
      Has Code
    With code tags
        'In the form designer set form WindowState to minimized.  <<<<<<<<<<<<<<<<<
        Private Sub Form1_Load(ByVal sender As System.Object, _
                               ByVal e As System.EventArgs) Handles MyBase.Load
            If My.Application.CommandLineArgs.Count = 1 AndAlso _
                My.Application.CommandLineArgs(0) = "-startintray" Then
                'Me.Hide()
                'or
                Me.Visible = False
            Else
                Me.WindowState = FormWindowState.Maximized
            End If
        End Sub
    

    Without


        'In the form designer set form WindowState to minimized.  <<<<<<<<<<<<<<<<<
        Private Sub Form1_Load(ByVal sender As System.Object, _
                               ByVal e As System.EventArgs) Handles MyBase.Load
            If My.Application.CommandLineArgs.Count = 1 AndAlso _
                My.Application.CommandLineArgs(0) = "-startintray" Then
                'Me.Hide()
                'or
                Me.Visible = False
            Else
                Me.WindowState = FormWindowState.Maximized
            End If
        End Sub


    Looking for work - Zip 65101 http://www.vbforums.com/showthread.php?t=552774
  • Sunday, January 10, 2010 11:09 PM
     
     
    I replaced the code with a new version (0.1.2) with an attempt to handle HTML codes.  I pasted it, copied it to VB IDE and ran it without error.
  • Sunday, January 10, 2010 11:52 PM
     
     
    Seems to work for my xaml test I just did good work John .
    coding for fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
  • Sunday, January 10, 2010 11:52 PM
     
     
    I applaud your efforts, but for now I'll probably just paste in the main window without tags. 

    Looking for work - Zip 65101 http://www.vbforums.com/showthread.php?t=552774
  • Wednesday, January 13, 2010 2:43 AM
     
     
    Just wanted to bump this topic John's formatter is cool I use it to post in the forums .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
  • Friday, January 15, 2010 8:38 AM
     
     
    'Visual Basic 2008 - .net 2.0 - Any CPU
    #Region "The RtfToHTML class by johnwein "

    Public Class RtfToHtml
        
    Private SR As StringReader
        
    Private SW As StringWriter
        
    Private Clrtbl As List(Of String)
        
    ' Added:
        ' Public Shared Property CommentStarter() As String 
        '     -> get/set how a comment is startet for desired language ( ' or // )
        ' Public Shared Property HasCode() As Boolean
        '     -> true: the code will be copied using UnicodeText
        '     -> false: the code will be copied using RichTextFormat
        ' Public Shared Property CodeTag() As String
        '     -> Values accepted: "x-vbnet","x-c#","x-cpp" or ""
        '     -> if Value="" the pre tag will be added
        '     -> otherwise pre lang="x-vbnet" tag will be added
        ' Public Shared Property Comment() As String
        '     -> For the adding of a desired comment 
        '        (for the addin Language - framework - platform)
        ' Public Shared Property FontSize() As String
        '     -> Fontsize to use in html stile like: "x-medium" ..
        ' Friend Function RtfToHtml(ByVal RtfIn As String, ByVal TheFontsize As String) As String
        '     -> will be called if HasCode=False
        ' Friend Function TxtToHtml(ByVal txtIn As String, ByVal TheFontsize As String) As String
        '     -> will be called if HasCode=True
        ' Private Sub WriteColor(ByVal C As String) <- more colors can be handled
        '     -> more colors can be handled
        '
        ' Obsolete:
        ' Private Sub WriteColor(ByVal C As Char)
        ' New Vars
        Private Const FONTSIZESTRING As String = "; font-size:"
        Private Shared _Fontsize As String = "x-medium"
        Private Shared _HasCode As Boolean = False
        Private Shared _Comment As String = String.Empty
        
    Private Shared _CodeTag As String = String.Empty
        
    Private Shared _CommentStarter As String = "'"
        Public Shared Property CommentStarter() As String
            Get
                Return _CommentStarter
            
    End Get
            Set(ByVal value As String)
                _CommentStarter = value
            
    End Set
        End Property

        Public Shared Property CodeTag() As String
            Get
                Return _CodeTag
            
    End Get
            Set(ByVal value As String)
                
    Select Case value
                    
    Case "x-vbnet"
                        _CodeTag = value
                    
    Case "x-c#"
                        _CodeTag = value
                    
    Case "x-cpp"
                        _CodeTag = value
                    
    Case Else
                        _CodeTag = String.Empty
                
    End Select
            End Set
        End Property
        Public Shared Property HasCode() As Boolean
            Get
                Return _HasCode
            
    End Get
            Set(ByVal value As Boolean)
                _HasCode = value
            
    End Set
        End Property
        Public Shared Property Comment() As String
            Get
                Return _Comment
            
    End Get
            Set(ByVal value As String)
                _Comment = value
            
    End Set
        End Property
        Public Shared Property FontSize() As String
            Get
                Return _Fontsize
            
    End Get
            Set(ByVal value As String)
                _Fontsize = value
            
    End Set
        End Property
        Friend Function RtfToHtml(ByVal TextIn As StringAs String
            Dim ReturnValue As String = String.Empty
            
    If _HasCode Then
                ReturnValue = TxtToHtml(TextIn, _Fontsize)
            
    Else
                ReturnValue = RtfToHtml(TextIn, _Fontsize)
            
    End If
            Return ReturnValue
        
    End Function
        Friend Function TxtToHtml(ByVal txtIn As StringByVal TheFontsize As StringAs String
            SR = New StringReader(txtIn)
            SW = 
    New StringWriter()
            
    Dim S As String = SR.ReadLine
            SW.Write(
    "<br><span style=" & Chr(34) & "line-height:100%;font-family: Courier new")
            SW.Write(FONTSIZESTRING & TheFontsize & Chr(34) & 
    ">")

            
    If String.IsNullOrEmpty(_CodeTag) OrElse _CodeTag.Length = 0 Then
                SW.Write("<pre>")
            
    Else
                SW.Write("<pre lang=" & Chr(34) & _CodeTag & Chr(34) & ">")
            
    End If
            If Not String.IsNullOrEmpty(_Comment) Then
                SW.Write(_CommentStarter & _Comment & Environment.NewLine)
            
    End If
            SW.Write(txtIn)
            SW.Write(
    "</pre></span><br>")
            
    'My.Computer.FileSystem.WriteAllText("C:\test.html", SW.ToString, False)

            Return SW.ToString
        
    End Function
        Friend Function RtfToHtml(ByVal RtfIn As StringByVal TheFontsize As StringAs String
            RtfIn = RtfIn.Substring(1, RtfIn.Length - 2)
            SR = 
    New StringReader(RtfIn)
            SW = 
    New StringWriter()
            
    Dim S As String = GetColorTable()
            SW.Write(
    "<span style=" & Chr(34) & "line-height:100%;font-family: Courier new")
            SW.Write(FONTSIZESTRING & TheFontsize & Chr(34) & 
    ">")
            
    If Not String.IsNullOrEmpty(_Comment) Then
                SW.Write("<span style=" & Chr(34) & "Color: #008000;" & Chr(34) & ">" & _CommentStarter & _Comment & "</span><br><span>")
            
    End If
            Do
                WriteLine(S)
                S = SR.ReadLine
            
    Loop Until S Is Nothing
            SW.Write("</span></span><br>")
            
    'My.Computer.FileSystem.WriteAllText("C:\test.html", SW.ToString, False)
            Return SW.ToString
        
    End Function
        Sub WriteLine(ByVal S As String)
            
    Dim I, J As Integer
            If S(0) = "}" And S.Length = 1 Then Return
            For I = 0 To S.Length - 1
                
    Select Case S(I)
                    
    Case "\"c
                        Select Case S(I + 1)
                            
    Case "{"c"}"c"\"c
                                I += 1
                                SW.Write(S(I))
                                
    Continue For
                            Case "u"c ' VS 2008 IDE Unicode
                                I += 2
                                
    For J = I To S.Length - 1
                                    
    If S(J) = " " Then Exit For
                                Next
                                SW.Write("&#" & S.Substring(I, J - I) & ";")
                                I = J + 1
                            
    Case "'"c ' VS 2005 IDE Unicode
                                I += 2
                                
    For J = I To S.Length - 1
                                    
    If S(J) = " " Then Exit For
                                Next
                                SW.Write("&#" & Integer.Parse(S.Substring(I, J - I), Globalization.NumberStyles.HexNumber).ToString & ";")
                                I = J - 1
                            
    Case Else
                                I += 1
                                
    For J = I To S.Length - 1
                                    
    If S(J) = " " Or S(J) = "\" Then Exit For
                                Next
                                If S.Substring(I, 2) = "cf" Then
                                    ' Changed to add support to more then 10 colors
                                    WriteColor(S.Substring(I + 2, J - I - 2))

                                
    End If

                                'I = If(J < S.Length, If(S(J) = " ", J, J - 1), J)
                                'Change start
                                If J < S.Length Then
                                    If S(J) = " " Then
                                        I = J
                                    
    Else
                                        I = J - 1
                                    
    End If
                                Else
                                    I = J
                                
    End If
                                'Change end
                        End Select
                    Case "<"c
                        SW.Write("&lt;")
                    
    Case ">"c
                        SW.Write("&gt;")
                    
    Case "&"c
                        SW.Write("&amp;")
                    
    Case " "c
                        SW.Write("&nbsp;")
                    
    Case Else
                        SW.Write(S(I))
                
    End Select
            Next
            SW.Write("<br>" & Environment.NewLine)

        
    End Sub
        <Obsolete()> Private Sub WriteColor(ByVal C As Char)
            
    Dim I As Integer
            I = Integer.Parse(C) - 1
            
    If I < 0 Then
                SW.Write("</span><span>")
            
    Else
                SW.Write("</span><span style=" & Chr(34) & "Color: " & Clrtbl(I) & ";" & Chr(34) & ">")
            
    End If
        End Sub
        Private Sub WriteColor(ByVal C As String)
            
    Dim I As Integer
            I = Integer.Parse(C) - 1
            
    If I < 0 Then
                SW.Write("</span><span>")
            
    Else
                SW.Write("</span><span style=" & Chr(34) & "Color: " & Clrtbl(I) & ";" & Chr(34) & ">")
            
    End If
        End Sub
        Private Function GetWholeColorTableString() As String
            Dim ReturnValue As String
            Dim I As Integer
            Dim S As String = SR.ReadLine
            I = S.IndexOf(
    "{\colortbl")
            
    If I > -1 Then
                I += 11
                S = S.Substring(I)
                
    While S.IndexOf("}"c) < 0 AndAlso SR.Peek > -1
                    S &= SR.ReadLine
                
    End While
                ReturnValue = S
            
    Else
                ReturnValue = S
            
    End If
            Return ReturnValue
        
    End Function
        Function GetColorTable() As String
            Dim I As Integer
            Dim S As String
            Clrtbl = New List(Of String)
            S = GetWholeColorTableString()
            I = S.IndexOf(
    "}"c)
            
    If I > 0 Then
                FillColorTable(S.Substring(0, I).Split(";"c))
            
    End If
            Select Case I
                
    Case S.Length - 1
                    S = SR.ReadLine
                
    Case Is > 0
                    S = S.Substring(I + 1)
            
    End Select
            Return S
        
    End Function
        Private Sub FillColorTable(ByVal TheColors() As String)
            
    Dim I As Integer
            Dim J As Integer
            Dim SingleColor As String
            Dim S2() As String
            Dim Clrs() As Integer = {3, 5, 4} 'Length of the colors
            For I = 0 To TheColors.Length - 2
                S2 = TheColors(I).Split(
    "\"c)
                SingleColor = 
    "#"
                For J = 1 To 3
                    SingleColor &= Hex(
    Integer.Parse(S2(J).Substring(Clrs(J - 1)))).PadLeft(2, "0"c)
                
    Next
                Clrtbl.Add(SingleColor)
            
    Next
        End Sub
    End
     Class

    #End
     Region

    Ok, as a hint for everybody: don`t use the HasCode with html inside your code.
    • Edited by Heslacher Tuesday, January 19, 2010 10:34 AM Version 1.0.5
    • Edited by Heslacher Tuesday, January 19, 2010 10:35 AM Version 1.0.5 Part 1
    • Edited by Heslacher Friday, March 05, 2010 11:38 AM Version 1.0.6 part 1
    • Edited by Heslacher Friday, March 05, 2010 11:39 AM
    • Edited by Heslacher Friday, March 05, 2010 11:40 AM
    • Edited by Heslacher Friday, March 05, 2010 11:40 AM
    • Edited by Heslacher Friday, March 05, 2010 12:05 PM
    • Edited by Heslacher Friday, March 05, 2010 12:12 PM
    • Edited by Heslacher Friday, March 05, 2010 12:16 PM
    • Edited by Heslacher Friday, March 05, 2010 12:19 PM
    •  
  • Friday, January 15, 2010 9:15 AM
     
     
    The express versions don't allow addins though .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
  • Friday, January 15, 2010 9:17 AM
     
     
    Complete project and setup is located here www.srsoft.us 
    Hannes

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
  • Monday, January 18, 2010 3:03 PM
     
     
    Hi John,

    i have uploaded the addin as msi package (without source) to Visual Studio Gallery. If you don`t agree to this, i will delete it.
    Link: http://visualstudiogallery.msdn.microsoft.com/en-us/1262da48-acef-4e7a-b56c-a42a84ce6e0e

    Regards
    Hannes
    Hannes

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
  • Monday, January 18, 2010 3:35 PM
     
     
    I'd prefer that the project source was located on Skydrive where it would be available to all forum members.  You've certainly put quite a bit of effort into this.  I hope it gets some use, particularly by the newer forum users. 
  • Monday, January 18, 2010 3:48 PM
     
     
  • Tuesday, January 19, 2010 10:36 AM
     
      Has Code
    'Visual Basic 2008 - .net 2.0 - Any CPU
    ' A reference to System.Windows.Forms is needed !
    ' A reference to System.Drawing is needed !
    #Region "Imports for addin"
    Imports Microsoft.VisualStudio.CommandBars
    Imports Extensibility
    Imports EnvDTE
    #End Region
    
    #Region "Imports for clipboard"
    Imports System.Windows.Forms
    #End Region
    
    #Region "Imports for RtfToHtml class"
    Imports System.IO
    Imports System.Collections.Generic
    #End Region
    
    Public Class Connect
        Implements Extensibility.IDTExtensibility2
    
    #Region "Addin related variables and events"
        Private WithEvents _WindowEvents As WindowEvents
        ' Variables for IDE and add-in instances
        Private applicationObject As EnvDTE.DTE
        Private addInInstance As EnvDTE.AddIn
        Private Sub _WindowEvents_WindowActivated(ByVal GotFocus As EnvDTE.Window, ByVal LostFocus As EnvDTE.Window) Handles _WindowEvents.WindowActivated
            EnableDisableButton(GotFocus)
        End Sub
        Public Sub OnConnection(ByVal application As Object, ByVal connectMode _
           As Extensibility.ext_ConnectMode, ByVal addInInst As Object, _
           ByRef custom As System.Array) _
           Implements Extensibility.IDTExtensibility2.OnConnection
            Try
                applicationObject = CType(application, EnvDTE.DTE)
                addInInstance = CType(addInInst, EnvDTE.AddIn)
                Dim events As EnvDTE.Events
                events = applicationObject.Events
                _WindowEvents = CType(events.WindowEvents(Nothing), EnvDTE.WindowEvents)
                Select Case connectMode
                    Case ext_ConnectMode.ext_cm_UISetup
                    Case ext_ConnectMode.ext_cm_Startup
                    Case ext_ConnectMode.ext_cm_AfterStartup
                        Initialize()
                End Select
            Catch e As System.Exception
                MsgBox(e.ToString)
            End Try
        End Sub
    
        Public Sub OnStartupComplete(ByRef custom As System.Array) _
           Implements Extensibility.IDTExtensibility2.OnStartupComplete
            Initialize()
        End Sub
        Private Sub Initialize()
            InitFontSizes()
            AddCommandBarAndButtons()
        End Sub
        Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, _
           ByRef custom As System.Array) _
           Implements Extensibility.IDTExtensibility2.OnDisconnection
            Try
                Select Case RemoveMode
                    Case ext_DisconnectMode.ext_dm_HostShutdown, ext_DisconnectMode.ext_dm_UserClosed
                        If Not (myTemporaryToolbar Is Nothing) Then
                            myTemporaryToolbar.Delete()
                            myTemporaryToolbar = Nothing
                        End If
                        mySelectButton = Nothing
                        mySelectAllButton = Nothing
                        mySettingButton = Nothing
                End Select
            Catch e As System.Exception
                MsgBox(e.ToString)
            End Try
            _WindowEvents = Nothing
        End Sub
    
        Public Sub OnBeginShutdown(ByRef custom As System.Array) _
           Implements Extensibility.IDTExtensibility2.OnBeginShutdown
        End Sub
    
        Public Sub OnAddInsUpdate(ByRef custom As System.Array) _
            Implements Extensibility.IDTExtensibility2.OnAddInsUpdate
        End Sub
    
    #End Region
    
    #Region "User interface variables,functions and events"
        ' Commandbarbuttons
        Private WithEvents mySelectButton As CommandBarButton
        Private WithEvents mySelectAllButton As CommandBarButton
        Private WithEvents mySettingButton As CommandBarButton
        ' We must keep them at class level to remove them when the add-in is unloaded
        Private myTemporaryToolbar As CommandBar
        Private TheFontSizes(10) As String
    
        Private Sub mySettingButton_Click(ByVal Ctrl As Microsoft.VisualStudio.CommandBars.CommandBarButton, ByRef CancelDefault As Boolean) Handles mySettingButton.Click
            Dim MySetting As Settings
            MySetting = New Settings(My.Settings.Setting, My.Settings.Fontsize, TheFontSizes)
            AddHandler MySetting.SettingChanged, AddressOf SettingChanged
            MySetting.ShowDialog()
            RemoveHandler MySetting.SettingChanged, AddressOf SettingChanged
            MySetting = Nothing
        End Sub
    
        Private Sub SettingChanged(ByVal AddValue As Integer, ByVal FontSize As Integer)
            My.Settings.Setting = AddValue
            My.Settings.Fontsize = FontSize
            My.Settings.Save()
        End Sub
        Private Sub InitFontSizes()
            TheFontSizes(0) = "default"
            TheFontSizes(1) = "small"
            TheFontSizes(2) = "smaller"
            TheFontSizes(3) = "x-small"
            TheFontSizes(4) = "xx-small"
            TheFontSizes(5) = "medium"
            TheFontSizes(6) = "x-medium"
            TheFontSizes(7) = "large"
            TheFontSizes(8) = "larger"
            TheFontSizes(9) = "x-large"
            TheFontSizes(10) = "xx-large"
        End Sub
            Private Sub AddCommandBarAndButtons()
            Dim commandBars As CommandBars
            ' As a quick workaraound for the VS2010 Commandbuttons
            Dim UseFaceID As Boolean = (GetVersionOfVS(applicationObject.ActiveWindow) <> VSVersion.VS2010)
            Try
                commandBars = DirectCast(applicationObject.CommandBars, CommandBars)
                '' Add a new toolbar 
                myTemporaryToolbar = commandBars.Add("Code formatter", _
                   MsoBarPosition.msoBarTop, System.Type.Missing, True)
                ' Add button 
                mySelectButton = DirectCast(myTemporaryToolbar.Controls.Add(MsoControlType.msoControlButton, , , , True), CommandBarButton)
                mySelectButton.Caption = "Selected code to HTML"
                mySelectButton.Style = MsoButtonStyle.msoButtonIconAndCaption
                mySelectButton.Enabled = False
                If UseFaceID Then
                    mySelectButton.FaceId = 231
                End If
                mySelectButton.TooltipText = "Generate html output from the selected code"
                ' The next button
                mySelectAllButton = DirectCast(myTemporaryToolbar.Controls.Add(MsoControlType.msoControlButton, , , , True), CommandBarButton)
                mySelectAllButton.Caption = "All code to HTML"
                mySelectAllButton.Style = MsoButtonStyle.msoButtonIconAndCaption
                mySelectAllButton.Enabled = False
                If UseFaceID Then
                    mySelectAllButton.FaceId = 230
                End If
                mySelectAllButton.TooltipText = "Generate html output from the whole code in that codewindow"
                ' The setting button
                mySettingButton = DirectCast(myTemporaryToolbar.Controls.Add(MsoControlType.msoControlButton, , , , True), CommandBarButton)
                mySettingButton.Caption = "Settings"
                mySettingButton.Style = MsoButtonStyle.msoButtonIconAndCaption
                mySettingButton.Enabled = True
                If UseFaceID Then
                    mySettingButton.FaceId = 230
                End If
                mySettingButton.TooltipText = "Settings about the appearance"
    
                ' Show the toolbar
                myTemporaryToolbar.Visible = True
                EnableDisableButton(applicationObject.ActiveWindow)
            Catch e As System.Exception
                MsgBox(e.ToString)
            End Try
        End Sub
        Private Sub mySelectAllButton_Click(ByVal Ctrl As Microsoft.VisualStudio.CommandBars.CommandBarButton, ByRef CancelDefault As Boolean) Handles mySelectAllButton.Click
            Convert(True)
        End Sub
        Private Sub mySelectButton_Click(ByVal Ctrl As Microsoft.VisualStudio.CommandBars.CommandBarButton, ByRef CancelDefault As Boolean) Handles mySelectButton.Click
            Convert(False)
        End Sub
    #End Region
    #Region "IDE related functions and events"
        Private WithComment As Boolean = True
        Private Enum VSVersion As Integer
            VSNotRecognized = 0
            VS2005 = 2005
            VS2008 = 2008
            VS2010 = 2010
        End Enum
        Private Function GetCodeFromCodeWindow(ByVal SelectAll As Boolean, ByVal CopyAsUnicode As Boolean) As String
            Dim ReturnValue As String = String.Empty
            Dim oSel As TextSelection = DirectCast(applicationObject.ActiveDocument.Selection, TextSelection)
            If SelectAll Then
                oSel.SelectAll()
            End If
            If Not oSel.IsEmpty Then
                oSel.Copy()
                If CopyAsUnicode Then
                    ReturnValue = Clipboard.GetText(TextDataFormat.UnicodeText)
                Else
                    ReturnValue = Clipboard.GetText(TextDataFormat.Rtf)
                End If
            End If
            Return ReturnValue
        End Function
        Private Function IsFormWindow(ByVal EnvDteWindow As EnvDTE.Window) As Boolean
            Dim ReturnValue As Boolean = False
            If TypeOf EnvDteWindow.Object Is System.ComponentModel.Design.IDesignerHost Then
                ReturnValue = True
            End If
            Return ReturnValue
        End Function
        Private Function IsCodeWindow(ByVal EnvDTEWindow As EnvDTE.Window) As Boolean
            Dim ReturnValue As Boolean = True
            If EnvDTEWindow.ProjectItem Is Nothing OrElse EnvDTEWindow.ProjectItem.FileCodeModel Is Nothing Then
                ReturnValue = False
            End If
            Return ReturnValue
        End Function
        Private Function GetLanguage(ByVal EnvDTEWindow As EnvDTE.Window, ByVal VersionOfVS As VSVersion) As String
            Dim ReturnValue As String = String.Empty
            Select Case EnvDTEWindow.Project.CodeModel.Language
                Case CodeModelLanguageConstants.vsCMLanguageCSharp
                    ReturnValue = "Visual C#"
                    RtfToHtml.CodeTag = "x-c#"
                    RtfToHtml.CommentStarter = "//"
                Case CodeModelLanguageConstants.vsCMLanguageIDL
                    ReturnValue = "Microsoft IDL"
                    RtfToHtml.CodeTag = String.Empty
                    RtfToHtml.CommentStarter = "//"
                Case CodeModelLanguageConstants.vsCMLanguageMC
                    ReturnValue = "Visual C++"
                    RtfToHtml.CodeTag = "x-cpp"
                    RtfToHtml.CommentStarter = "//"
                Case CodeModelLanguageConstants.vsCMLanguageVB
                    ReturnValue = "Visual Basic"
                    RtfToHtml.CodeTag = "x-vbnet"
                    RtfToHtml.CommentStarter = "'"
                Case CodeModelLanguageConstants.vsCMLanguageVC
                    ReturnValue = "Visual C++"
                    RtfToHtml.CodeTag = "x-cpp"
                    RtfToHtml.CommentStarter = "//"
            End Select
            Return ReturnValue & " " & DirectCast(VersionOfVS, Integer).ToString
        End Function
        Private Function GetPlatformType(ByVal EnvDTEWindow As EnvDTE.Window) As String
            Return EnvDTEWindow.Project.ConfigurationManager.ActiveConfiguration.PlatformName
        End Function
        Private Function GetTargetFramework(ByVal EnvDTEWindow As EnvDTE.Window, ByVal VersionOfVS As VSVersion) As String
            Dim ReturnValue As String = String.Empty
            Select Case VersionOfVS
                Case VSVersion.VS2005
                    ReturnValue = ".net 2.0"
                Case VSVersion.VS2008
                    ReturnValue = ".net " & GetTargetFramework(EnvDTEWindow.Project)
                Case VSVersion.VS2010
                    ReturnValue = ".net " & GetTargetFramework(EnvDTEWindow.Project)
                Case VSVersion.VSNotRecognized
                    ReturnValue = "unknown"
            End Select
            Return ReturnValue
        End Function
        Private Function GetTargetFramework(ByVal EnvDTEProject As EnvDTE.Project) As String
            Const NetFx20 As Integer = 131072
            Const NetFx30 As Integer = 196608
            Const NetFx35 As Integer = 196613
            Const NetFX40 As Integer = 262144
            Dim ReturnValue As String = String.Empty
            Select Case CType(EnvDTEProject.Properties.Item("TargetFramework").Value, Integer)
                Case NetFx20
                    ReturnValue = "2.0"
                Case NetFx30
                    ReturnValue = "3.0"
                Case NetFx35
                    ReturnValue = "3.5"
                Case NetFX40
                    ReturnValue = "4.0"
            End Select
            Return ReturnValue
        End Function
        Private Sub EnableDisableButton(ByVal EnvDTEWindow As EnvDTE.Window)
            If IsFormWindow(EnvDTEWindow) Then
                mySelectButton.Enabled = False
                mySelectAllButton.Enabled = False
                Exit Sub
            ElseIf IsCodeWindow(EnvDTEWindow) Then
                mySelectButton.Enabled = True
                mySelectAllButton.Enabled = True
                Exit Sub
            Else
                mySelectAllButton.Enabled = False
                mySelectButton.Enabled = False
                Exit Sub
            End If
        End Sub
        Private Function GetVersionOfVS(ByVal EnvDTEWindow As EnvDTE.Window) As VSVersion
            Dim ReturnValue As VSVersion = VSVersion.VSNotRecognized
            Select Case EnvDTEWindow.DTE.Version
                Case "8.0"
                    ReturnValue = VSVersion.VS2005
                Case "9.0"
                    ReturnValue = VSVersion.VS2008
                Case "10.0"
                    ReturnValue = VSVersion.VS2010
            End Select
            Return ReturnValue
        End Function
        Private Function GetComment(ByVal EnvDTEWindow As EnvDTE.Window, ByVal AddValue As Integer) As String
            Dim ReturnList As New List(Of String)
            Dim VersionOfVS As VSVersion
            If (AddValue And 1) > 0 OrElse (AddValue And 2) > 0 Then
                VersionOfVS = GetVersionOfVS(EnvDTEWindow)
                If (AddValue And 1) > 0 Then
                    ReturnList.Add(GetLanguage(EnvDTEWindow, VersionOfVS))
                End If
                If (AddValue And 2) > 0 Then
                    ReturnList.Add(GetTargetFramework(EnvDTEWindow, VersionOfVS))
                End If
            End If
            If (AddValue And 4) > 0 Then
                ReturnList.Add(GetPlatformType(EnvDTEWindow))
            End If
            Return ComposeComment(ReturnList)
        End Function
        Private Function ComposeComment(ByVal ReturnList As List(Of String)) As String
            Dim ReturnValue As String = String.Empty
            Dim i As Integer
            If ReturnList.Count > 0 Then
                For i = 0 To ReturnList.Count - 2
                    ReturnValue &= ReturnList.Item(i) & " - "
                Next
                ReturnValue &= ReturnList.Item(i)
            End If
            Return ReturnValue
        End Function
    #End Region
    
    #Region "The convert function"
        Private Sub Convert(ByVal SelectAll As Boolean)
            Dim CodeToHTMLFormatter As RtfToHtml
            CodeToHTMLFormatter = New RtfToHtml()
            RtfToHtml.Comment = GetComment(applicationObject.ActiveWindow, My.Settings.Setting)
            RtfToHtml.FontSize = TheFontSizes(My.Settings.Fontsize)
            RtfToHtml.HasCode = (My.Settings.Setting And 8) > 0
            Dim CodeAsRTF As String = GetCodeFromCodeWindow(SelectAll, RtfToHtml.HasCode)
            If Not CodeAsRTF = String.Empty Then
                Dim CodeAsHtml As String = CodeToHTMLFormatter.RtfToHtml(CodeAsRTF)
                If CodeAsHtml.Length > 60000 Then
                    MsgBox("Code to long for MSDN forum")
                End If
                Clipboard.SetText(CodeAsHtml, TextDataFormat.Html)
            End If
        End Sub
    #End Region
    
    End Class


    Hannes

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    • Edited by Heslacher Tuesday, January 19, 2010 10:37 AM Version 1.0.5 Part 2
    • Edited by Heslacher Friday, March 05, 2010 11:37 AM Version 1.0.6 Part 2
    • Edited by Heslacher Wednesday, April 14, 2010 11:08 AM Version 1.0.7
    • Edited by Heslacher Wednesday, April 14, 2010 11:16 AM
    • Edited by Heslacher Wednesday, April 14, 2010 11:20 AM
    •  
  • Friday, January 22, 2010 11:38 PM
     
     
    Try this.  Maybe we can get an improved method of posting code to the forums.  Please provide feedback.
  • Friday, January 22, 2010 11:39 PM
     
     
    ^bump^

    I just want to subscribe to this thread.


    Mark the best replies as answers. "Fooling computers since 1971."
  • Saturday, January 23, 2010 6:55 AM
     
     
    What did Heslacher  just post ? The current version ? Is it different from what John has posted ?
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
  • Saturday, January 23, 2010 8:26 AM
     
     
    Hi bdbodger,

    you can also ask me directly :-) . Yes it is the current version of the addin, i needed to split it into 2 posts, because it has been to long. And yes it is a little bit different to John`s code. This code works with the rtf based on the Codewindow of the ide. I did remove the changed comments, because i had thought to get it in one post, but it didn`t work and i forgot to put the comments back.
    I also added in the WriteLine() method 2 cases for unicode formats in the ide based on the different rtf text of VS 2005 and VS 2008.
    With this version it works for both VS 2005 and 2008 (with no problems so far).

    Hannes

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
  • Saturday, January 23, 2010 8:57 AM
     
     
    The addin I see ok . I use VBE so I guess I'll stick with the original code . I may even change it a bit right now you have to press two buttons one to paste another to copy seems to me that it should only need one button press . I may even do it from a NotifyIcon :) or not it works ok as is .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
  • Saturday, January 23, 2010 9:09 AM
     
     
    The two buttons were for the richtextbox.  To simplify to one button, I'd remove the RTB and make a really small form.  Might even detect the presence of VB or VCS and RTF and convert it to HTML.
  • Saturday, January 23, 2010 11:28 AM
     
     
    For the addin it will stay with 2 buttons. On is for the allready selected code to convert to html, and the other is for converting all code in the actual codewindow to convert to html.
    Also with VBE you could, if you want to, use the addin, because i have uploaded also a setup for it.

    Hannes

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
  • Monday, February 01, 2010 7:33 PM
     
     
    John,
    It's nice to see people posting code in this forum again. We should insist upon it.
    Renee
  • Monday, February 22, 2010 11:24 PM
     
     
  • Tuesday, February 23, 2010 6:52 PM
    Moderator
     
     
    Centralized post which refers to this one along with the links now sticky in C# General forum: Forums Code Addin Alternative to Insert Code Block.

    William Wegerson (www.OmegaCoder.Com )
  • Tuesday, February 23, 2010 7:34 PM
    Moderator
     
     
    I updated the text in the post to give Heslacher credit and also created a sticky in this forum with the same text.

    Forums Code Addin Alternative to Insert Code Block
    William Wegerson (www.OmegaCoder.Com)
  • Friday, March 05, 2010 12:21 PM
     
      Has Code

    'Visual Basic 2008 - .net 2.0 - Any CPU
    Public Class Settings
        Public Event SettingChanged(ByVal AddValue As Integer, ByVal FontSize As Integer)
        Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
            Me.Hide()
        End Sub
        Private Function GetAddValue() As Integer
            Dim ReturnValue As Integer = 0
            If chAddlanguage.Checked Then
                ReturnValue = ReturnValue Or 1
            End If
            If chAddframework.Checked Then
                ReturnValue = ReturnValue Or 2
            End If
            If chAddplatform.Checked Then
                ReturnValue = ReturnValue Or 4
            End If
            If chUseCodeTag.Checked Then
                ReturnValue = ReturnValue Or 8
            End If
            Return ReturnValue
        End Function
        Private Sub SetAddValue(ByVal AddValue As Integer)
            Me.chAddlanguage.Checked = (AddValue And 1) > 0
            Me.chAddframework.Checked = (AddValue And 2) > 0
            Me.chAddplatform.Checked = (AddValue And 4) > 0
            Me.chUseCodeTag.Checked = (AddValue And 8) > 0
        End Sub
        Private Function GetFontsize() As Integer
            Return cbFontsize.SelectedIndex
        End Function
    
        Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
            Me.Hide()
            RaiseEvent SettingChanged(GetAddValue, GetFontsize)
        End Sub
        Private Sub New()
            InitializeComponent()
        End Sub
        Private Sub InitializeFontSizesCombobox(ByVal FontSize As Integer, ByVal MyFontSizes() As String)
            If MyFontSizes IsNot Nothing Then
                cbFontsize.Items.AddRange(MyFontSizes)
                cbFontsize.SelectedIndex = FontSize
            End If
        End Sub
        Public Sub New(ByVal AddValue As Integer, ByVal Fontsize As Integer, ByVal MyFontSizes() As String)
            Me.New()
            SetAddValue(AddValue)
            InitializeFontSizesCombobox(Fontsize, MyFontSizes)
        End Sub
    End Class
    


    'Visual Basic 2008 - .net 2.0 - Any CPU
     _
    Partial Class Settings
        Inherits System.Windows.Forms.Form
    
        'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen.
         _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            Try
                If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
                End If
            Finally
                MyBase.Dispose(disposing)
            End Try
        End Sub
    
        'Wird vom Windows Form-Designer benötigt.
        Private components As System.ComponentModel.IContainer
    
        'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich.
        'Das Bearbeiten ist mit dem Windows Form-Designer möglich.  
        'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
         _
        Private Sub InitializeComponent()
            Me.cmdCancel = New System.Windows.Forms.Button
            Me.GroupBox1 = New System.Windows.Forms.GroupBox
            Me.Label1 = New System.Windows.Forms.Label
            Me.cbFontsize = New System.Windows.Forms.ComboBox
            Me.chAddlanguage = New System.Windows.Forms.CheckBox
            Me.chAddframework = New System.Windows.Forms.CheckBox
            Me.chAddplatform = New System.Windows.Forms.CheckBox
            Me.cmdSave = New System.Windows.Forms.Button
            Me.chUseCodeTag = New System.Windows.Forms.CheckBox
            Me.GroupBox1.SuspendLayout()
            Me.SuspendLayout()
            '
            'cmdCancel
            '
            Me.cmdCancel.Location = New System.Drawing.Point(230, 183)
            Me.cmdCancel.Name = "cmdCancel"
            Me.cmdCancel.Size = New System.Drawing.Size(83, 27)
            Me.cmdCancel.TabIndex = 0
            Me.cmdCancel.Text = "Cancel"
            Me.cmdCancel.UseVisualStyleBackColor = True
            '
            'GroupBox1
            '
            Me.GroupBox1.Controls.Add(Me.chUseCodeTag)
            Me.GroupBox1.Controls.Add(Me.Label1)
            Me.GroupBox1.Controls.Add(Me.cbFontsize)
            Me.GroupBox1.Controls.Add(Me.chAddlanguage)
            Me.GroupBox1.Controls.Add(Me.chAddframework)
            Me.GroupBox1.Controls.Add(Me.chAddplatform)
            Me.GroupBox1.Location = New System.Drawing.Point(4, 0)
            Me.GroupBox1.Name = "GroupBox1"
            Me.GroupBox1.Size = New System.Drawing.Size(309, 177)
            Me.GroupBox1.TabIndex = 7
            Me.GroupBox1.TabStop = False
            '
            'Label1
            '
            Me.Label1.AutoSize = True
            Me.Label1.Location = New System.Drawing.Point(22, 152)
            Me.Label1.Name = "Label1"
            Me.Label1.Size = New System.Drawing.Size(46, 13)
            Me.Label1.TabIndex = 13
            Me.Label1.Text = "Fontsize"
            '
            'cbFontsize
            '
            Me.cbFontsize.FormattingEnabled = True
            Me.cbFontsize.Location = New System.Drawing.Point(103, 148)
            Me.cbFontsize.Name = "cbFontsize"
            Me.cbFontsize.Size = New System.Drawing.Size(198, 21)
            Me.cbFontsize.TabIndex = 12
            '
            'chAddlanguage
            '
            Me.chAddlanguage.AutoSize = True
            Me.chAddlanguage.Location = New System.Drawing.Point(6, 19)
            Me.chAddlanguage.Name = "chAddlanguage"
            Me.chAddlanguage.Size = New System.Drawing.Size(232, 17)
            Me.chAddlanguage.TabIndex = 11
            Me.chAddlanguage.Text = "Add used language (e.g. Visual Basic 2005)"
            Me.chAddlanguage.UseVisualStyleBackColor = True
            '
            'chAddframework
            '
            Me.chAddframework.AutoSize = True
            Me.chAddframework.Location = New System.Drawing.Point(6, 52)
            Me.chAddframework.Name = "chAddframework"
            Me.chAddframework.Size = New System.Drawing.Size(189, 17)
            Me.chAddframework.TabIndex = 10
            Me.chAddframework.Text = "Add used framework (e.g. .net 2.0)"
            Me.chAddframework.UseVisualStyleBackColor = True
            '
            'chAddplatform
            '
            Me.chAddplatform.AutoSize = True
            Me.chAddplatform.Location = New System.Drawing.Point(6, 84)
            Me.chAddplatform.Name = "chAddplatform"
            Me.chAddplatform.Size = New System.Drawing.Size(183, 17)
            Me.chAddplatform.TabIndex = 9
            Me.chAddplatform.Text = "Add used platform (e.g. any CPU)"
            Me.chAddplatform.UseVisualStyleBackColor = True
            '
            'cmdSave
            '
            Me.cmdSave.Location = New System.Drawing.Point(141, 183)
            Me.cmdSave.Name = "cmdSave"
            Me.cmdSave.Size = New System.Drawing.Size(83, 27)
            Me.cmdSave.TabIndex = 8
            Me.cmdSave.Text = "Save"
            Me.cmdSave.UseVisualStyleBackColor = True
            '
            'chUseCodeTag
            '
            Me.chUseCodeTag.AutoSize = True
            Me.chUseCodeTag.Location = New System.Drawing.Point(6, 116)
            Me.chUseCodeTag.Name = "chUseCodeTag"
            Me.chUseCodeTag.Size = New System.Drawing.Size(131, 17)
            Me.chUseCodeTag.TabIndex = 14
            Me.chUseCodeTag.Text = "Use Has Code feature"
            Me.chUseCodeTag.UseVisualStyleBackColor = True
            '
            'Settings
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(317, 216)
            Me.Controls.Add(Me.cmdSave)
            Me.Controls.Add(Me.GroupBox1)
            Me.Controls.Add(Me.cmdCancel)
            Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
            Me.Name = "Settings"
            Me.Text = "Settings"
            Me.GroupBox1.ResumeLayout(False)
            Me.GroupBox1.PerformLayout()
            Me.ResumeLayout(False)
    
        End Sub
        Friend WithEvents cmdCancel As System.Windows.Forms.Button
        Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
        Friend WithEvents chAddlanguage As System.Windows.Forms.CheckBox
        Friend WithEvents chAddframework As System.Windows.Forms.CheckBox
        Friend WithEvents chAddplatform As System.Windows.Forms.CheckBox
        Friend WithEvents cmdSave As System.Windows.Forms.Button
        Friend WithEvents Label1 As System.Windows.Forms.Label
        Friend WithEvents cbFontsize As System.Windows.Forms.ComboBox
        Friend WithEvents chUseCodeTag As System.Windows.Forms.CheckBox
    
    End Class
    


    'Visual Basic 2008 - .net 2.0 - Any CPU
    '------------------------------------------------------------------------------
    ' 
    '     Dieser Code wurde von einem Tool generiert.
    '     Laufzeitversion:2.0.50727.3603
    '
    '     Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
    '     der Code erneut generiert wird.
    ' 
    '------------------------------------------------------------------------------
    
    Option Strict On
    Option Explicit On
    
    
    Namespace My
        
          _
        Partial Friend NotInheritable Class MySettings
            Inherits Global.System.Configuration.ApplicationSettingsBase
            
            Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings),MySettings)
            
    #Region "Funktion zum automatischen Speichern von My.Settings"
    #If _MyType = "WindowsForms" Then
        Private Shared addedHandler As Boolean
    
        Private Shared addedHandlerLockObject As New Object
    
         _
        Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs)
            If My.Application.SaveMySettingsOnExit Then
                My.Settings.Save()
            End If
        End Sub
    #End If
    #End Region
            
            Public Shared ReadOnly Property [Default]() As MySettings
                Get
                    
    #If _MyType = "WindowsForms" Then
                   If Not addedHandler Then
                        SyncLock addedHandlerLockObject
                            If Not addedHandler Then
                                AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
                                addedHandler = True
                            End If
                        End SyncLock
                    End If
    #End If
                    Return defaultInstance
                End Get
            End Property
            
              _
            Public Property Setting() As Integer
                Get
                    Return CType(Me("Setting"),Integer)
                End Get
                Set
                    Me("Setting") = value
                End Set
            End Property
            
              _
            Public Property Fontsize() As Integer
                Get
                    Return CType(Me("Fontsize"),Integer)
                End Get
                Set
                    Me("Fontsize") = value
                End Set
            End Property
        End Class
    End Namespace
    
    Namespace My
        
          _
        Friend Module MySettingsProperty
            
              _
            Friend ReadOnly Property Settings() As Global.RTFTOHTML.My.MySettings
                Get
                    Return Global.RTFTOHTML.My.MySettings.Default
                End Get
            End Property
        End Module
    End Namespace
    


    Hannes

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    • Edited by Heslacher Friday, March 05, 2010 12:22 PM Version 1.0.6 Part 3
    •