Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD


Public Class Fen_UserControl

    Private Sub ListBox_ListeDesPresentation_DoubleClic _
    (ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles ListBox_ListeDesPresentation.DoubleClick

        Dim NomPresentation As String

        NomPresentation = ListBox_ListeDesPresentation.Items(ListBox_ListeDesPresentation.SelectedIndex).ToString

        ActivationPresentation(NomPresentation)

    End Sub


    Public Sub ActivationPresentation(ByVal NomPresenation As String)

        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor

        Using docLock As DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument()
            Using db As Database = Application.DocumentManager.MdiActiveDocument.Database
                Using tr As Transaction = db.TransactionManager.StartTransaction
                    Dim lm As LayoutManager = LayoutManager.Current

                    lm.CurrentLayout = NomPresenation

                    Label_NomPresentation.Text = NomPresenation
                    Label_NombreDePresentation.Text = ListBox_ListeDesPresentation.Items.Count.ToString


                    tr.Commit()
                    ed.Regen()
                End Using
            End Using
        End Using

    End Sub



    Public Sub RemplissageListe()

        ListBox_ListeDesPresentation.Items.Clear()


        Dim db As Database
        Dim tr As Transaction
        Dim ed As Editor
        Dim lyt As Layout
        Dim lytDict As DBDictionary
        Dim entry As System.Collections.DictionaryEntry
        Dim lMgr As Autodesk.AutoCAD.DatabaseServices.LayoutManager

        Try
            db = HostApplicationServices.WorkingDatabase
            tr = db.TransactionManager.StartTransaction
            ed = Application.DocumentManager.MdiActiveDocument.Editor
            lMgr = LayoutManager.Current

            Label_NomPresentation.Text = lMgr.CurrentLayout
            Label_NombreDePresentation.Text = lMgr.LayoutCount.ToString

            lytDict = CType(tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead), DBDictionary)

            For Each entry In lytDict
                lyt = CType(tr.GetObject(CType(entry.Value, ObjectId), OpenMode.ForRead), Layout)

                ListBox_ListeDesPresentation.Items.Add(lyt.LayoutName)
            Next
            tr.Commit()
        Catch ex As Exception
            ed.WriteMessage(ex.ToString)
        Finally
            tr.Dispose()
        End Try
    End Sub



    Private Sub LinkLabel_site_LinkClicked _
    (ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) _
    Handles LinkLabel_Site.LinkClicked

        System.Diagnostics.Process.Start("http://www.dominique-vaquand.com/")

    End Sub


End Class
