强烈求教,关于打开窗口的问题。

rextan 2004-08-11 04:33:14
在一个windows应用程序里面,为什么我用函数打开的窗口都是在加载状态或者是停在那里不能操作,而用button事件打开的窗口就正常显示呢。
为这个问题我已经郁闷了好久了,请各位指点指点。
...全文
222 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
rextan 2004-08-12
  • 打赏
  • 举报
回复
up!各位英雄好汉,帮忙调试一下,感激不尽。
csq0516 2004-08-11
  • 打赏
  • 举报
回复
up
rextan 2004-08-11
  • 打赏
  • 举报
回复
再附上窗口代码:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace LedServer
{
/// <summary>
/// LedShow 的摘要说明。
/// </summary>
public class LedShow : System.Windows.Forms.Form
{
private AxSHDocVw.AxWebBrowser axWebBrowserLeftTop;
private AxSHDocVw.AxWebBrowser axWebBrowserLeftBottom;
private AxSHDocVw.AxWebBrowser axWebBrowserRightTop;
private AxSHDocVw.AxWebBrowser axWebBrowserRightBottom;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.PictureBox pictureBox3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public LedShow()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <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()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(LedShow));
this.axWebBrowserLeftTop = new AxSHDocVw.AxWebBrowser();
this.axWebBrowserLeftBottom = new AxSHDocVw.AxWebBrowser();
this.axWebBrowserRightTop = new AxSHDocVw.AxWebBrowser();
this.axWebBrowserRightBottom = new AxSHDocVw.AxWebBrowser();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.pictureBox3 = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.axWebBrowserLeftTop)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.axWebBrowserLeftBottom)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.axWebBrowserRightTop)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.axWebBrowserRightBottom)).BeginInit();
this.SuspendLayout();
//
// axWebBrowserLeftTop
//
this.axWebBrowserLeftTop.Enabled = true;
this.axWebBrowserLeftTop.Location = new System.Drawing.Point(0, 0);
this.axWebBrowserLeftTop.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowserLeftTop.OcxState")));
this.axWebBrowserLeftTop.Size = new System.Drawing.Size(560, 120);
this.axWebBrowserLeftTop.TabIndex = 0;
//
// axWebBrowserLeftBottom
//
this.axWebBrowserLeftBottom.Enabled = true;
this.axWebBrowserLeftBottom.Location = new System.Drawing.Point(0, 120);
this.axWebBrowserLeftBottom.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowserLeftBottom.OcxState")));
this.axWebBrowserLeftBottom.Size = new System.Drawing.Size(560, 480);
this.axWebBrowserLeftBottom.TabIndex = 1;
//
// axWebBrowserRightTop
//
this.axWebBrowserRightTop.Enabled = true;
this.axWebBrowserRightTop.Location = new System.Drawing.Point(560, 0);
this.axWebBrowserRightTop.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowserRightTop.OcxState")));
this.axWebBrowserRightTop.Size = new System.Drawing.Size(240, 180);
this.axWebBrowserRightTop.TabIndex = 2;
//
// axWebBrowserRightBottom
//
this.axWebBrowserRightBottom.Enabled = true;
this.axWebBrowserRightBottom.Location = new System.Drawing.Point(560, 180);
this.axWebBrowserRightBottom.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowserRightBottom.OcxState")));
this.axWebBrowserRightBottom.Size = new System.Drawing.Size(240, 420);
this.axWebBrowserRightBottom.TabIndex = 3;
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.SystemColors.ControlText;
this.pictureBox1.Location = new System.Drawing.Point(3, 116);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(557, 8);
this.pictureBox1.TabIndex = 4;
this.pictureBox1.TabStop = false;
//
// pictureBox2
//
this.pictureBox2.BackColor = System.Drawing.SystemColors.ControlText;
this.pictureBox2.Location = new System.Drawing.Point(556, 3);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(8, 594);
this.pictureBox2.TabIndex = 5;
this.pictureBox2.TabStop = false;
//
// pictureBox3
//
this.pictureBox3.BackColor = System.Drawing.SystemColors.ControlText;
this.pictureBox3.Location = new System.Drawing.Point(560, 176);
this.pictureBox3.Name = "pictureBox3";
this.pictureBox3.Size = new System.Drawing.Size(237, 8);
this.pictureBox3.TabIndex = 6;
this.pictureBox3.TabStop = false;
//
// LedShow
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.ControlText;
this.ClientSize = new System.Drawing.Size(800, 600);
this.Controls.Add(this.pictureBox3);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.axWebBrowserRightBottom);
this.Controls.Add(this.axWebBrowserRightTop);
this.Controls.Add(this.axWebBrowserLeftBottom);
this.Controls.Add(this.axWebBrowserLeftTop);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "LedShow";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "LedShow";
((System.ComponentModel.ISupportInitialize)(this.axWebBrowserLeftTop)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.axWebBrowserLeftBottom)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.axWebBrowserRightTop)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.axWebBrowserRightBottom)).EndInit();
this.ResumeLayout(false);

}
#endregion
public void leddisplay()
{
string url = "http://localhost/Ledshow/test.htm";
System.Object nullObject = 0 ;
string str = "" ;
System.Object nullObjStr = str ;
Cursor.Current = Cursors.WaitCursor ;
axWebBrowserLeftTop.Navigate ( url , ref nullObject , ref nullObjStr , ref nullObjStr , ref nullObjStr ) ;

axWebBrowserLeftBottom.Navigate ( url , ref nullObject , ref nullObjStr , ref nullObjStr , ref nullObjStr ) ;

axWebBrowserRightTop.Navigate ( url , ref nullObject , ref nullObjStr , ref nullObjStr , ref nullObjStr ) ;

axWebBrowserRightBottom.Navigate ( url , ref nullObject , ref nullObjStr , ref nullObjStr , ref nullObjStr ) ;


Cursor.Current = Cursors.Default ;
}

}
}
ffb 2004-08-11
  • 打赏
  • 举报
