CAD 도면의 입면에 다른 유형의 기호를 배치하는 유틸리티 클래스를 만들고 있습니다. 그렇게하는 GraphicsPath 객체를 처리해야하는지 확인하고 싶습니다.GraphicsPath를 사용 후 폐기해야합니까?
getCircle 함수 내부에서 아래 코드는 myPath "GraphicsPath"개체를 AddStringToPath 함수에 전달하고 있음을 보여줍니다.
myPath 그래픽 객체를 ref로 전달하기 때문에 using() {} 범위를 사용할 수 없습니다.
이 디자인을 사용하는 것이 좋습니까? 아니면 가비지 수집을 보장하기 위해 다른 방식으로 진행해야합니까?
GraphicsPath getCircle(Graphics dc, string text = "")
{
GraphicsPath myPath = new GraphicsPath();
myPath.AddEllipse(symbolCircle);
AddStringToPath(dc, ref myPath, text);
return myPath;
}
void AddStringToPath(Graphics dc, ref GraphicsPath path, string text)
{
SizeF textSize = dc.MeasureString(text, elevFont);
var centerX = (path.GetBounds().Width/2) - (textSize.Width/2);
var centerY = (path.GetBounds().Height/2) - (textSize.Height/2);
// Add the string to the path.
path.AddString(text,
elevFont.FontFamily,
(int)elevFont.Style,
elevFont.Size,
new PointF(centerX + 2, centerY + 2),
StringFormat.GenericDefault);
}
감사합니다. 더 나은 명명 규칙을 제공합니다. –
더 좋은데,'var path ='또는'GraphicsPath path ='? – barlop