Windows 窗体代码未执行?
好吧,我这里有一个奇怪的。我正在尝试使用 Windows 窗体制作一个基本的平铺引擎,但我的一些代码只是......没有发生。我将发布有问题的块。
private void MapEditor_Load(object sender, EventArgs e)
{
LoadImageList();
FixScrollBarScales();
cboCodeValues.Items.Clear();
cboCodeValues.Items.Add("ENEMY");
cboCodeValues.Items.Add("CHEST");
cboCodeValues.Items.Add("NPC");
for (int x = 0; x < 100; x++)
cboMapNumber.Items.Add(x.ToString().PadLeft(3, '0'));
cboMapNumber.SelectedIndex = 0;
TileMap.EditorMode = true;
backgroundToolStripMenuItem.Checked = true;
}
这应该在表单加载时调用,对吧?该代码深入到 LoadImageList(),其中包含:
private void LoadImageList()
{
string filepath = Application.StartupPath +
@"\Content\Textures\IndoorTileSet.png";
Bitmap tileSheet = new Bitmap(filepath);
int tilecount = 0;
for(int y = 0; y < tileSheet.Height / TileMap.TileHeight; y++)
{
for(int x = 0; x < tileSheet.Width / TileMap.TileWidth; x++)
{
Bitmap newBitmap = tileSheet.Clone(
new System.Drawing.Rectangle(
x * TileMap.TileWidth,
y * TileMap.TileHeight,
TileMap.TileWidth,
TileMap.TileHeight),
System.Drawing.Imaging.PixelFormat.DontCare);
imgListTiles.Images.Add(newBitmap);
string itemName = "";
if(tilecount == 0)
itemName = "Empty";
if(tilecount == 1)
itemName = "Floor";
listTiles.Items.Add(new ListViewItem(itemName, tilecount++));
}
}
}
位图正确加载,但整个 MapEditor_Load 方法停止工作。 tileCount似乎是调试器中的局部变量,其值为0,但调试器永远不会在分配给它的行上执行断点。我完全不知道为什么它会这样做,这让我发疯。有什么帮助吗? 哦,我将位图加载放在 try/catch 块中只是为了看看它是否以奇怪的方式处理异常,但我没有运气。它没有抛出异常。在用更新版本替换 IndoorTileSet 后,我立即开始遇到此问题。我尝试过干净重建,但没有成功。
我读过一些关于一个人有类似问题的文章,他最终不得不将某些东西声明为类的实例,但是这篇文章不够详细,我不知道这是否是我出错的地方,或者我可能会做什么必须声明为实例才能工作......或者实例甚至意味着什么,真的。
Ok, I've got a weird one here. I'm trying to make a basic tile engine using a windows form, but some of my code is just...not happening. I'll post the chunks in question.
private void MapEditor_Load(object sender, EventArgs e)
{
LoadImageList();
FixScrollBarScales();
cboCodeValues.Items.Clear();
cboCodeValues.Items.Add("ENEMY");
cboCodeValues.Items.Add("CHEST");
cboCodeValues.Items.Add("NPC");
for (int x = 0; x < 100; x++)
cboMapNumber.Items.Add(x.ToString().PadLeft(3, '0'));
cboMapNumber.SelectedIndex = 0;
TileMap.EditorMode = true;
backgroundToolStripMenuItem.Checked = true;
}
This should be called when the form loads, right? The code dives into LoadImageList(), which contains:
private void LoadImageList()
{
string filepath = Application.StartupPath +
@"\Content\Textures\IndoorTileSet.png";
Bitmap tileSheet = new Bitmap(filepath);
int tilecount = 0;
for(int y = 0; y < tileSheet.Height / TileMap.TileHeight; y++)
{
for(int x = 0; x < tileSheet.Width / TileMap.TileWidth; x++)
{
Bitmap newBitmap = tileSheet.Clone(
new System.Drawing.Rectangle(
x * TileMap.TileWidth,
y * TileMap.TileHeight,
TileMap.TileWidth,
TileMap.TileHeight),
System.Drawing.Imaging.PixelFormat.DontCare);
imgListTiles.Images.Add(newBitmap);
string itemName = "";
if(tilecount == 0)
itemName = "Empty";
if(tilecount == 1)
itemName = "Floor";
listTiles.Items.Add(new ListViewItem(itemName, tilecount++));
}
}
}
The bitmap loads correctly, but then the entire MapEditor_Load method just stops working. tileCount seems to be a local variable in the debugger, and its value is 0, but the debugger never executes the breakpoint on the line which it is assigned. I have absolutely no idea why it would do this, and it's driving me nuts. Any help?
Oh, I put the bitmap load in a try/catch block just to see if it was handling an exception in a weird way, but I had no luck. It's not throwing an exception. I began having this problem immediately after replacing my IndoorTileSet with an updated version. I've tried a clean rebuild, with no success.
I read something about a person having a similar problem, who wound up having to declare something as an Instance of a class, but the post wasn't detailed enough for me to know if that's where I'm going wrong, or what I might have to declare as an Instance for it to work...or what an Instance even means, really.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定
LoadImageList
() 方法中的代码,但我建议您使用 BackgroundWorker 或 Control.Invoke 使您的应用程序响应更快。I'm not sure about the code in
LoadImageList
() method but I suggest you to use BackgroundWorker or Control.Invoke to make your application more responsive.试试这个:
Try this :
从表面上看,问题是我的位图代码抛出 FileNotFound 异常,这意味着我的文件路径错误。我能处理好。程序实际上没有抛出异常,并且似乎忽略了代码,这是 64 位操作系统无法处理所有实例中的异常调用的问题。有关详细信息以及解决该问题的修补程序的链接,可以在 此网站。
The problem is, superficially, that my Bitmap code is throwing an FileNotFound exception, which means I've got a bad filepath. I can handle that. The issue of the program not actually throwing exceptions, and seeming to ignore code, is an issue with 64-bit operating systems not being able to handle exception calls in all instances. The details, and a link to a hotfix to solve the issue, can be found at this site.