2
我試圖做一個表作爲用戶提交更多的數據:動態地將行在AutoCAD表非常小的字體
public void addRow(String[] data)
{
Transaction tr = doc.TransactionManager.StartTransaction();
DocumentLock docLock = doc.LockDocument();
using (tr)
using (docLock)
{
if (!IsWriteEnabled || !IsReadEnabled) //Committing transactions closes everything for reading and writing so it must be reopened
{
tr.GetObject(this.ObjectId, OpenMode.ForRead);
tr.GetObject(this.ObjectId, OpenMode.ForWrite);
}
if (!data[0].Equals("Mark")) //If the data being added is not the titles of the columns
{
SetSize(NumRows + 1, NumColumns);
}
BlockTable bt = (BlockTable)tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[Autodesk.AutoCAD.DatabaseServices.BlockTableRecord.ModelSpace], OpenMode.ForWrite);
selectedRow = NumRows - 1; //Sets the lowest empty row as the one to be modified
//Adding data to each cell
for (int i = 0; i < data.Length; i++)
{
Cells[selectedRow, i].SetValue(data[i], ParseOption.SetDefaultFormat);
}
GenerateLayout();
//Attempting to add table into drawing. If table already exists and is just being updated the catch statement will realize this and move on
try
{
btr.AppendEntity(this);
tr.AddNewlyCreatedDBObject(this, true);
}
catch (Autodesk.AutoCAD.Runtime.Exception e)
{
SetRowHeight(3); //Sets height of new row
SetColumnWidth(8); //Sets width of new columns
Cells.TextHeight = 1; //Sets height of new text
}
tr.Commit(); //Updating table
}
}
但是什麼最終發生的是,列的標題被加入時創建的表格格式正確(中心對齊,尺寸良好的字體),但添加的所有內容都具有非常小的字體大小。我如何製作它以便字體大小與添加的每個條目相同?
我想你應該明確地設置字體格式,你想要的,就像你要設置行高和其他屬性。表格可能是不可預測的。例如,只需在AutoCAD UI中工作,如果插入一行,它通常會複製顏色和字體的格式,但會丟失數字格式。如果你想確定它會做什麼,請明確。 – Mike 2014-10-16 20:23:32