public FormMain() { InitializeComponent(); if (components == null) components = new Container(); #if DEBUG Text += " " + Path.GetPathRoot(Application.ExecutablePath); #endif this.FormClosing += (o, e) => { if (m_appLogic.State != AppLogicState.WaitingForDropFile) { if (MessageBox.Show("正在传输文件,确认要退出吗?", "确认", MessageBoxButtons.YesNo) != DialogResult.Yes) { e.Cancel = true; } } }; m_textBox.MouseDoubleClick += FormMain_MouseDoubleClick; m_textBox.KeyUp += FormMain_KeyUp; m_appLogic = new AppLogic(); m_appLogic.FileTransFound += s => { return MessageBox.Show(s, "提示", MessageBoxButtons.YesNo) == DialogResult.Yes; }; m_appLogic.ErrorHandler += error => MessageBox.Show(error); m_appLogic.ProgressChanged += (percent) => { if (m_enableUpdateSpecUI != null && m_enableUpdateSpecUI.HasSig) { switch (m_appLogic.State) { case AppLogicState.SendingFile: m_textBox.Lines = new string[] { "正在发送文件:", m_appLogic.TransingFileName, "已发送文件(个):", m_appLogic.TransedFileCount.ToString(), "总耗时(秒):", m_appLogic.TransSeconds.ToString(), }; break; case AppLogicState.ReceivingFile: m_textBox.Lines = new string[] { "正在接受文件:", m_appLogic.TransingFileName, "已接受文件(个):", m_appLogic.TransedFileCount.ToString(), "总耗时(秒):", m_appLogic.TransSeconds.ToString(), }; break; default: break; } m_enableUpdateSpecUI.ClearSig(); } ((ToolStripProgressBar)m_statusStrip.Items[0]).Value = percent; }; m_appLogic.StateChanged += () => { switch (m_appLogic.State) { case AppLogicState.WaitingForDropFile: m_textBox.Lines = new string[]{ "拖拽文件到这里" }; ((ToolStripProgressBar)m_statusStrip.Items[0]).Value = 0; if (m_enableUpdateSpecUI != null) { m_enableUpdateSpecUI.Dispose(); m_enableUpdateSpecUI = null; } break; case AppLogicState.SendingFile: case AppLogicState.ReceivingFile: Program.Assert(m_enableUpdateSpecUI == null); m_enableUpdateSpecUI = new AutoResetSig(250); break; default: break; } }; m_textBox.Lines = new string[] { "拖拽文件到这里" }; { Timer t = new Timer(); this.components.Add(t); t.Tick += (o, e) => { if (m_appLogic.State != AppLogicState.WaitingForDropFile) { ((ToolStripStatusLabel)m_statusStrip.Items[1]).Text = string.Format("{0,3} MB/S", m_appLogic.TransSpeed); } }; t.Interval = 1000; t.Start(); } }
public FormMain() { InitializeComponent(); if (components == null) { components = new Container(); } #if DEBUG Text += " " + Path.GetPathRoot(Application.ExecutablePath); #endif this.FormClosing += (o, e) => { if (m_appLogic.State != AppLogicState.WaitingForDropFile) { if (MessageBox.Show("正在传输文件,确认要退出吗?", "确认", MessageBoxButtons.YesNo) != DialogResult.Yes) { e.Cancel = true; } } }; m_textBox.MouseDoubleClick += FormMain_MouseDoubleClick; m_textBox.KeyUp += FormMain_KeyUp; m_appLogic = new AppLogic(); m_appLogic.FileTransFound += s => { return(MessageBox.Show(s, "提示", MessageBoxButtons.YesNo) == DialogResult.Yes); }; m_appLogic.ErrorHandler += error => MessageBox.Show(error); m_appLogic.ProgressChanged += (percent) => { if (m_enableUpdateSpecUI != null && m_enableUpdateSpecUI.HasSig) { switch (m_appLogic.State) { case AppLogicState.SendingFile: m_textBox.Lines = new string[] { "正在发送文件:", m_appLogic.TransingFileName, "已发送文件(个):", m_appLogic.TransedFileCount.ToString(), "总耗时(秒):", m_appLogic.TransSeconds.ToString(), }; break; case AppLogicState.ReceivingFile: m_textBox.Lines = new string[] { "正在接受文件:", m_appLogic.TransingFileName, "已接受文件(个):", m_appLogic.TransedFileCount.ToString(), "总耗时(秒):", m_appLogic.TransSeconds.ToString(), }; break; default: break; } m_enableUpdateSpecUI.ClearSig(); } ((ToolStripProgressBar)m_statusStrip.Items[0]).Value = percent; }; m_appLogic.StateChanged += () => { switch (m_appLogic.State) { case AppLogicState.WaitingForDropFile: m_textBox.Lines = new string[] { "拖拽文件到这里" }; ((ToolStripProgressBar)m_statusStrip.Items[0]).Value = 0; if (m_enableUpdateSpecUI != null) { m_enableUpdateSpecUI.Dispose(); m_enableUpdateSpecUI = null; } break; case AppLogicState.SendingFile: case AppLogicState.ReceivingFile: Program.Assert(m_enableUpdateSpecUI == null); m_enableUpdateSpecUI = new AutoResetSig(250); break; default: break; } }; m_textBox.Lines = new string[] { "拖拽文件到这里" }; { Timer t = new Timer(); this.components.Add(t); t.Tick += (o, e) => { if (m_appLogic.State != AppLogicState.WaitingForDropFile) { ((ToolStripStatusLabel)m_statusStrip.Items[1]).Text = string.Format("{0,3} MB/S", m_appLogic.TransSpeed); } }; t.Interval = 1000; t.Start(); } }