C#에서 작성한 메서드에서 일부 비트 맵을 렌더링 중입니다.DrawText 메서드의 현재 컨텍스트 오류에서 이름 "e"가 존재하지 않습니다.
TextRenderer.DrawText()
메서드를 사용하여 비트 맵에 텍스트를 그리는 법을 배우고 있습니다. 다음과 같이 코드 조각은 다음과 같습니다
TextRenderer.DrawText(e.Graphics, "Regular Text", SystemFonts.DefaultFont, new Point(10, 10), SystemColors.ControlText);
그러나, e.Graphics
에서, 나는 The name "e" does not exist under the current context
하는 오류를 제공하고 있습니다.
무엇이 문제 일 수 있는지 궁금합니다.
내 Render 메서드에서 코드, Rhino의 공통 라이브러리 사용 : 코드는 위의 메뚜기 캔버스에 히트 맵을 렌더링과 같이
protected override void Render(Grasshopper.GUI.Canvas.GH_Canvas canvas, Graphics graphics, Grasshopper.GUI.Canvas.GH_CanvasChannel channel) {
base.Render(canvas, graphics, channel);
if (channel == Grasshopper.GUI.Canvas.GH_CanvasChannel.Wires) {
var comp = Owner as KT_HeatmapComponent;
if (comp == null)
return;
List<HeatMap> maps = comp.CachedHeatmaps;
if (maps == null)
return;
if (maps.Count == 0)
return;
int x = Convert.ToInt32(Bounds.X + Bounds.Width/2);
int y = Convert.ToInt32(Bounds.Bottom + 10);
for (int i = 0; i < maps.Count; i++) {
Bitmap image = maps[i].Image;
if (image == null)
continue;
Rectangle mapBounds = new Rectangle(x, y, maps[i].Width, maps[i].Height);
mapBounds.X -= mapBounds.Width/2;
Rectangle edgeBounds = mapBounds;
edgeBounds.Inflate(4, 4);
GH_Capsule capsule = GH_Capsule.CreateCapsule(edgeBounds, GH_Palette.Normal);
capsule.Render(graphics, Selected, false, false);
capsule.Dispose();
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
graphics.DrawImage(image, mapBounds);
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Default;
graphics.DrawRectangle(Pens.Black, mapBounds);
TextRenderer.DrawText(e.Graphics, "Regular Text", SystemFonts.DefaultFont, new Point(10, 10), SystemColors.ControlText);
y = edgeBounds.Bottom - (mapBounds.Height) - 4;
}
}
}
:
을 그러나 제목과 x/y 축 텍스트를 추가하는 데 관심이 있습니다.
여기에서 * e *가 예상됩니까? 여기에는 컨텍스트가 없습니다. 이벤트 처리기에 있습니까? 다른 것? –
아마도 스 니펫은 페인트 핸들러에서 가져온 것이고 'e'라는 이벤트 객체가 전달되었을 것입니다. –
방금 배운 이벤트 처리기 arg입니다. 아니요, 이것은 이벤트 핸들러가 아니므로 잘못된 방법을 사용하여 비트 맵에 텍스트를 그릴 수 있습니다. 나는 좀 더 구체적으로 편집 할 것이다. – theGreenCabbage