LINETYPE

LINETYPE

Anonymous
Not applicable
2,753 Views
3 Replies
Message 1 of 4

LINETYPE

Anonymous
Not applicable

Linetype.JPG

Dear, is it possible to create a combobox in c# with line styles (see image)?

Best regards

0 Likes
Accepted solutions (2)
2,754 Views
3 Replies
Replies (3)
Message 2 of 4

norman.yuan
Mentor
Mentor

I am not aware of this kind of ready-to-use control available. If I were you, when there is need to ask user to select a line type on a custom UI, I would use a button beside a read-only text box (to show linetype name, but maybe a picture showing the line type image). Clicking the button would open the AutoCAD built-in LineType dialog as second level dialog. The AutoCAD LineType dialog can be found in Autodesk.AutoCAD.Windows.LineTypeDialog in acmgd.dll.

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 4

_gile
Consultant
Consultant
Accepted solution

Hi,

 

Here's a little example which displays the loaded line types.

 

    public struct Linetype
    {
        public Linetype(string name, ObjectId id)
        {
            Name = name;
            ObjectId = id;
        }
        public string Name { get; }
        public ObjectId ObjectId { get; }
    }

    public partial class Dialog : Form
    {
        Linetype[] source;

        public Linetype Linetype => (Linetype)comboLinetypes.SelectedItem;

        public Dialog()
        {
            InitializeComponent();

            // get the current database loaded line types
            var db = HostApplicationServices.WorkingDatabase;
            using (var tr = db.TransactionManager.StartOpenCloseTransaction())
            {
                source = ((LinetypeTable)tr.GetObject(db.LinetypeTableId, OpenMode.ForRead))
                    .Cast<ObjectId>()
                    .Select(id => (LinetypeTableRecord)tr.GetObject(id, OpenMode.ForRead))
                    .Select(lt => new Linetype(lt.Name, lt.ObjectId))
                    .ToArray();
            }

            // set the combo box binding and properties
            comboLinetypes.DropDownStyle = ComboBoxStyle.DropDownList;
            comboLinetypes.DataSource = source;
            comboLinetypes.DisplayMember = "Name";
            comboLinetypes.DrawMode = DrawMode.OwnerDrawFixed;
            comboLinetypes.DrawItem += ComboLinetypesnDrawItem;
        }

        // draw the combo box items
        private void ComboLinetypesnDrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index > -1)
            {
                var item = source[e.Index];
                var bounds = e.Bounds;
                int height = bounds.Height;
                int width = bounds.Width;
                Graphics graphics = e.Graphics;
                e.DrawBackground();
                graphics.DrawString(
                    item.Name,
                    e.Font,
                    new SolidBrush(e.ForeColor),
                    new Rectangle(bounds.Left, bounds.Top, 120, height));

                IntPtr iPtr = Autodesk.AutoCAD.Internal.Utils.DrawLineTypePattern(
                    item.ObjectId,
                    0, 0, width - 120, height);
                var img = System.Drawing.Image.FromHbitmap(iPtr);
                graphics.DrawImage(img, bounds.Left + 120, bounds.Top);
                e.DrawFocusRectangle();
            }
        }
    }

dialog.png



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 4

MassimilianoBaratta
Contributor
Contributor
Accepted solution

Dear Gilles,

 

thank you for the previous collaboration.

 

Now, with the autocad 2019, the command  DrawLineTypePatter is replace with DrawLineType, but not work me.

the image is all black. Do you have a idea about?

 

Best regards

0 Likes