再次双消息框 [英] double message box again

查看:57
本文介绍了再次双消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我又遇到了这个问题。第一个我能够使用

调试器来看它被调用两次,所以我修复了它。不过,这个

的时间,调试器没有显示它(MessageBox.Show)是两次调用
,有时它*不会被调用两次!所以我不知道为什么会发生这种情况。这是代码。我希望它看起来不错,如果不是

我会以不同的方式发布它。

命名空间CharacterManager

{

公共部分类frmCharacterManager:表格

{

private string incompatibleSelection =" Incompatible Selection" ;;



#region类验证器


公共布尔IsBarbarian()

{

if(rdoBarbarian.Checked == true)

返回true;


返回false;

}


公共布尔IsBard( )

{

如果(rdoBard.Checked == true)

返回true;


返回false;

}


public bool IsCleric()

{

if(rdoCleric。检查== true)

返回true;


返回false;

}


public bool IsDruid()

{

if(rdoDruid.Checked == true)

return true;


返回false;

}

公共布尔IsFighter()

{

如果(rdoFemale.Checked == true)

返回true;


返回false;

}


public bool IsMonk()

{

if(rdoMonk.Checked == true)

返回true;


返回false;

}


public bool IsPaladin()

{

if(rdoPaladin.Checked == true)

返回true;


返回false;

}


public bool IsRanger()

{

if(rdoRanger.Checked == true)

返回true;


返回false;

}


public bool IsRogue()

{

if(rdoRogue.Checked == true)

返回true;


返回false;

}


public bool IsSorcerer ()

{

if(rdoSorcerer.Checked == true)

返回true;


返回false;

}


public bool IsWizard()

{

if(rdoWizard.Checked == true)

返回true;


返回false;

}

#endregion


#region对齐验证器


public bool IsLawful()

{

if(rdoLawfulGood.Checked == true || rdoLawfulNeutral.Checked == true

|| rdoLawfulEvil.Checked == true)

返回true;


返回false;

}


public bool IsChaotic()

{

if(rdoChaoticGood.Checked == true || rdoChaoticNeutral.Checked ==

true || rdoChaoticEvil.Checked == true)

返回true;


返回false;

}


public bool IsGood()

{

if(rdoLawfulGood.Checked == true || rdoNeutralGood.Checked == true

|| rdoChaoticGood.Checked == true)

返回true;


返回false;

}


public bool IsNeutral()

{

if(rdoLawfulNeutral.Checked == true || rdoNeutralGood.Checked ==

true || rdoTrueNeutral.Checked == true || rdoNeutralEvil.Checked == true

|| rdoChaoticNeutral.Checked == true)

return true;


返回false;

}


公共布尔IsEvil()

{

if( rdoLawfulEvil.Checked == true || rdoNeutralEvil.Checked == true

|| rdoChaoticEvil.Checked == true)

返回true;


返回false;

}

#endregion


#region竞赛活动处理程序


private void rdoHuman_CheckedChanged(object sender,EventArgs e)

{

SuggestClass();

}


private void rdoElf_CheckedChanged(object sender,EventArgs e)

{

SuggestClass();

}


private void rdoDwarf_CheckedChanged(object sender,EventArgs e)

{

SuggestClass();

}


private void rdoHalfElf_CheckedChanged(object sender,EventArgs e)

{

SuggestClass();

}


private void rdoGnome_CheckedChanged(object sender,EventArgs e)< br $>
{

SuggestClass();

}


private void rdoHalfling_CheckedChanged(object sender,EventArgs e )

{

SuggestClass();

}


private void rdoHalfOrc_CheckedChanged(object sender,EventArgs e)

{

SuggestClass();

}

#endregion


private void btnReorganizeAlignments_Click(object sender,EventArgs e)

{

Point p1;

点数p2;


p1 = rdoLawfulNeutral.Location;

p2 = rdoNeutralGood.Location;


rdoLawfulNeutral.Location = p2;

rdoNeutralGood.Location = p1;


p1 = rdoLawfulEvil.Location;

p2 = rdoChaoticGood .Location;


rdoLawfulEvil.Location = p2;

rdoChaoticGood.Location = p1;


p1 = rdoNeutralEvil .Location;

p2 = rdoChaoticNeutral.Location;


rdoNeutralEvil.Location = p2;

rdoChaoticNeutral.Location = p1; < br $>
}


public void SuggestClass()

{

if(chkSuggestedClass.Checked == true) )

{

string noClass =&quo t; No Recommended Class" ;;


if(rdoHuman.Checked == true)

{

string noHumanClass ="人类没有建议的课程。;

stsStatusLabel.Text = noHumanClass;

MessageBox.Show(noHumanClass,noClass);

}


if(rdoElf.Checked == true)

rdoWizard.Checked = true;


if( rdoDwarf.Checked == true)

rdoFighter.Checked = true;


if(rdoHalfElf.Checked == true)

{

string noHalfElfClass ="没有推荐的等级为

半精灵。" ;;

stsStatusLabel.Text = noHalfElfClass;

MessageBox.Show(noHalfElfClass,noClass);

}


if(rdoGnome.Checked == true)

rdoWizard.Checked = true;


if(rdoHalfling.Checked == true)

rdoRogue.Checked = true;


if(rdoHalfOrc.Checked == true)

rdoBarbarian.Checked = true ;

}

}

}

}

