winform 大数据量查询滚动条设计
代码部分

 Code
Codeusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace LogTallyManage.Attemp
{
public partial class frmProgressBar : Form
{
internal Form m_frmOwner = null; // 进度条窗口的主窗口
internal Thread m_thdPBar = null; // 执行操作的线程
internal bool m_bAutoProgress = false; // 自动滚动进度条
internal string m_sExceptionMessage = null; // 异常信息
private int m_iTenthSecondNum = 0; // 执行的分秒数
public frmProgressBar()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void tmCheckThread_Tick(object sender, EventArgs e)
{
tmCheckThread.Tick -= tmCheckThread_Tick;
if (ThreadState.Stopped == m_thdPBar.ThreadState) // 如果线程操作结束,自动关闭进度条窗口
{
if (null == m_sExceptionMessage)
{
pgbWait.Value = pgbWait.Maximum;
Thread.Sleep(200);
}
else // 线程异常退出
{
//Utility.ShowError(m_sExceptionMessage);
m_sExceptionMessage = null;
}
this.Close();
}
if (m_bAutoProgress && pgbWait.Value < pgbWait.Maximum) // 自动滚动进度条
pgbWait.Value++;
else if (m_bAutoProgress)
pgbWait.Value = 0;
m_iTenthSecondNum++;
if (0 == m_iTenthSecondNum % 10)
lblTime.Text = (m_iTenthSecondNum / 10).ToString() + "秒";
tmCheckThread.Tick += tmCheckThread_Tick;
}
}
public class clsProgressBarThread
{
#region 线程方法
public delegate void DlgMothed();
private DlgMothed m_dlgThreadFun = null; // 要在线程中执行的方法委托
protected void pDlgThreadFun()
{
try
{
m_dlgThreadFun();
}
catch (Exception ex)
{
m_frmPgb.m_sExceptionMessage = "发生如下异常,请联系软件开发者!\n" + ex.Message;
}
}
internal DlgMothed ThreadFun
{
set // 设置线程中执行的方法
{
m_dlgThreadFun = value;
}
}
internal DlgMothed MainThreadFun
{
set // 设置在线程中要执行的主线程的方法
{
if (m_frmPgb.m_frmOwner.InvokeRequired)
m_frmPgb.m_frmOwner.Invoke(value);
}
}
#endregion
#region 构造函数
private frmProgressBar m_frmPgb = null; // 进度条窗口
private clsProgressBarThread() { }
public clsProgressBarThread(Form AOwner)
{
m_frmPgb = new frmProgressBar();
m_frmPgb.m_frmOwner = AOwner;
}
public clsProgressBarThread(Form AOwner, bool AAutoProgress)
: this(AOwner)
{
m_frmPgb.m_bAutoProgress = AAutoProgress;
}
#endregion
public bool StartShow() // 显示进度条
{
m_frmPgb.m_thdPBar = new Thread(new ThreadStart(pDlgThreadFun));
m_frmPgb.m_thdPBar.Start();
m_frmPgb.ShowDialog(m_frmPgb.m_frmOwner);
m_frmPgb.m_thdPBar.Abort();
return true;
}
#region 进度条属性
public string ShowInfo
{
get
{
return m_frmPgb.lblInfo.Text;
}
set
{
m_frmPgb.lblInfo.Text = value;
}
}
public int MaxinumShowValue
{
get
{
return m_frmPgb.pgbWait.Maximum;
}
set
{
if (!m_frmPgb.m_bAutoProgress)
{
m_frmPgb.pgbWait.Maximum = value;
m_frmPgb.pgbWait.Value = 0;
}
}
}
public int CurrenShowValue
{
get
{
return m_frmPgb.pgbWait.Value;
}
set
{
if (!m_frmPgb.m_bAutoProgress)
m_frmPgb.pgbWait.Value = value;
}
}
#endregion
}
}
界面部分

 Code
Codenamespace LogTallyManage.Attemp
{
partial class frmProgressBar
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.pgbWait = new System.Windows.Forms.ProgressBar();
this.button1 = new System.Windows.Forms.Button();
this.lblInfo = new System.Windows.Forms.Label();
this.tmCheckThread = new System.Windows.Forms.Timer(this.components);
this.lblTime = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// pgbWait
//
this.pgbWait.Location = new System.Drawing.Point(13, 34);
this.pgbWait.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.pgbWait.Name = "pgbWait";
this.pgbWait.Size = new System.Drawing.Size(341, 31);
this.pgbWait.TabIndex = 0;
//
// button1
//
this.button1.ImageIndex = 0;
this.button1.Location = new System.Drawing.Point(362, 34);
this.button1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(82, 31);
this.button1.TabIndex = 1;
this.button1.Text = "取消";
this.button1.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// lblInfo
//
this.lblInfo.AutoSize = true;
this.lblInfo.Location = new System.Drawing.Point(13, 9);
this.lblInfo.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lblInfo.Name = "lblInfo";
this.lblInfo.Size = new System.Drawing.Size(57, 20);
this.lblInfo.TabIndex = 2;
this.lblInfo.Text = "请稍等";
//
// tmCheckThread
//
this.tmCheckThread.Enabled = true;
this.tmCheckThread.Tick += new System.EventHandler(this.tmCheckThread_Tick);
//
// lblTime
//
this.lblTime.AutoSize = true;
this.lblTime.Location = new System.Drawing.Point(308, 9);
this.lblTime.Name = "lblTime";
this.lblTime.Size = new System.Drawing.Size(34, 20);
this.lblTime.TabIndex = 3;
this.lblTime.Text = "0秒";
//
// frmProgressBar
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.ClientSize = new System.Drawing.Size(458, 74);
this.Controls.Add(this.lblTime);
this.Controls.Add(this.lblInfo);
this.Controls.Add(this.button1);
this.Controls.Add(this.pgbWait);
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.Name = "frmProgressBar";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "等待

 ";
";this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
internal System.Windows.Forms.Label lblInfo;
internal System.Windows.Forms.ProgressBar pgbWait;
private System.Windows.Forms.Timer tmCheckThread;
private System.Windows.Forms.Label lblTime;
}
}
查询按钮click调用代码如下:
delegate{}里面写你查询的方法

 Code
CodeDataTable dt=new DataTable ();
clsProgressBarThread oPBar = new clsProgressBarThread(this, true);
oPBar.ShowInfo = "正在查询,请稍候

 ";
";oPBar.ThreadFun = delegate
{
dt = ECI.PL.Query.ProcessSql(sql);
};
oPBar.StartShow();
FrmReportList frmR = new FrmReportList(dt);
frmR.ShowDialog();
 
                    
                 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号