你好,这可能是一个愚蠢的问题,但我无法在这里找出问题..这是我用一个块填写表格的代码:
private void drawBackground()
{
Graphics g = genPan.CreateGraphics();
Image Block = Image.FromFile(@"C:\Users\Administrator\Desktop\movment V1\movment V1\images\BrownBlock.png");
float recWidth = Block.Width;
// rectangle width didnt change the name from previous code, it's picture width.
float recHeight = Block.Height;
// rectangle Heightdidnt change the name from previous code, it's picture Height.
float WinWidth = genPan.Width; // genPan is a panel that docked to the form
float WinHeight = genPan.Height;
float curWidth = 0; //indicates where the next block will be placed int the X axis
float curHeight = 0;//indicates where the next block will be placed int the Y axis
while ((curHeight + recHeight) <= WinHeight)
{
if (curWidth >= WinWidth / 3 || curWidth <= WinWidth / 1.5 ||
curHeight >= WinHeight / 3 || curHeight <= WinHeight / 1.5)
{
g.DrawImage(Block, curWidth, curHeight, recWidth , recHeight );
}
curWidth += recWidth;
if ((WinWidth - curWidth) < recWidth)
{
curWidth = 0;
curHeight += 50;
}
}
}
如果我通过一个按钮启动这个函数,它会工作得很好。但是如果我在 InitializeComponent(); 之后启动函数 构造函数或 FORM 显示事件中的方法,当按钮仍在表单上时,它将执行 func 但是块背景将不可见,但灰色将是。但如果我删除按钮,背景将可见。=\
我不明白为什么会发生这种情况,如何解决它以及我做错了什么..谁能解释一下..?