解决方案

" John Salerno" <乔****** @ NOSPAMgmail.com>写道:

public bool IsBarbarian()
[...]
公共布尔IsBard()
[...]
public bool IsCleric()
[...]
公共布尔IsDruid()
[...]




嘿,我知道这不是你要问的,但是你有没有考虑过

让你的各种角色类继承自一个抽象的

角色?然后你可以使用是和是。运算符并利用

继承,而不是大量的IsThis,IsThat类型代码。


P.


Paul E Collins写道:

" John Salerno" <乔****** @ NOSPAMgmail.com>写道:

public bool IsBarbarian()
[...]
公共布尔IsBard()
[...]
公共布尔IsCleric()
[...]
公共布尔IsDruid()
[...]



嘿,我知道这不是你要问的,但是你有没有考虑过让你的各种角色类继承自一个抽象的角色?然后你可以使用是和是。运算符并利用
继承,而不是大量的IsThis,IsThat类型代码。

P.




实际上,我从一开始就想到了这一点,但并不是真的知道如何做到这一点。我喜欢这样的建议,因为我总是试图让所有东西尽可能高效和简化。

你能举例说明我如何实现是运营商?




" John Salerno" <乔****** @ NOSPAMgmail.com>在留言中写道

news:cd ******************** @ rcn.net ...

Ok ,我再次遇到这个问题。第一个我能够使用
调试器来看它被调用两次,所以我修复了它。但是,这个时间,调试器没有显示它(MessageBox.Show)两次调用
,有时它*不会被调用两次!所以我不知道为什么它正在发生。这是代码。我希望它看起来不错,如果不是我会以不同的方式发布它。

