📄 mainform.cs
字号:
strSwitch += "End Select\r\n";
result += strSwitch;
}
return (result);
}
private string BuildForVisualBasicOld()
{
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 = "";
switch(cboButtons.SelectedIndex)
{
case 0: //OK
strSwitch = "If " + txtVariable.Text + " = dialogresult.OK Then\r\n";
strSwitch += "\t' Add your code here\r\n";
strSwitch += "End If";
break;
case 1: //OK/Cancel
strSwitch = "If " + txtVariable.Text + " = DialogResult.OK Then\r\n";
strSwitch += "\t' Add your code here\r\n";
strSwitch += "ElseIf " + txtVariable.Text + " = DialogResult.Cancel\r\n";
strSwitch += "\t' Add your code here\r\n";
strSwitch += "End If";
break;
case 2: //Retry/Cancel
strSwitch = "If " + txtVariable.Text + " = DialogResult.Retry Then\r\n";
strSwitch += "\t' Add your code here\r\n";
strSwitch += "ElseIf " + txtVariable.Text + " = DialogResult.Cancel\r\n";
strSwitch += "\t' Add your code here\r\n";
strSwitch += "End If";
break;
case 3: //Abort/Retry/Ignore
strSwitch = "If " + txtVariable.Text + " = DialogResult.Abort Then\r\n";
strSwitch += "\t' Add your code here\r\n";
strSwitch += "ElseIf " + txtVariable.Text + " = DialogResult.Retry\r\n";
strSwitch += "\t' Add your code here\r\n";
strSwitch += "ElseIf " + txtVariable.Text + " = DialogResult.Ignore\r\n";
strSwitch += "\t' Add your code here\r\n";
strSwitch += "End If";
break;
case 4://Yes/No
strSwitch = "If " + txtVariable.Text + " = DialogResult.Yes Then\r\n";
strSwitch += "\t' Add your code here\r\n";
strSwitch += "ElseIf " + txtVariable.Text + " = DialogResult.No\r\n";
strSwitch += "\t' Add your code here\r\n";
strSwitch += "End If";
break;
case 5://Yes/No/Cancel
strSwitch = "If " + txtVariable.Text + " = DialogResult.Yes Then\r\n";
strSwitch += "\t' Add your code here\r\n";
strSwitch += "ElseIf " + txtVariable.Text + " = DialogResult.No\r\n";
strSwitch += "\t' Add your code here\r\n";
strSwitch += "ElseIf " + txtVariable.Text + " = DialogResult.Cancel\r\n";
strSwitch += "\t' Add your code here\r\n";
strSwitch += "End If";
break;
}
result += strSwitch;
}
return (result);
}
private string BuildForCSharp()
{
string strIcon = "";
string strButtons = "";
string strDefButton = "";
string result = "";
result="MessageBox.Show(\"";
string [] lines = txtMessage.Lines;
for (int x = 0; x < lines.Length; ++x)
{
result += lines[x];
if (x < (lines.Length - 1))
result += "\\n";
}
string strSwitch="";
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)
{
if (cbnDeclareIt.Checked)
result = "DialogResult " + 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 void ButtonsAreUs (ref string strButtons, ref string strSwitch, ref string strIcon, ref string strDefButton)
{
if (cboButtons.SelectedIndex!=-1)
{
switch(cboButtons.SelectedIndex)
{
case 0: //OK
strSwitch ="\tcase DialogResult.OK:";
strSwitch+="\r\n\t\tbreak;";
break;
case 1: //OK/Cancel
strButtons = "MessageBoxButtons.OKCancel";
btnStyle = MessageBoxButtons.OKCancel;
strSwitch = "\tcase DialogResult.OK :";
strSwitch += "\r\n\t\tbreak;";
strSwitch += "\r\n\tcase DialogResult.Cancel :";
strSwitch += "\r\n\t\tbreak;";
break;
case 2: //Retry/Cancel
strButtons = "MessageBoxButtons.RetryCancel";
btnStyle=MessageBoxButtons.RetryCancel;
strSwitch ="\tcase DialogResult.Retry :";
strSwitch+="\r\n\t\tbreak;";
strSwitch+="\r\n\tcase DialogResult.Cancel :";
strSwitch+="\r\n\t\tbreak;";
break;
case 3: //Abort/Retry/Ignore
strButtons="MessageBoxButtons.AbortRetryIgnore";
btnStyle=MessageBoxButtons.AbortRetryIgnore;
strSwitch ="\tcase DialogResult.Abort :";
strSwitch+="\r\n\t\tbreak;";
strSwitch+="\r\n\tcase DialogResult.Retry :";
strSwitch+="\r\n\t\tbreak;";
strSwitch+="\r\n\tcase DialogResult.Ignore :";
strSwitch+="\r\n\t\tbreak;";
break;
case 4: //Yes/No
strButtons = "MessageBoxButtons.YesNo";
btnStyle = MessageBoxButtons.YesNo;
strSwitch ="\tcase DialogResult.Yes :";
strSwitch+="\r\n\t\tbreak;";
strSwitch+="\r\n\tcase DialogResult.No :";
strSwitch+="\r\n\t\tbreak;";
break;
case 5: //Yes/No/Cancel
strButtons = "MessageBoxButtons.YesNoCancel";
btnStyle=MessageBoxButtons.YesNoCancel;
strSwitch ="\tcase DialogResult.Yes :";
strSwitch+="\r\n\t\tbreak;";
strSwitch+="\r\n\tcase DialogResult.No :";
strSwitch+="\r\n\t\tbreak;";
strSwitch+="\r\n\tcase DialogResult.Cancel :";
strSwitch+="\r\n\t\tbreak;";
break;
}
if (cbnDefault1.Checked)
{
strDefButton = "MessageBoxDefaultButton.Button1";
btnDefault = MessageBoxDefaultButton.Button1;
}
else if (cbnDefault2.Checked)
{
strDefButton = "MessageBoxDefaultButton.Button2";
btnDefault = MessageBoxDefaultButton.Button2;
}
else if (cbnDefault3.Checked)
{
strDefButton = "MessageBoxDefaultButton.Button3";
btnDefault = MessageBoxDefaultButton.Button3;
}
}
switch (listBox1.SelectedIndex)
{
case 0:
this.pbIcon.Visible = false;
break;
case 1:
strIcon = "MessageBoxIcon.Information";
iconStyle = MessageBoxIcon.Information;
this.pbIcon.Visible = true;
this.pbIcon.Image = ((System.Drawing.Bitmap)(imageList1.Images[0]));
break;
case 2:
strIcon = "MessageBoxIcon.Question";
iconStyle = MessageBoxIcon.Question;
this.pbIcon.Visible = true;
this.pbIcon.Image = ((System.Drawing.Bitmap)(imageList1.Images[1]));
break;
case 3:
strIcon = "MessageBoxIcon.Exclamation";
iconStyle = MessageBoxIcon.Exclamation;
this.pbIcon.Visible = true;
this.pbIcon.Image = ((System.Drawing.Bitmap)(imageList1.Images[2]));
break;
case 4:
strIcon = "MessageBoxIcon.Error";
iconStyle = MessageBoxIcon.Error;
this.pbIcon.Visible = true;
this.pbIcon.Image = ((System.Drawing.Bitmap)(imageList1.Images[3]));
break;
}
//
// Be sure there are no empty parameters
if ((strDefButton != "") && (strIcon == ""))
{
iconStyle = MessageBoxIcon.None;
strIcon = "MessageBoxIcon.None";
}
if ((strIcon != "") && (strButtons == ""))
{
strButtons = "MessageBoxButtons.OK";
btnStyle = MessageBoxButtons.OK;
}
}
protected void btnPreview_Click (object sender, System.EventArgs e)
{
OnMessageBoxChanged (sender, e);
string str = txtMessage.Text.ToString();
MessageBox.Show(txtMessage.Text,txtCaption.Text,btnStyle, iconStyle, btnDefault);
}
protected void cbnUseReturnVar_CheckedChanged (object sender, System.EventArgs e)
{
txtVariable.Enabled=cbnUseReturnVar.Checked;
cbnBuildSwitch.Enabled=cbnUseReturnVar.Checked;
lblVariable.Enabled=cbnUseReturnVar.Checked;
cbnDeclareIt.Enabled = cbnUseReturnVar.Checked;
OnMessageBoxChanged (sender, e);
}
private void OnListBox1DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
StringFormat format = new StringFormat ();
format.LineAlignment = StringAlignment.Center;
Rectangle rc = e.Bounds;
Brush brush;
bool bSelected = (e.State & DrawItemState.Selected) != 0;
string str = listBox1.GetItemText(listBox1.Items[e.Index]);
int Left = e.Bounds.Left;
int Top = e.Bounds.Top + 3;
int Height = 20;
int Width = 20;
if (e.Index > 0)
imageList1.Draw (e.Graphics, Left, Top, Height, Width, e.Index - 1);
rc.X += Width + 3;
if (bSelected)
{
e.Graphics.FillRectangle (Brushes.DarkBlue, rc);
brush = Brushes.White;
}
else
{
e.Graphics.FillRectangle (Brushes.White, rc);
brush = Brushes.Black;
}
e.Graphics.DrawString (str, listBox1.Font, brush, rc, format);
OnMessageBoxChanged (sender, e);
}
private void listBox1_MeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
{
e.ItemHeight = 24;
e.ItemWidth = listBox1.Width;
}
private void OnLanguageChanged(object sender, System.EventArgs e)
{
CheckBox cbn = (CheckBox) sender;
if (cbn == cbnVisualBasic)
{
cbnVisualBasic.Checked = true;
cbnVisualCPP.Checked = false;
cbnUseMFC.Checked = false;
cbnUseMFC.Enabled = false;
cbnVisualCSharp.Checked = false;
}
else if (cbn == cbnVisualCSharp)
{
cbnVisualBasic.Checked = false;
cbnVisualCPP.Checked = false;
cbnUseMFC.Checked = false;
cbnUseMFC.Enabled = false;
cbnVisualCSharp.Checked = true;
}
else if (cbn == cbnVisualCPP)
{
cbnVisualBasic.Checked = false;
cbnVisualCPP.Checked = true;
cbnUseMFC.Enabled = true;
cbnVisualCSharp.Checked = false;
}
OnMessageBoxChanged (sender, e);
}
private void cbnUseReturnVar_OnCheckChanged(object sender, System.EventArgs e)
{
cbnDeclareIt.Enabled = cbnUseReturnVar.Checked;
cbnBuildSwitch.Enabled = cbnUseReturnVar.Checked;
lblVariable.Enabled = cbnUseReturnVar.Checked;
txtVariable.Enabled = cbnUseReturnVar.Checked;
OnMessageBoxChanged (sender, e);
}
private void btnDefault1_OnClick(object sender, System.EventArgs e)
{
cbnDefault1.Checked ^= true;
cbnDefault2.Checked = false;
cbnDefault3.Checked = false;
OnMessageBoxChanged (sender, e);
}
private void btnDefault2_OnClick(object sender, System.EventArgs e)
{
cbnDefault1.Checked = false;
cbnDefault2.Checked ^= true;
cbnDefault3.Checked = false;
OnMessageBoxChanged (sender, e);
}
private void btnDefault3_OnClick(object sender, System.EventArgs e)
{
cbnDefault1.Checked = false;
cbnDefault2.Checked = false;
cbnDefault3.Checked ^= true;
OnMessageBoxChanged (sender, e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -