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.
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();
}
}
}