命名空间CharacterManager
{
公共部分类frmCharacterManager:表格
{
私人字符串incompatibleSelection ="不兼容的选择" ;;

#region类验证员

公共bool IsBarbarian()
{
if(rdoBarbarian.Checked == true)
返回true;

返回false;
}


一些编码指针。您不必使用== true;只是

if(rdoBarbarian.Checked)就足够了。你也可以使用


返回rdoBarbarian.Checked;

公共布尔IsLawful()
如果(rdoLawfulGood.Checked = = true || rdoLawfulNeutral.Checked == true ||
rdoLawfulEvil.Checked == true)
返回true;

返回false;
}


所有这些测试都应该真正分离出来。


Validator v = new Validator();

v。 ChaoticGood = rdoChaoticGood.Checked;

v.ChaoticNeutral = rdoChaoticNeutral.Checked;


那么你可以问对象


v.IsChaotic


#region赛事活动处理程序

私人void rdoHuman_CheckedChanged(object sender,EventArgs e)
{
SuggestClass();
}
private void rdoElf_CheckedChanged(object sender,EventArgs e)
{
SuggestClass();
}


您可以为所有人使用相同的事件处理程序CheckChanged事件,因为他们

都做同样的事情:SuggestClass()
私有空btnReorganizeAlignments_Click(对象发送者,EventArgs e)
{
点p1;
点p2;

p1 = rdoLawfulNeutral.Location;
p2 = rdoNeutralGood.Location;

rdoLawfulNeutral.Location = p2;
rdoNeutralGood.Location = p1;




从未见过任何与您实际问题相关的代码!!


SP


Ok, I''m having this problem again. The first I was able to use the
debugger to see that it was being called twice, so I fixed that. This
time, though, the debugger does not show it (MessageBox.Show) being
called twice, and sometimes it *doesn''t* get called twice! So I don''t
know why it''s happening. Here''s the code. I hope it looks ok, if not
I''ll post it a different way.
namespace CharacterManager
{
public partial class frmCharacterManager : Form
{
private string incompatibleSelection = "Incompatible Selection";


#region Class validators

public bool IsBarbarian()
{
if (rdoBarbarian.Checked == true)
return true;

return false;
}

public bool IsBard()
{
if (rdoBard.Checked == true)
return true;

return false;
}

public bool IsCleric()
{
if (rdoCleric.Checked == true)
return true;

return false;
}

public bool IsDruid()
{
if (rdoDruid.Checked == true)
return true;

return false;
}

public bool IsFighter()
{
if (rdoFemale.Checked == true)
return true;

return false;
}

public bool IsMonk()
{
if (rdoMonk.Checked == true)
return true;

return false;
}

public bool IsPaladin()
{
if (rdoPaladin.Checked == true)
return true;

return false;
}

public bool IsRanger()
{
if (rdoRanger.Checked == true)
return true;

return false;
}

public bool IsRogue()
{
if (rdoRogue.Checked == true)
return true;

return false;
}

public bool IsSorcerer()
{
if (rdoSorcerer.Checked == true)
return true;

return false;
}

public bool IsWizard()
{
if (rdoWizard.Checked == true)
return true;

return false;
}
#endregion

#region Alignment validators

public bool IsLawful()
{
if (rdoLawfulGood.Checked == true || rdoLawfulNeutral.Checked == true
|| rdoLawfulEvil.Checked == true)
return true;

return false;
}

public bool IsChaotic()
{
if (rdoChaoticGood.Checked == true || rdoChaoticNeutral.Checked ==
true || rdoChaoticEvil.Checked == true)
return true;

return false;
}

public bool IsGood()
{
if (rdoLawfulGood.Checked == true || rdoNeutralGood.Checked == true
|| rdoChaoticGood.Checked == true)
return true;

return false;
}

public bool IsNeutral()
{
if (rdoLawfulNeutral.Checked == true || rdoNeutralGood.Checked ==
true || rdoTrueNeutral.Checked == true || rdoNeutralEvil.Checked == true
|| rdoChaoticNeutral.Checked == true)
return true;

return false;
}

public bool IsEvil()
{
if (rdoLawfulEvil.Checked == true || rdoNeutralEvil.Checked == true
|| rdoChaoticEvil.Checked == true)
return true;

return false;
}
#endregion

#region Race event handlers

private void rdoHuman_CheckedChanged(object sender, EventArgs e)
{
SuggestClass();
}

private void rdoElf_CheckedChanged(object sender, EventArgs e)
{
SuggestClass();
}

private void rdoDwarf_CheckedChanged(object sender, EventArgs e)
{
SuggestClass();
}

private void rdoHalfElf_CheckedChanged(object sender, EventArgs e)
{
SuggestClass();
}

private void rdoGnome_CheckedChanged(object sender, EventArgs e)
{
SuggestClass();
}

private void rdoHalfling_CheckedChanged(object sender, EventArgs e)
{
SuggestClass();
}

private void rdoHalfOrc_CheckedChanged(object sender, EventArgs e)
{
SuggestClass();
}
#endregion

private void btnReorganizeAlignments_Click(object sender, EventArgs e)
{
Point p1;
Point p2;

p1 = rdoLawfulNeutral.Location;
p2 = rdoNeutralGood.Location;

rdoLawfulNeutral.Location = p2;
rdoNeutralGood.Location = p1;

p1 = rdoLawfulEvil.Location;
p2 = rdoChaoticGood.Location;

rdoLawfulEvil.Location = p2;
rdoChaoticGood.Location = p1;

p1 = rdoNeutralEvil.Location;
p2 = rdoChaoticNeutral.Location;

rdoNeutralEvil.Location = p2;
rdoChaoticNeutral.Location = p1;
}

public void SuggestClass()
{
if (chkSuggestedClass.Checked == true)
{
string noClass = "No Recommended Class";

if (rdoHuman.Checked == true)
{
string noHumanClass = "There is no suggested class for Humans.";
stsStatusLabel.Text = noHumanClass;
MessageBox.Show(noHumanClass, noClass);
}

if (rdoElf.Checked == true)
rdoWizard.Checked = true;

if (rdoDwarf.Checked == true)
rdoFighter.Checked = true;

if (rdoHalfElf.Checked == true)
{
string noHalfElfClass = "There is no recommended class for
Half-Elves.";
stsStatusLabel.Text = noHalfElfClass;
MessageBox.Show(noHalfElfClass, noClass);
}

if (rdoGnome.Checked == true)
rdoWizard.Checked = true;

if (rdoHalfling.Checked == true)
rdoRogue.Checked = true;

if (rdoHalfOrc.Checked == true)
rdoBarbarian.Checked = true;
}
}
}
}

解决方案

"John Salerno" <jo******@NOSPAMgmail.com> wrote:

public bool IsBarbarian()
[...]
public bool IsBard()
[...]
public bool IsCleric()
[...]
public bool IsDruid()
[...]



Hey, I know this isn''t what you''re asking, but have you considered
making your various character classes inherit from an abstract
Character? Then you could use the "is" operator and take advantage of
inheritance, rather than having masses of IsThis, IsThat type code.

P.


Paul E Collins wrote:

"John Salerno" <jo******@NOSPAMgmail.com> wrote:

public bool IsBarbarian()
[...]
public bool IsBard()
[...]
public bool IsCleric()
[...]
public bool IsDruid()
[...]


Hey, I know this isn''t what you''re asking, but have you considered
making your various character classes inherit from an abstract
Character? Then you could use the "is" operator and take advantage of
inheritance, rather than having masses of IsThis, IsThat type code.

P.



Actually, I thought of this right from the beginning but didn''t really
know how to do it. I love suggestions like this, because I''m always
trying to make everything as efficient and streamlined as possible.
Could you give an example of how I might implement the is operator for this?



"John Salerno" <jo******@NOSPAMgmail.com> wrote in message
news:cd********************@rcn.net...

Ok, I''m having this problem again. The first I was able to use the
debugger to see that it was being called twice, so I fixed that. This
time, though, the debugger does not show it (MessageBox.Show) being called
twice, and sometimes it *doesn''t* get called twice! So I don''t know why
it''s happening. Here''s the code. I hope it looks ok, if not I''ll post it a
different way.
namespace CharacterManager
{
public partial class frmCharacterManager : Form
{
private string incompatibleSelection = "Incompatible Selection";

#region Class validators

public bool IsBarbarian()
{
if (rdoBarbarian.Checked == true)
return true;

return false;
}
Some coding pointers. You do not have to use "== true" just
if(rdoBarbarian.Checked) is sufficient. You could also just use

return rdoBarbarian.Checked;
public bool IsLawful()
{
if (rdoLawfulGood.Checked == true || rdoLawfulNeutral.Checked == true ||
rdoLawfulEvil.Checked == true)
return true;

return false;
}
All these tests should really be separated out to some object.

Validator v = new Validator();
v.ChaoticGood = rdoChaoticGood.Checked;
v.ChaoticNeutral = rdoChaoticNeutral.Checked;

then you can ask the object

v.IsChaotic

and keep the complexities of the tests where they belong.

#region Race event handlers

private void rdoHuman_CheckedChanged(object sender, EventArgs e)
{
SuggestClass();
}

private void rdoElf_CheckedChanged(object sender, EventArgs e)
{
SuggestClass();
}
You can use the same event handler for all the CheckChanged events as they
all do the same thing: SuggestClass()

private void btnReorganizeAlignments_Click(object sender, EventArgs e)
{
Point p1;
Point p2;

p1 = rdoLawfulNeutral.Location;
p2 = rdoNeutralGood.Location;

rdoLawfulNeutral.Location = p2;
rdoNeutralGood.Location = p1;



Never saw any code that related to you actual question!!

SP


这篇关于再次双消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