如何查找文字?
C#开发|冯美娟|2018-07-25 15:15
-
回答:
private void FindText(string str) { // 创建选择集对象 MxDrawSelectionSet ss = new MxDrawSelectionSet(); // 创建过滤对象. MxDrawResbuf spFilte = new MxDrawResbuf(); // 把文字对象,当着过滤条件. spFilte.AddStringEx("TEXT,MTEXT", 5020); // 得到图上,所有文字对象. ss.Select2(MCAD_McSelect.mcSelectionSetAll, null, null, null, spFilte); // 遍历每个文字. bool bFind = false; for (int i = 0; i < ss.Count; i++) { MxDrawEntity ent = ss.Item(i); if (ent == null) continue; if (ent.ObjectName == "McDbText") { // 是一个文字 MxDrawText text = (MxDrawText)ent; string sTxt = text.TextString; if (sTxt == str) { // 找到把文字放到视区中间. axMxDrawX1.PutEntityInView(ent.ObjectID, 300); var dLen = axMxDrawX1.ViewLongToDocCoord(80); // 绘制一个标记圆. axMxDrawX1.DrawVectorCircle(text.Position.x, text.Position.y, dLen, 65280); bFind = true; } } else if (ent.ObjectName == "McDbMText") { // 找到一个多行文字 MxDrawResbuf param = new MxDrawResbuf(); param.AddObjectId(ent.ObjectID); MxDrawMText mtext = (MxDrawMText)ent; // 得到多行文字中的,文字内容. MxDrawResbuf ret = (MxDrawResbuf)axMxDrawX1.CallEx("Mx_GetMTextContent", param); if (ret.AtString(0) == "Ok") { if (ret.AtString(1) == str) { // 把文字放到视区. axMxDrawX1.PutEntityInView(ent.ObjectID, 300); var dLen = axMxDrawX1.ViewLongToDocCoord(80); // 绘制一个标记圆. axMxDrawX1.DrawVectorCircle(mtext.Location.x, mtext.Location.y, dLen, 65280); bFind = true; break; } } } } if (bFind) MessageBox.Show("找到文字"); else MessageBox.Show("没有找到文字"); }