2010-04-28 48 views
-1

所以我的程序是这样工作的:使用winforms,用户输入ID号码,使用数组,基于正确的身份证号码,学生信息和课程安排在消息框中输出!Winform/Program以及如何将第1类,第2类,第3类,第4类写入链接标签?

我的问题是如何将4个类放在消息框/数组中并将它们写入表单2中的linklabel文本?

我Getschedule类包含所述阵列并且在下面列出:

命名空间Eagle_Eye_Class_Finder {

public class GetSchedule 
{ 
    IDnumber[] IDnumbers = new IDnumber[3]; 

    public string GetDataFromNumber(string ID) 
    { 
     foreach (IDnumber IDCandidateMatch in IDnumbers) 
     { 

      if (IDCandidateMatch.ID == ID) 
      { 
       StringBuilder myData = new StringBuilder(); 
       myData.AppendLine(IDCandidateMatch.Name); 
       myData.AppendLine(": "); 
       myData.AppendLine(IDCandidateMatch.ID); 
       myData.AppendLine(IDCandidateMatch.year); 
       myData.AppendLine(IDCandidateMatch.class1); 
       myData.AppendLine(IDCandidateMatch.class2); 
       myData.AppendLine(IDCandidateMatch.class3); 
       myData.AppendLine(IDCandidateMatch.class4); 
       //return myData; 
       return myData.ToString(); 
      } 
     } 
     return ""; 
    } 

    public GetSchedule() 
    { 
     IDnumbers[0] = new IDnumber() { Name = "Joshua Banks", ID = "900456317", year = "Senior", class1 = "TEET 4090", class2 = "TEET 3020", class3 = "TEET 3090", class4 = "TEET 4290" }; 
     IDnumbers[1] = new IDnumber() { Name = "Sean Ward", ID = "900456318", year = "Junior", class1 = "ENGNR 4090", class2 = "ENGNR 3020", class3 = "ENGNR 3090", class4 = "ENGNR 4290" }; 
     IDnumbers[2] = new IDnumber() { Name = "Terrell Johnson", ID = "900456319", year = "Sophomore", class1 = "BUS 4090", class2 = "BUS 3020", class3 = "BUS 3090", class4 = "BUS 4290" }; 

    } 
    public class IDnumber 
    { 
     public string Name { get; set; } 
     public string ID { get; set; } 
     public string year { get; set; } 
     public string class1 { get; set; } 
     public string class2 { get; set; } 
     public string class3 { get; set; } 
     public string class4 { get; set; } 


     public static void ProcessNumber(IDnumber myNum) 
      { 
       StringBuilder myData = new StringBuilder(); 
       myData.AppendLine(myNum.Name); 
       myData.AppendLine(": "); 
       myData.AppendLine(myNum.ID); 
       myData.AppendLine(myNum.year); 
       myData.AppendLine(myNum.class1); 
       myData.AppendLine(myNum.class2); 
       myData.AppendLine(myNum.class3); 
       myData.AppendLine(myNum.class4); 
       MessageBox.Show(myData.ToString()); 
      } 




    } 

} 

}

我的形式2,其将包含linklabels列表如下:

public class YOURCLASSSCHEDULE:System.Windows.Forms.Form { public System.Windows.Forms.LinkLabel linkLabel1; public System.Windows.Forms.LinkLabel linkLabel2; public System.Windows.Forms.LinkLabel linkLabel3; public System.Windows.Forms.LinkLabel linkLabel4; 私人按钮button1;

/// Required designer variable. 

    public System.ComponentModel.Container components = null; 

    public YOURCLASSSCHEDULE() 
    { 

     // 
     InitializeComponent(); 

     // TODO: Add any constructor code after InitializeComponent call 

    } 

