#region progressBar实时显示进度
private void button1_Click(object sender, EventArgs e)
{
int i = 10000;
progressBar1.Minimum = 0;
progressBar1.Maximum = i;
for (int k = 0; k < i; k++)
{
progressBar1.Value += 1;
Application.DoEvents(); //label1实时显示,而非处理完成后再显示
label1.Text = progressBar1.Value.ToString() ;
}
}
#endregion
#region 打开文件选择对话框
private void menuFileLoad_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Open Photo";
dlg.Filter = "jpg files(*.jpg)|*.jpg|All files(*.*)|*.*";
if (dlg.ShowDialog() == DialogResult.OK)
{
try
{
pbxPhoto.Image = new Bitmap(dlg.OpenFile());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
dlg.Dispose();
}
#endregion
#region 菜单选中或可选
private void menuImage_DropDownOpening(object sender, EventArgs e)
{
ProcessImageOpening(sender as ToolStripDropDownItem);
}
private void ProcessImageOpening(ToolStripDropDownItem parent)
{
if (parent != null)
{
string enumval = pbxPhoto.SizeMode.ToString();
foreach (ToolStripMenuItem item in parent.DropDownItems)
{
item.Enabled = (pbxPhoto.Image != null);
item.Checked = item.Tag.Equals(enumval);
}
}
}
#endregion
Winform常用的一些功能收集(持续更新),布布扣,bubuko.com
Winform常用的一些功能收集(持续更新)