我有这种方法可以接受多个JobSetting
标志
private void ProcessTheData(string[] dataFiles, PictureBox sender, JobSetting? jobSetting)
Flags枚举是这个
[Flags]
enum JobSetting
{
ForcePrint = 1,
ForceProof = 2,
UseDefault = 4,
SkipImposition = 8,
HighPriority = 16,
SetDP = 32
}
我有一个事件处理程序,它查看CheckboxList,并根据选中的选项构建标志列表。
JobSetting js;
if (((Control)sender).Name.ToLower().Contains("proof"))
{
if (chkbxList_Proof.CheckedItems.Contains("Skip Imposition") && chkbxList_Proof.CheckedItems.Contains("High Priority") && chkbxList_Proof.CheckedItems.Contains("_SetDP"))
{
js = (JobSetting.ForceProof | JobSetting.SkipImposition | JobSetting.HighPriority | JobSetting.SetDP);
}
else if (chkbxList_Proof.CheckedItems.Contains("Skip Imposition") && chkbxList_Proof.CheckedItems.Contains("High Priority"))
{
js = (JobSetting.ForceProof | JobSetting.SkipImposition | JobSetting.HighPriority);
}
else if (chkbxList_Proof.CheckedItems.Contains("Skip Imposition"))
{
js = (JobSetting.ForceProof | JobSetting.SkipImposition);
}
else if (chkbxList_Proof.CheckedItems.Contains("High Priority"))
{
js = (JobSetting.ForceProof | JobSetting.HighPriority);
}
else if (chkbxList_Proof.CheckedItems.Contains("_SetDP"))
{
js = (JobSetting.ForceProof | JobSetting.SetDP);
}
else
{
js = JobSetting.ForceProof;
}
}
所有方法都可以...但是我觉得那是建立我的标志列表的最不有效的方法。
我想以这种方式或任何正确的方式来构建它。
JobSeetings js = JobSetting.ForceProof;
if(chkbxList_Proof.CheckedItems.Contains("Skip Imposition"))
{
js.add(JobSetting.SkipImposition)
}
if(chkbxList_Proof.CheckedItems.Contains("High Priority"))
{
js.add(JobSetting.HighPriority)
}
答案 0 :(得分:1)
您可以根据所检查的项目将标志与按位或进行组合。
JobSetting js = JobSetting.ForceProof;
if (chkbxList_Proof.CheckedItems.Contains("Skip Imposition"))
{
js |= JobSetting.SkipImposition;
}
if (chkbxList_Proof.CheckedItems.Contains("High Priority"))
{
js |= JobSetting.HighPriority;
}
//etc, etc...
如果选中"Skip Imposition"
和"High Priority"
,则js
将等于JobSetting.ForceProof | JobSetting.SkipImposition | JobSetting.HighPriority
。