    /// Clean up any resources being used. 
    protected override void Dispose(bool disposing) 
    { 
     if (disposing) 
     { 
      if (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() 
    { 
     System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(YOURCLASSSCHEDULE)); 
     this.linkLabel1 = new System.Windows.Forms.LinkLabel(); 
     this.linkLabel2 = new System.Windows.Forms.LinkLabel(); 
     this.linkLabel3 = new System.Windows.Forms.LinkLabel(); 
     this.linkLabel4 = new System.Windows.Forms.LinkLabel(); 
     this.button1 = new System.Windows.Forms.Button(); 
     this.SuspendLayout(); 
     // 
     // linkLabel1 
     // 
     this.linkLabel1.BackColor = System.Drawing.SystemColors.ActiveCaption; 
     this.linkLabel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; 
     this.linkLabel1.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
     this.linkLabel1.LinkArea = new System.Windows.Forms.LinkArea(0, 7); 
     this.linkLabel1.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline; 
     this.linkLabel1.Location = new System.Drawing.Point(41, 123); 
     this.linkLabel1.Name = "linkLabel1"; 
     this.linkLabel1.Size = new System.Drawing.Size(288, 32); 
     this.linkLabel1.TabIndex = 1; 
     this.linkLabel1.TabStop = true; 
     this.linkLabel1.Text = "Class 1"; 
     this.linkLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; 
     this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked); 
     // 
     // linkLabel2 
     // 
     this.linkLabel2.BackColor = System.Drawing.SystemColors.ActiveCaption; 
     this.linkLabel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; 
     this.linkLabel2.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
     this.linkLabel2.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline; 
     this.linkLabel2.Location = new System.Drawing.Point(467, 123); 
     this.linkLabel2.Name = "linkLabel2"; 
     this.linkLabel2.Size = new System.Drawing.Size(288, 32); 
     this.linkLabel2.TabIndex = 2; 
     this.linkLabel2.TabStop = true; 
     this.linkLabel2.Text = "Class 2"; 
     this.linkLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; 
     this.linkLabel2.VisitedLinkColor = System.Drawing.Color.Navy; 
     this.linkLabel2.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel2_LinkClicked); 
     // 
     // linkLabel3 
     // 
     this.linkLabel3.BackColor = System.Drawing.SystemColors.ActiveCaption; 
     this.linkLabel3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; 
     this.linkLabel3.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
     this.linkLabel3.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline; 
     this.linkLabel3.Location = new System.Drawing.Point(41, 311); 
     this.linkLabel3.Name = "linkLabel3"; 
     this.linkLabel3.Size = new System.Drawing.Size(288, 32); 
     this.linkLabel3.TabIndex = 3; 
     this.linkLabel3.TabStop = true; 
     this.linkLabel3.Text = "Class 3"; 
     this.linkLabel3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; 
     this.linkLabel3.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel3_LinkClicked); 
     // 
     // linkLabel4 
     // 
     this.linkLabel4.BackColor = System.Drawing.SystemColors.ActiveCaption; 
     this.linkLabel4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; 
     this.linkLabel4.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
     this.linkLabel4.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline; 
     this.linkLabel4.Location = new System.Drawing.Point(467, 311); 
     this.linkLabel4.Name = "linkLabel4"; 
     this.linkLabel4.Size = new System.Drawing.Size(288, 32); 
     this.linkLabel4.TabIndex = 4; 
     this.linkLabel4.TabStop = true; 
     this.linkLabel4.Text = "Class 4"; 
     this.linkLabel4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; 
     this.linkLabel4.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel4_LinkClicked); 
     // 

     // 
     this.AutoScaleBaseSize = new System.Drawing.Size(6, 15); 
     this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage"))); 
     this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; 
     this.ClientSize = new System.Drawing.Size(790, 482); 
     this.Controls.Add(this.button1); 
     this.Controls.Add(this.linkLabel4); 
     this.Controls.Add(this.linkLabel3); 
     this.Controls.Add(this.linkLabel2); 
     this.Controls.Add(this.linkLabel1); 
     this.Font = new System.Drawing.Font("OldDreadfulNo7 BT", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
     this.Name = "YOURCLASSSCHEDULE"; 
     this.Text = "Your Classes"; 
     this.Load += new System.EventHandler(this.Form2_Load); 
     this.ResumeLayout(false); 

    } 
    #endregion 

    public void Form2_Load(object sender, System.EventArgs e) 
    { 
     // if (text == "900456317") 
     // { 

     //} 

    } 

    public void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) 
    { 

     System.Diagnostics.Process.Start("http://www.georgiasouthern.edu/map/"); 
    } 

    private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) 
    { 

    } 

    private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) 
    { 

    } 

    private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) 
    { 

    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     Form1 form1 = new Form1(); 
     form1.Show(); 
     this.Hide(); 
    } 
} 

}

回答

0

移动你的4类静态对象或业务层。使用业务层访问您的表单中的数据。

使用方法如下,例如:

YourBusinessLayer.ScheduleManager manager = new ScheduleManager(); 

ScheduleManager.Add(new Schedule("Name", "ID", "Class", "Timings"); //Add schedules 
List<Schedule> listOfAllSchedules= manager.GetSchedules(); //Get Schedules 

manager.Schedule[0].ID 
manager.Schedule[0].Name 
manager.Schedule[0].Class 
//.... 

然后,接入(编辑/更新)您的日程安排经理在你的任何形式。

顺便说一句,就像一个网站的说明,一个班不应该(读:不能)是一个GetSchedule;而是一个类可能包含一个名为GetSchedule()的方法(读取:操作)。

+0

好吧让我改说一下,我只想写这些类的链接标签! – 2010-04-28 22:20:43

+0

我的表单2包含4个链接标签,我希望他们更新标签文本链接上的标签,以链接到已引用到数组的任何类别! – 2010-04-28 22:24:55

+0

@JB:'我希望他们更新';在这种情况下谁是'他们'? – 2010-04-29 06:12:15

相关问题