为什么我编的C#的WINDOWS应用程序,运行时FORM不会显现出来,而是在后台运行?
我写了个链表类,然后想进行两个链表合并,再在FORM上显示出来,以前还可以的,但后来加了些代码后调试的时候就不能出现FORM,而是在后台运行
我发现不要调用public void ListInsert(int i,int e)函数就可以显示FORM,为什么?
部分代码:
namespace List
{
/// <summary>
/// Summary description for ListNode.
/// </summary>
// 结点类
public class ListNode
{
public ListNode(int NewValue)
{
Value=NewValue;
}
/// <summary>
/// 前一个
/// </summary>
public ListNode Previous;
/// <summary>
/// 后一个
/// </summary>
public ListNode Next;
/// <summary>
/// 值
/// </summary>
public int Value;
}
public class Clist
{
private ListNode Head; //头结点
private ListNode p; //当前结点
private int ListLen;
//*******************************************
public Clist()
{
Head=null;
p=null;
ListLen=0;
}
/// <summary>
/// 返回指定位置结点的值
/// </summary>
public int GetElem(int i)
{
ListNode move;
if(!ListEmpty() && i>=1 && i<=ListLength)
{
int j;
move=Head;
for(j=1;j<i;j++)
//while(move!=null)
{
move=move.Next;
}
return move.Value;
}
return 0;
}
public void ListInsert(int i,int e)
{
ListNode NewNode=new ListNode(e);
ListNode q;
ListNode move;
int j;
if(!ListEmpty() && i>=1 && i<=ListLength)
{
if(i==1)
{
Head.Previous =NewNode;
NewNode.Next =Head;
Head=NewNode;
ListLen++;
}
else
{
move=Head;
for(j=1;j<i;j++)
//while(move.Next!=null)
{
move=move.Next;
}
q=move;
NewNode.Next =q;
q.Previous =NewNode;
move.Next =NewNode;
NewNode.Previous =move;
move=NewNode;
p=NewNode;
ListLen++;
}
}
return;
}
/// <summary>
/// 判断链表中是否存在e
/// </summary>
public bool Isin(int e)
{
bool bl=false;
ListNode move;
int i;
move=Head;
while(move!=null)
//for(i=1;i<=ListLength;i++)
{
if(move.Value==e)
{
bl=true;
break;
}
else
{
move=move.Next;
}
}
return bl;
}
public string PrintList()
{
ListNode move;
string strtext="";
move=Head;
while(move!=null)
{
strtext=strtext + move.Value.ToString() + ",";
move=move.Next;
}
return strtext;
}
}
}
//*******************************
//form1.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using List;
namespace WindowsApplication3
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblOut;
private Clist La;
private Clist Lb;
private System.Windows.Forms.Label lbl_a;
private System.Windows.Forms.Label lbl_b;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public void CreateList()
{
La=new Clist();
La.AppendNode(3);
La.AppendNode(5);
La.AppendNode(8);
La.AppendNode(11);
Lb=new Clist();
Lb.AppendNode(2);
Lb.AppendNode(6);
Lb.AppendNode(8);
Lb.AppendNode(9);
Lb.AppendNode(11);
Lb.AppendNode(15);
Lb.AppendNode(20);
return;
}
public string ex2_1()
{
Clist temp;
int La_len,Lb_len,i,e;
//CreateList();
La_len=La.ListLength;
Lb_len=Lb.ListLength;
temp=La;
for(i=1;i<=Lb_len;i++)
{
e=Lb.GetElem(i);
if(!temp.Isin(e))
{
La.ListInsert(La_len,e);
}
}
return La.PrintList();
}
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
CreateList();
lbl_a.Text =La.PrintList();
lbl_b.Text =Lb.PrintList();
lblOut.Text =ex2_1();
}
}
}