回复
this.ledshow.Close();
改为
this.ledshow.Dispose();
rextan 2004-08-11
  • 打赏
  • 举报
回复
其实问题能不能打开窗口,只是private void label_status_TextChanged(object sender, System.EventArgs e)
{
if(this.label_status.Text=="刷新")
{
------------------首先,确认是否执行到这里------------------
button_refresh_Click(new object(),new System.EventArgs());
------------------把上面改成“button_refresh.PerformClick();”----------
}
this.label_status.Text= "正在监听";
}
这个方法打开的窗口不正常,处于加载状态的样子。
Knight94 2004-08-11
  • 打赏
  • 举报
回复
试试下面的:
private void label_status_TextChanged(object sender, System.EventArgs e)
{
if(this.label_status.Text=="刷新")
{
------------------首先,确认是否执行到这里------------------
button_refresh_Click(new object(),new System.EventArgs());
------------------把上面改成“button_refresh.PerformClick();”----------
}
this.label_status.Text= "正在监听";
}

rextan 2004-08-11
  • 打赏
  • 举报
回复
小弟初学写的恶心不要见怪。
rextan 2004-08-11
  • 打赏
  • 举报
回复
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace LedShow
{
/// <summary>
/// Index 的摘要说明。
/// </summary>
public class Index : System.Web.UI.Page
{
private static IPAddress ip=IPAddress.Parse("172.28.121.28");
private IPEndPoint po=new IPEndPoint(ip,8000);
protected System.Web.UI.WebControls.Button ButtonRefresh;
private Socket socket=new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);


private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{

}

}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ButtonRefresh.Click += new System.EventHandler(this.ButtonRefresh_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void refresh()
{
socket.Connect(po);
if (socket.Connected)
{
//Response.Write ("<script>alert('联接成功');</script>");
string messages="刷新";
Byte[] fsbyte= System.Text.Encoding.Unicode.GetBytes(messages);
socket.Send(fsbyte,fsbyte.Length,0);
}
else Response.Write ("<script>alert('刷新不成功');</script>");

}

private void ButtonRefresh_Click(object sender, System.EventArgs e)
{
Thread t = new Thread(new ThreadStart(refresh));
t.Start();
}
}
}
rextan 2004-08-11
  • 打赏
  • 举报
回复
代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net.Sockets;
using System.Net;
using System.Threading;

namespace LedServer
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Server : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button_start;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button button_refresh;
private System.Windows.Forms.Label label_status;
/// <summary>
/// 必需的设计器变量。
/// </summary>
///
private static IPAddress ip=IPAddress.Parse("172.28.121.28");
private IPEndPoint po=new IPEndPoint(ip,8000);
private Socket socket;
private Socket tempsocket;
private LedShow ledshow=null;
private string str=null;

private System.ComponentModel.Container components = null;

