Author Topic: LineType display in a form  (Read 8184 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8722
  • AKA Daniel
Re: LineType display in a form
« Reply #15 on: May 21, 2010, 02:07:43 AM »
Thats it!!!! you rock  8-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: LineType display in a form
« Reply #16 on: May 21, 2010, 04:12:00 AM »

Excellent Mark !!
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: LineType display in a form
« Reply #17 on: May 21, 2010, 06:40:18 AM »
Thank you very much Mark, I was rebuilding the wheel... :oops:
Speaking English as a French Frog

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: LineType display in a form
« Reply #18 on: May 22, 2010, 08:09:37 AM »
Hi,

I had some time today to try to implement it for a ListView control.
For those who are interested, here's a sample code. The ListView.OwnerDraw property have to be set to true.

Thanks again to Mark and others too.

Code: [Select]
using System;
using System.Drawing;
using System.Windows.Forms;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Internal;
using Autodesk.AutoCAD.Runtime;

namespace LinetypesDisplay
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Database db = HostApplicationServices.WorkingDatabase;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                LinetypeTable ltt =
                    (LinetypeTable)tr.GetObject(db.LinetypeTableId, OpenMode.ForRead);
                foreach (ObjectId id in ltt)
                {
                    LinetypeTableRecord lttr =
                        (LinetypeTableRecord)tr.GetObject(id, OpenMode.ForRead);
                    string ltName = lttr.Name;
                    if (!ltName.Equals("Continuous", StringComparison.CurrentCultureIgnoreCase) &&
                        !ltName.Equals("ByBlock", StringComparison.CurrentCultureIgnoreCase) &&
                        !ltName.Equals("ByLayer", StringComparison.CurrentCultureIgnoreCase))
                    {
                        ListViewItem lvi = new ListViewItem(
                            new string[] { lttr.Name, string.Empty, lttr.AsciiDescription });
                        this.listView1.Items.Add(lvi);
                    }
                }
            }
        }

        private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
        {
            e.DrawDefault = true;
        }

        private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            Database db = HostApplicationServices.WorkingDatabase;
            if (e.ColumnIndex == 1)
            {
                Rectangle rect = e.Bounds;
                rect.Location = new Point(0, 0);
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    LinetypeTable ltt =
                        (LinetypeTable)tr.GetObject(db.LinetypeTableId, OpenMode.ForRead);
                    string ltName = e.Item.Text;
                    IntPtr iPtr =
                        Utils.DrawLineTypePattern(ltt[ltName], rect.Left, rect.Top, rect.Right, rect.Bottom);
                    System.Drawing.Image img = System.Drawing.Image.FromHbitmap(iPtr);
                    e.Graphics.DrawImage(img, e.Bounds.Location);
                }
            }
            else
                e.DrawDefault = true;
        }

        [CommandMethod("test")]
        public void test()
        {
            this.ShowDialog();
        }
    }
}
« Last Edit: May 22, 2010, 08:12:38 AM by gile »
Speaking English as a French Frog

Chumplybum

  • Newt
  • Posts: 97
Re: LineType display in a form
« Reply #19 on: May 22, 2010, 09:46:06 PM »
no worries Gile, happy to help


cheers,

LE3

  • Guest
Re: LineType display in a form
« Reply #20 on: May 24, 2010, 12:09:48 PM »
Interesting !

Have not tried, but just a quick question, will this work properly without any issues as when you try to use for example some controls inside of Autodesk.AutoCAD.Internal
and in particular (for my case) the TrueColorPicker for the color combobox.

It simple crashes or put in a non responding mode Visual Studio (2005 or 2008).... BTW

I simple end up removing/commenting out the calls to avoid this, and to be able to jump to the form designer...


LE!

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: LineType display in a form
« Reply #21 on: May 24, 2010, 01:35:59 PM »
Hi Luis,

As far as I tried, I had no problem using this code (or something similar in the prog I'm working on) except it doesn't display the appearance on versions prior than 2010 but doesn't crash.
No need to reference acmgdinternal.dll with 2010, it's included in acmgd.dll.
Speaking English as a French Frog

LE3

  • Guest
Re: LineType display in a form
« Reply #22 on: May 24, 2010, 01:40:17 PM »
Hi Luis,

As far as I tried, I had no problem using this code (or something similar in the prog I'm working on) except it doesn't display the appearance on versions prior than 2010 but doesn't crash.
No need to reference acmgdinternal.dll with 2010, it's included in acmgd.dll.

Hi Gile,

Thanks! - well in my case it simple crashes VS when I try to use the Autodesk.AutoCAD.Internal.TrueColorPicker - testing on 2005 and 2008 pro VS versions...  :-(

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: LineType display in a form
« Reply #23 on: May 24, 2010, 02:05:07 PM »
I had no problem with VS 2008 Standard too.
Speaking English as a French Frog

LE3

  • Guest
Re: LineType display in a form
« Reply #24 on: May 24, 2010, 02:07:53 PM »
I had no problem with VS 2008 Standard too.
must be something in particular with TrueColorPicker... (or me)