关于MessageBox的问题(c#)

fengyedan2 2008-10-25 01:11:10
大家请看这句代码:
DialogResult result = MessageBox.Show("确定要删除这些项目吗?","友情提醒",MessageBoxButtons .YesNo ,MessageBoxIcon .Information );
程序运行到这 句的时候系统出现绿色的错误的提示:
Capacity exceeds maximum capacity.
Parameter name: capacity
捕捉到 System.ArgumentOutOfRangeException
Message="Capacity exceeds maximum capacity.\r\nParameter name: capacity"

请问为什么,该如何解决?
(这问题让人很郁闷,如果直接运行debug下的exe文件,并不报错,但如果你打开程序运行就出现如上错误,请问这会影响程序的稳定性吗?)
...全文
251 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
li45214521 2008-10-26
  • 打赏
  • 举报
回复

private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("确定要删除这些项目吗?","友情提醒",MessageBoxButtons .YesNo ,MessageBoxIcon .Information );
if (result == DialogResult.Yes)
{
foreach (ListViewItem item in this.lvDetails.SelectedItems)
{
File.Delete(item.Name);
}
this.lvDetails.SelectedItems.Clear();
}
catch (Exception ee)
{
MessageBox.Show(ee.Message ,"错误提示",MessageBoxButtons .OK ,MessageBoxIcon.Error);
}
}
}

lovehongyun 2008-10-26
  • 打赏
  • 举报
回复
你设个断点调试一下.看看到底是哪行代码出个错.

然后在分析
li45214521 2008-10-26
  • 打赏
  • 举报
回复

private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("确定要删除这些项目吗?","友情提醒",MessageBoxButtons .YesNo ,MessageBoxIcon .Information );
if (result == DialogResult.Yes)
{
int count = this.lvDetails.SelectedItems.Count;
try
{
ListView.SelectedListViewItemCollection items = this.lvDetails.SelectedItems;
ListViewItem item;
if (count != 0)
{
while (this.lvDetails.SelectedItems.Count > 0) //这里
{
item = items[0];
this.lvDetails.Items.Remove(item);
File.Delete(item.Name);
}
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message ,"错误提示",MessageBoxButtons .OK ,MessageBoxIcon.Error);
}
}
}
sageking2 2008-10-26
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 slimfeng 的回复:]
好像这个错误不是MessageBox引起的,还是检查其他的错误吧
[/Quote]
支持.

[Quote=引用 7 楼 charleyzhu 的回复:]
C# code能说得仔细点吗?这是那段有问题的代码
private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)




程序中可以有中文的吗?
[/Quote]
可以,string 帅哥="你";
Console.Write(帅哥);
charleyzhu 2008-10-25
  • 打赏
  • 举报
回复
能说得仔细点吗?这是那段有问题的代码 
private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)



程序中可以有中文的吗?
止戈而立 2008-10-25
  • 打赏
  • 举报
回复
                    ListViewItem item; 
if (count != 0)
{
while (count > 0)
{
item = items[0];
this.lvDetails.Items.Remove(item);
File.Delete(item.Name);
count--;
}
}
这一段改一下:
foreach(ListViewItem item in items)
{
this.lvDetails.Items.Remove(item);
File.Delete(item.Name);
}


fengyedan2 2008-10-25
  • 打赏
  • 举报
回复
能说得仔细点吗?这是那段有问题的代码
private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("确定要删除这些项目吗?","友情提醒",MessageBoxButtons .YesNo ,MessageBoxIcon .Information );
if (result == DialogResult.Yes)
{
int count = this.lvDetails.SelectedItems.Count;
try
{
ListView.SelectedListViewItemCollection items = this.lvDetails.SelectedItems;
ListViewItem item;
if (count != 0)
{
while (count > 0)
{
item = items[0];
this.lvDetails.Items.Remove(item);
File.Delete(item.Name);
count--;
}
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message ,"错误提示",MessageBoxButtons .OK ,MessageBoxIcon.Error);
}
}
}
gtempzjs 2008-10-25
  • 打赏
  • 举报
回复
我测试了一下 你的那个messagebox没有错误,那么错误应该是你程序的其他部分,你应该好好检查一下。 或者你可以新建一个纯净的新程序 测试一下代码里的messagebox 应该也不会有问题
slimfeng 2008-10-25
  • 打赏
  • 举报
回复
好像这个错误不是MessageBox引起的,还是检查其他的错误吧
止戈而立 2008-10-25
  • 打赏
  • 举报
回复
你的索引控制得有问题。。
止戈而立 2008-10-25
  • 打赏
  • 举报
回复
这句应该不会有问题。。有问题的应该是上一句。。

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