public Server()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <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()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Server));
this.button_start = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.button_refresh = new System.Windows.Forms.Button();
this.label_status = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button_start
//
this.button_start.Location = new System.Drawing.Point(160, 16);
this.button_start.Name = "button_start";
this.button_start.Size = new System.Drawing.Size(40, 20);
this.button_start.TabIndex = 0;
this.button_start.Text = "启动";
this.button_start.Click += new System.EventHandler(this.button_start_Click);
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(16, 4);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(108, 104);
this.pictureBox1.TabIndex = 1;
this.pictureBox1.TabStop = false;
//
// button_refresh
//
this.button_refresh.Location = new System.Drawing.Point(160, 48);
this.button_refresh.Name = "button_refresh";
this.button_refresh.Size = new System.Drawing.Size(40, 20);
this.button_refresh.TabIndex = 4;
this.button_refresh.Text = "刷新";
this.button_refresh.Click += new System.EventHandler(this.button_refresh_Click);
//
// label_status
//
this.label_status.Location = new System.Drawing.Point(144, 84);
this.label_status.Name = "label_status";
this.label_status.Size = new System.Drawing.Size(76, 16);
this.label_status.TabIndex = 5;
this.label_status.Text = "状态";
this.label_status.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label_status.TextChanged += new System.EventHandler(this.label_status_TextChanged);
//
// Server
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(228, 109);
this.Controls.Add(this.label_status);
this.Controls.Add(this.button_refresh);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.button_start);
this.Location = new System.Drawing.Point(620, 500);
this.Name = "Server";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Server());
}
private void button_start_Click(object sender, System.EventArgs e)
{
ledshow = new LedShow();
ledshow.Show();
ledshow.leddisplay();
socket =new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
socket.Bind(po);
socket.Listen(50);
Thread t=new Thread(new ThreadStart(js));
t.Start();

this.button_start.Enabled = false;

}
private void js()
{
while(true)
{
tempsocket=socket.Accept();
if (tempsocket.Connected)
{
Byte[] b=new byte[1024];
//这个缓冲区长了没事,如果比发送端缓冲区短就会把信息截去
//排个例子中发送方缓冲区是10
tempsocket.Receive(b,b.Length,0);
//string str=b.ToString();
str=System.Text.Encoding.Unicode.GetString(b);
this.label_status.Text = "刷新";
}
}
}



private void button_refresh_Click(object sender, System.EventArgs e)
{
this.ledshow.Close();
ledshow = new LedShow();
ledshow.Show();
ledshow.leddisplay();
}
private void label_status_TextChanged(object sender, System.EventArgs e)
{
if(this.label_status.Text=="刷新")
{
button_refresh_Click(new object(),new System.EventArgs());

//this.ledshow.Close();
//ledshow = new LedShow();
//ledshow.ShowDialog();
//ledshow.leddisplay();
}
this.label_status.Text= "正在监听";
}

}
}
BlueLevin 2004-08-11
  • 打赏
  • 举报
回复
Form1 InputForm =new Form1();
Form1.ShowDialog();打开模式窗口
或InputForm.Show();打开窗口
觉得不会有问题啊,窗口也是类。和其它类一样。先实例化再调用方法,Show()就是显示的方法。也许你其它地方有问题!看一下别的代码!或者贴下代码给大伙看看!
xaodoudou 2004-08-11
  • 打赏
  • 举报
回复
把 PerformClick 改成 
button_refresh_Click(new object(),new System.EventArgs())
qifanghcy 2004-08-11
  • 打赏
  • 举报
回复
private void button_refresh_Click(object sender, System.EventArgs e)
{
//this.ledshow.Close();
LedShow ledshow = new LedShow();
ledshow.Show();
}
private void label_status_TextChanged(object sender, System.EventArgs e)
{
button_refresh.PerformClick();
}
这样改就不会了!
ljwpal 2004-08-11
  • 打赏
  • 举报
回复
我也不信!!!
Form Form1 =new Form();
Form1 .ShowDialog() ;
rextan 2004-08-11
  • 打赏
  • 举报
回复
private void button_refresh_Click(object sender, System.EventArgs e)
{
this.ledshow.Close();
ledshow = new LedShow();
ledshow.Show();
}
private void label_status_TextChanged(object sender, System.EventArgs e)
{
button_refresh.PerformClick();
}
上面的事件打开的窗口就很正常,但是用下面这个事件打开的窗口就不正常。
boyxia 2004-08-11
  • 打赏
  • 举报
回复
Form2 InputForm =new Form2();
InputForm.ShowDialog();或InputForm.Show();

我不信打不开

110,536

社区成员

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

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

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