📄 mainform.cs
字号:
protected void cboButtons_OnSelectedIndexChanged (object sender, System.EventArgs e)
{
grpDefault.Enabled=true;
int index=cboButtons.SelectedIndex;
switch (index)
{
case 0: // OK
btnDefault1.Visible = false;
btnDefault2.Visible = false;
btnDefault3.Visible = false;
cbnDefault1.Checked = false;
cbnDefault2.Checked = false;
cbnDefault3.Checked = false;
cbnDefault1.Visible = false;
cbnDefault2.Visible = false;
cbnDefault3.Visible = false;
this.pbIcon.Visible = false;
btnSample1.Visible = false;
btnSample2.Visible = false;
btnSample3.Visible = true;
btnSample4.Visible = false;
btnSample5.Visible = false;
btnSample3.Text = "OK";
break;
case 1: // OK/Cancel
cbnDefault1.Checked = false;
cbnDefault2.Checked = false;
cbnDefault3.Checked = false;
btnDefault1.Text = "OK";
btnDefault2.Text = "Cancel";
btnDefault1.Visible = true;
btnDefault2.Visible = true;
btnDefault3.Visible = false;
cbnDefault1.Visible = true;
cbnDefault2.Visible = true;
cbnDefault3.Visible = false;
txtCode.Text = BuildMessageBox();
btnSample1.Visible = false;
btnSample2.Visible = true;
btnSample3.Visible = false;
btnSample4.Visible = true;
btnSample5.Visible = false;
btnSample2.Text = "OK";
btnSample4.Text = "Cancel";
break;
case 2: // Retry/Cancel
cbnDefault1.Checked = false;
cbnDefault2.Checked = false;
cbnDefault3.Checked = false;
btnDefault1.Text = "Retry";
btnDefault2.Text = "Cancel";
btnDefault1.Visible = true;
btnDefault2.Visible = true;
btnDefault3.Visible = false;
cbnDefault1.Visible = true;
cbnDefault2.Visible = true;
cbnDefault3.Visible = false;
txtCode.Text=BuildMessageBox();
btnSample1.Visible = false;
btnSample2.Visible = true;
btnSample3.Visible = false;
btnSample4.Visible = true;
btnSample5.Visible = false;
btnSample2.Text = "Retry";
btnSample4.Text = "Cancel";
break;
case 3: // Abort/Retry/Ignore
cbnDefault1.Checked = false;
cbnDefault2.Checked = false;
cbnDefault3.Checked = false;
btnDefault1.Text = "Abort";
btnDefault2.Text = "Retry";
btnDefault3.Text = "Cancel";
btnDefault1.Visible = true;
btnDefault2.Visible = true;
btnDefault3.Visible = true;
cbnDefault1.Visible = true;
cbnDefault2.Visible = true;
cbnDefault3.Visible = true;
txtCode.Text=BuildMessageBox();
btnSample1.Visible = true;
btnSample2.Visible = false;
btnSample3.Visible = true;
btnSample4.Visible = false;
btnSample5.Visible = true;
btnSample1.Text = "Abort";
btnSample3.Text = "Retry";
btnSample5.Text = "Ignore";
break;
case 4: // Yes/No
cbnDefault1.Checked = false;
cbnDefault2.Checked = false;
cbnDefault3.Checked = false;
btnDefault1.Text = "Yes";
btnDefault2.Text = "No";
btnDefault1.Visible = true;
btnDefault2.Visible = true;
btnDefault3.Visible = false;
cbnDefault1.Visible = true;
cbnDefault2.Visible = true;
cbnDefault3.Visible = false;
txtCode.Text=BuildMessageBox();
btnSample1.Visible = false;
btnSample2.Visible = true;
btnSample3.Visible = false;
btnSample4.Visible = true;
btnSample5.Visible = false;
btnSample2.Text = "Yes";
btnSample4.Text = "No";
break;
case 5: // Yes/No/Cancel
cbnDefault1.Checked = false;
cbnDefault2.Checked = false;
cbnDefault3.Checked = false;
btnDefault1.Text = "Yes";
btnDefault2.Text = "No";
btnDefault3.Text = "Cancel";
btnDefault1.Visible = true;
btnDefault2.Visible = true;
btnDefault3.Visible = true;
cbnDefault1.Visible = true;
cbnDefault2.Visible = true;
cbnDefault3.Visible = true;
txtCode.Text=BuildMessageBox();
btnSample1.Visible = true;
btnSample2.Visible = false;
btnSample3.Visible = true;
btnSample4.Visible = false;
btnSample5.Visible = true;
btnSample1.Text = "Yes";
btnSample3.Text = "No";
btnSample5.Text = "Cancel";
break;
}
string str = BuildMessageBox();
OnMessageBoxChanged (sender, e);
}
private string BuildMessageBox()
{
string result = "";
if (cbnVisualBasic.Checked)
{
result = BuildForVisualBasic();
}
else if (cbnVisualCPP.Checked)
result = BuildForCPlusPlus();
else
result = BuildForCSharp();
return (result);
}
private string BuildForCPlusPlus()
{
string strButtons = "";
string result = "";
string strSwitch="";
if (cbnUseMFC.Checked)
result = "AfxMessageBox(\"";
else
result = "MessageBox (NULL, \"";
string [] lines = txtMessage.Lines;
for (int x = 0; x < lines.Length; ++x)
{
result += lines[x];
if (x < (lines.Length - 1))
result += "\\n";
}
result+="\",\"";
result+=txtCaption.Text+"\"";
switch(cboButtons.SelectedIndex)
{
default:
break;
case 0:
strSwitch = "\tcase IDOK:";
strSwitch += "\r\n\t\tbreak;";
break;
case 1: // OK/Cancel
strButtons = "MB_OKCANCEL";
btnStyle=MessageBoxButtons.OKCancel;
strSwitch ="\tcase IDOK:";
strSwitch+="\r\n\t\tbreak;";
strSwitch+="\r\n\tcase IDCANCEL:";
strSwitch+="\r\n\t\tbreak;";
break;
case 2: //Retry/Cancel
strButtons = "MB_RETRYCANCEL";
btnStyle=MessageBoxButtons.RetryCancel;
strSwitch ="\tcase IDRETRY:";
strSwitch+="\r\n\t\tbreak;";
strSwitch+="\r\n\tcase IDCANCEL:";
strSwitch+="\r\n\t\tbreak;";
break;
case 3://Abort/Retry/Ignore
strButtons="MB_ABORTRETRYIGNORE";
btnStyle=MessageBoxButtons.AbortRetryIgnore;
strSwitch ="\tcase IDABORT:";
strSwitch+="\r\n\t\tbreak;";
strSwitch+="\r\n\tcase IDRETRY:";
strSwitch+="\r\n\t\tbreak;";
strSwitch+="\r\n\tcase IDIGNORE:";
strSwitch+="\r\n\t\tbreak;";
break;
case 4: // Yes/No
strButtons = "MB_YESNO";
btnStyle = MessageBoxButtons.YesNo;
strSwitch ="\tcase IDYES:";
strSwitch+="\r\n\t\tbreak;";
strSwitch+="\r\n\tcase IDNO:";
strSwitch+="\r\n\t\tbreak;";
break;
case 5://Yes/No/Cancel
strButtons = "MB_YESNOCANCEL";
btnStyle=MessageBoxButtons.YesNoCancel;
strSwitch ="\tcase IDYES:";
strSwitch+="\r\n\t\tbreak;";
strSwitch+="\r\n\tcase IDNO:";
strSwitch+="\r\n\t\tbreak;";
strSwitch+="\r\n\tcase IDCANCEL:";
strSwitch+="\r\n\t\tbreak;";
break;
}
if ((listBox1.SelectedIndex > 0) && (strButtons != ""))
strButtons += " | ";
switch (listBox1.SelectedIndex)
{
case 0:
this.pbIcon.Visible = false;
break;
case 1:
strButtons += "MB_ICONINFORMATION";
iconStyle = MessageBoxIcon.Information;
this.pbIcon.Visible = true;
this.pbIcon.Image = ((System.Drawing.Bitmap)(imageList1.Images[0]));
break;
case 2:
strButtons += "MB_ICONQUESTION";
iconStyle = MessageBoxIcon.Question;
this.pbIcon.Visible = true;
this.pbIcon.Image = ((System.Drawing.Bitmap)(imageList1.Images[1]));
break;
case 3:
strButtons += "MB_ICONEXCLAMATION";
iconStyle = MessageBoxIcon.Exclamation;
this.pbIcon.Visible = true;
this.pbIcon.Image = ((System.Drawing.Bitmap)(imageList1.Images[2]));
break;
case 4:
strButtons += "MB_ICONERROR";
iconStyle = MessageBoxIcon.Error;
this.pbIcon.Visible = true;
this.pbIcon.Image = ((System.Drawing.Bitmap)(imageList1.Images[3]));
break;
}
int iDefButton = 0;
if (cbnDefault1.Checked)
iDefButton = 1;
if (cbnDefault2.Checked)
iDefButton = 2;
if (cbnDefault3.Checked)
iDefButton = 3;
if (iDefButton > 0)
{
if (strButtons != "")
strButtons += " | ";
strButtons += "MB_DEFBUTTON";
strButtons += iDefButton.ToString();
}
switch (iDefButton)
{
case 1:
btnDefault = MessageBoxDefaultButton.Button1;
break;
case 2:
btnDefault = MessageBoxDefaultButton.Button2;
break;
case 3:
btnDefault = MessageBoxDefaultButton.Button3;
break;
}
if (strButtons != "")
{
result += ", ";
result += strButtons;
}
result += ");";
if (cbnUseReturnVar.Checked)
{
if (cbnDeclareIt.Checked)
result = "int " + txtVariable.Text + " = " + result;
else
result = txtVariable.Text + " = " + result;
if (cbnBuildSwitch.Checked)
{
result += "\r\n";
result += "switch(" + txtVariable.Text + ")";
result += "\r\n{";
result += "\r\n";
result += strSwitch;
result += "\r\n}";
}
}
return (result);
}
private string BuildForVisualBasic()
{
string strIcon = "";
string strButtons = "";
string strDefButton = "";
string strSwitch = "";
string result = "";
if (cbnUseReturnVar.Checked)
{
if (cbnDeclareIt.Checked)
result="dim " + txtVariable.Text + " as int32\r\n";
result += txtVariable.Text + " = ";
}
result += "MessageBox.Show(\"";
string [] lines = txtMessage.Lines;
string strUnion;
if (cbnVisualBasic.Checked)
{
strUnion = " ";
}
else
{
strUnion = "\\n";
}
for (int x = 0; x < lines.Length; ++x)
{
result += lines[x];
if (x < (lines.Length - 1))
result += strUnion;
}
result += "\", \"";
result += txtCaption.Text + "\"";
ButtonsAreUs (ref strButtons, ref strSwitch, ref strIcon, ref strDefButton);
if (strButtons.Length > 0)
{
result += ", ";
result += strButtons;
}
if (strIcon.Length > 0)
{
result += ", ";
result += strIcon;
}
if (strDefButton.Length > 0)
{
result += ", ";
result += strDefButton;
}
result += ")";
if (cbnUseReturnVar.Checked && cbnBuildSwitch.Checked)
{
result += "\r\n";
strSwitch = "";
strSwitch = "Select " + txtVariable.Text + "\r\n";
switch(cboButtons.SelectedIndex)
{
case 0: //OK
strSwitch += "\tCase DialogResult.OK\r\n";
strSwitch += "\t\t' Add your code here\r\n";
break;
case 1: //OK/Cancel
strSwitch += "\tCase DialogResult.OK\r\n";
strSwitch += "\t\t' Add your code here\r\n";
strSwitch += "\tCase DialogResult.Cancel\r\n";
strSwitch += "\t\t' Add your code here\r\n";
break;
case 2: //Retry/Cancel
strSwitch += "\tCase DialogResult.Retry\r\n";
strSwitch += "\t\t' Add your code here\r\n";
strSwitch += "\tCase DialogResult.Cancel\r\n";
strSwitch += "\t\t' Add your code here\r\n";
break;
case 3: //Abort/Retry/Ignore
strSwitch += "\tCase DialogResult.Abort\r\n";
strSwitch += "\t\t' Add your code here\r\n";
strSwitch += "\tCase DialogResult.Retry\r\n";
strSwitch += "\t\t' Add your code here\r\n";
strSwitch += "\tCase DialogResult.Ignore\r\n";
strSwitch += "\t\t' Add your code here\r\n";
break;
case 4://Yes/No
strSwitch += "\tCase DialogResult.Yes\r\n";
strSwitch += "\t\t' Add your code here\r\n";
strSwitch += "\tCase DialogResult.No\r\n";
strSwitch += "\t\t' Add your code here\r\n";
break;
case 5://Yes/No/Cancel
strSwitch += "\tCase DialogResult.Yes\r\n";
strSwitch += "\t\t' Add your code here\r\n";
strSwitch += "\tCase DialogResult.No\r\n";
strSwitch += "\t\t' Add your code here\r\n";
strSwitch += "\tCase DialogResult.Cancel\r\n";
strSwitch += "\t\t' Add your code here\r\n";
break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -