Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Windows

Public Class UserControl1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim oDb As Database = HostApplicationServices.WorkingDatabase
        Dim oTr As Transaction = oDb.TransactionManager.StartTransaction

        Try

            Dim oDocLock As DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument

            Dim oTt As TextStyleTable = oTr.GetObject(oDb.TextStyleTableId, OpenMode.ForWrite)
            Dim oTtr As TextStyleTableRecord
            If Not oTt.Has(TextBox1.Text) Then
                oTtr = New TextStyleTableRecord
                oTtr.Name = TextBox1.Text
                oTtr.FileName = "romans.shx"
                oTtr.BigFontFileName = "extfont2.shx"
                oTt.Add(oTtr)
                oTr.AddNewlyCreatedDBObject(oTtr, True)
            Else
                MsgBox("既に文字スタイルが存在しています")
            End If

            oTr.Commit()

            oDocLock.Dispose()

        Catch oEx As Exception
            'MsgBox(oEx.ToString())
        Finally
            oTr.Dispose()
        End Try

    End Sub
End Class
