질문 : 어떻게 폼이 아닌 Panel에 사각형을 그립니다. 사용 (그래픽 g = this.panel1.CreateGraphics()) {}Panel C# Form에 직사각형을 그립니다.
을
: 나는 이런 식으로 뭔가를 할 필요가 있으리라 믿고있어
/*
* based on a some flags i determine which shape i want to draw.
* All shapes are stored in a list. I loop through the list
* and call each shape specific draw method - as shown below:.
*
*/
namespace myDrawProgram
{
private void panelArea_Paint(object sender, PaintEventArgs e)
{
if (drawWithPaint == true)
{
Pen p = new Pen(Color.Blue);
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
if (IsShapeRectangle == true)
{
e.Graphics.DrawRectangle(p, rect);
}
else if (IsShapeCircle == true)
{
e.Graphics.DrawEllipse(p, rect);
}
}
foreach (Shapes shape in listOfShapes)
{
shape.Draw(e.Graphics);
}
}
}
/*
* In another file i have my class which deals with
* drawing rectangles. It is as follows:
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using SETPaint;
namespace myDrawProgram
{
class TheRectangles : Shapes
{
public Rectangle MyRect { set; get; }
public TheRectangles(Rectangle rect, Color colour, Color boarderColour, Int32 brushThickness)
: base(colour, boarderColour, brushThickness)
{
MyRect = rect;
}
public override void Draw(Graphics g)
{
base.Draw(g);
g.FillRectangle(new SolidBrush(Shapes.c), MyRect);
g.DrawRectangle(new Pen(bc, MyBrushThickness), MyRect);
}
}
}
: 여기처럼 내 코드는 모습입니다 난 내 코드에 관해서는 이것을 구현하는 방법을 모르겠다. ...
그림 논리를 패널 클래스에 넣고 양식에 넣지 않으시겠습니까? 그것이 그렇듯, 당신의 질문은 나에게 의미가 없습니다. –
사각형에 그려지는 양식을 원하지 않습니다. 패널에 표시하고 싶습니다. 현재 패널에 그릴 때 아무 것도 나타나지 않습니다. 이해가 되니? 희망이 너무 .. – BigBug
당신이 쳐다 보 : [http://stackoverflow.com/questions/282838/drawing-on-top-of-controls-inside-a-panel-c-winforms](http://stackoverflow .com/questions/282838/drawing-on-controls-inside-a-panel-c-winforms) – Udomaki