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