123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- using System;
- using System.Threading;
- using System.Windows.Forms;
- namespace LJLib.Jdt
- {
- public partial class Form_jdt : Form, IJdt, IDisposable
- {
- public static Form_jdt NewWin()
- {
- Form_jdt rslt = new Form_jdt();
- ThreadPool.QueueUserWorkItem(rslt.ShowJdt);
- do
- {
- Thread.Sleep(100);
- } while (!rslt.isShown);
- return rslt;
- }
- private Form_jdt()
- {
- InitializeComponent();
- this.closeJdt = this.CloseJdt;
- this.dispose = this.Dispose;
- this.acceptTotal = this.AcceptTotal;
- this.inc = this.Inc;
- this.setMsg = this.SetMsg;
- this.ole_test = this.label1.Text;
- }
- public bool isShown = false;
- private void ShowJdt(object state)
- {
- this.ShowDialog();
- }
- public void CloseJdt()
- {
- if (this.InvokeRequired)
- {
- this.Invoke(this.closeJdt);
- }
- else
- {
- if (this.isShown)
- {
- this.Close();
- this.isShown = false;
- }
- }
- }
- private string ole_test;
- public void AcceptTotal(int total)
- {
- if (this.InvokeRequired)
- {
- this.Invoke(this.acceptTotal, new object[] { total });
- }
- else
- {
- this.progressBar1.Maximum = total;
- this.Inc(0);
- this.SetMsg(this.ole_test);
- }
- }
- public void Inc(int value)
- {
- if (this.InvokeRequired)
- {
- this.Invoke(this.inc, new object[] { value });
- }
- else
- {
- if (value < this.progressBar1.Minimum)
- {
- value = this.progressBar1.Minimum;
- }
- if (value > this.progressBar1.Maximum)
- {
- value = this.progressBar1.Maximum;
- }
- this.progressBar1.Value = value;
- float progress = (float)this.progressBar1.Value / this.progressBar1.Maximum * 100;
- this.label2.Text = progress.ToString("####0.0") + "%";
- }
- }
- public void SetMsg(string value)
- {
- if (this.InvokeRequired)
- {
- this.Invoke(this.setMsg, new object[] { value });
- }
- else
- {
- this.label1.Text = value;
- }
- }
- private delegate void Delegate1();
- private Delegate1 closeJdt;
- private Delegate1 dispose;
- private delegate void Delegate2(int value);
- private Delegate2 acceptTotal;
- private Delegate2 inc;
- private delegate void Delegate3(string value);
- private Delegate3 setMsg;
- private void Form_jdt_Shown(object sender, EventArgs e)
- {
- this.Focus();
- isShown = true;
- }
- #region IDisposable 成员
- void IDisposable.Dispose()
- {
- if (this.InvokeRequired)
- {
- this.Invoke(this.dispose);
- }
- else
- {
- CloseJdt();
- base.Dispose();
- }
- }
- #endregion
- }
- }
|