내 PictureBox를 내부에 십자가를 끌고있다,하지만 나는 그것이 십자가를 끌고있다 g.DrawRectangle()
를 사용하는 경우 아래와 같이왜 DrawRectangle 내가 10 개 사각형을 그릴려고
을 내가 정점 개체를 만드는거야 해당 꼭지점에 대해 Rectangle
객체를 반환하는 getRectangle() 함수가 포함되어 있습니다.
나는이 객체를 만들고 pictureBox
에 사각형으로 표시하려고합니다.
여기
private System.Drawing.Graphics g;
private System.Drawing.Pen pen1 = new System.Drawing.Pen(Color.Blue, 2F);
public Form1()
{
InitializeComponent();
pictureBox.Dock = DockStyle.Fill;
pictureBox.BackColor = Color.White;
}
private void paintPictureBox(object sender, PaintEventArgs e)
{
// Draw the vertex on the screen
g = e.Graphics;
// Create new graph object
Graph newGraph = new Graph();
for (int i = 0; i <= 10; i++)
{
// Tried this code too, but it still shows the cross
//g.DrawRectangle(pen1, Rectangle(10,10,10,10);
g.DrawRectangle(pen1, newGraph.verteces[0,i].getRectangle());
}
}
코드 정점 클래스 내 코드의
class Vertex
{
public int locationX;
public int locationY;
public int height = 10;
public int width = 10;
// Empty overload constructor
public Vertex()
{
}
// Constructor for Vertex
public Vertex(int locX, int locY)
{
// Set the variables
this.locationX = locX;
this.locationY = locY;
}
public Rectangle getRectangle()
{
// Create a rectangle out of the vertex information
return new Rectangle(locationX, locationY, width, height);
}
}
코드 그래프 클래스의
class Graph
{
//verteces;
public Vertex[,] verteces = new Vertex[10, 10];
public Graph()
{
// Generate the graph, create the vertexs
for (int i = 0; i <= 10; i++)
{
// Create 10 Vertexes with different coordinates
verteces[0, i] = new Vertex(0, i);
}
}
}
내가 아는 전부는 예외가 귀하의 코드 또는 코드에서 발생했는지 여부입니다. 문제를 디버그하기 위해 무언가를 그릴 때까지 일부 논리를 제거하십시오. –
다른 사람들이 언급했듯이 "십자가"는 예외가 throw 된 결과입니다. 스택에있는 예외를 삼키지 않으면 쉽게 찾아서 수정할 수있는 버그가 코드에있을 수 있습니다. 결국 중요한 교훈이 있습니다. –