winform 为何在运行时,用鼠标拖动窗体没反应???

erictang2003 2004-03-25 11:18:16
启动后,程序开始访问EXCEL 文件,但读取过程中,用鼠标拖动窗体没反应???
知道所有读取完成后,才能拖动.
怎样解决?
...全文
180 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
erictang2003 2004-03-27
  • 打赏
  • 举报
回复
up
HNU 2004-03-26
  • 打赏
  • 举报
回复


save & up
marvelstack 2004-03-26
  • 打赏
  • 举报
回复
要使用多线程就行了,
如下面是我写的代码,
楼主可以看看,对你会有帮助
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;

namespace WindowsApplication1
{
//定义代理
public delegate void OccuredHandler(string msg);
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
//定义事件
public event OccuredHandler Occured;
//定义线程
Thread myThread;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
//注册事件
this.Occured +=new OccuredHandler(Form1_Occured);
myThread = new Thread(new ThreadStart(RunThread));

}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(184, 32);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "运行";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 112);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(192, 23);
this.label1.TabIndex = 1;
this.label1.Text = "label1";
//
// button2
//
this.button2.Location = new System.Drawing.Point(184, 72);
this.button2.Name = "button2";
this.button2.TabIndex = 2;
this.button2.Text = "退出";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
//线程方法
public void RunThread()
{
for(int i=0;i<1000000;i++)
{
this.label1.Text = i.ToString();
}
//激发事件
Occured("终于结束了,大哥快冒烟了!");
}
//线程结束通知函数
private void Form1_Occured(string msg)
{
MessageBox.Show(msg);
}

private void button1_Click(object sender, System.EventArgs e)
{
myThread.Start();
this.button1.Enabled = false;
}

private void button2_Click(object sender, System.EventArgs e)
{
//if(myThread.ThreadState!=ThreadState.Stopped||myThread.ThreadState!=ThreadState.Aborted)
myThread.Abort();
Application.Exit();
}
}
}
erictang2003 2004-03-26
  • 打赏
  • 举报
回复
up
yanransoft 2004-03-26
  • 打赏
  • 举报
回复
多线程操作
Napoleo 2004-03-26
  • 打赏
  • 举报
回复
用后台线程啦,比异步代理简单100倍
erictang2003 2004-03-26
  • 打赏
  • 举报
回复
up
HNU 2004-03-26
  • 打赏
  • 举报
回复

save
erictang2003 2004-03-26
  • 打赏
  • 举报
回复
有没有真正可用的代码?
wolftop 2004-03-25
  • 打赏
  • 举报
回复
开个线程处理打开和读取EXCEL~!
huangsuipeng 2004-03-25
  • 打赏
  • 举报
回复
用异步委托
delegate int Count(int a);
Count del =new Count(你的函数);
IAsyncReslut ar =del.BeginInvoke(10000,null,null);
.............
if(ar.IsCompleted)
{
int count=del.EndInvoke(ar);
}
else
{
以后再试

}
也可以使用CALLBACK方式
delegate int Count(int a);
Count del =new Count(你的函数);
AsyncCallback ab=new AsyncCallback(yourcallback)
IAsyncReslut ar =del.BeginInvoke(10000,ab,null);
.............
恶猫 2004-03-25
  • 打赏
  • 举报
回复
你读取是用的循环?还是...一次全部读取完??

如果是循环.

那么在循环内部加:

Application.DoEvents() (自己看大小写,我忘了)

如果是一次全部读完,
那你就要新建一个线程,另外读取那个文件了..

ipromise 2004-03-25
  • 打赏
  • 举报
回复
试着加一个读取线程,交给后台处理

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