2016-04-22 77 views
0

我在编写程序时会遇到一些问题,它会从TextBox中读取文本。我正在阅读两个TextBoxes中的两个值,但它似乎没有任何内容正在读取。最终发生的是我将值输入到文本框中,然后按按钮将值输入到程序中。我将它设置为打印出我的文本框中的值,但是当它打印时,它看起来没有从文本框中读取任何东西。在C中读取TextBox值时出错#

这里是我的窗口代码:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace Giveaway_Program 
{ 
    public partial class giveawayProgram : Form 
    { 
     public GiveawayEntry[] entries = {}; 

     public giveawayProgram() 
     { 
      InitializeComponent(); 
     } 

     private void Giveaway_Load(object sender, EventArgs e) 
     { 

     } 

     private void panel_Paint(object sender, PaintEventArgs e) 
     { 

     } 

     private void emailText_TextChanged(object sender, EventArgs e) 
     { 

     } 

     private void nameText_TextChanged(object sender, EventArgs e) 
     { 

     } 

     private void numberOfTimes_ValueChanged(object sender, EventArgs e) 
     { 

     } 

     private void addToList_Click(object sender, EventArgs e) 
     { 
      addEntry(new GiveawayEntry(emailText.Text, nameText.Text)); 
     } 

     private void generateWinner_Click(object sender, EventArgs e) 
     { 

     } 

     private void addEntry(GiveawayEntry newEntry) 
     { 
      GiveawayEntry[] newEntries = new GiveawayEntry[entries.Length + 1]; 
      Array.Copy(entries, newEntries, entries.Length); 
      entries = newEntries; 

      for (int i = 0; i < entries.Length; i++) 
      { 
       Console.WriteLine("Name: " + entries[i].Name + ", Email: " + entries[i].Email); 
      } 
     } 
    } 
} 

下面是值进入结构:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

namespace Giveaway_Program 
{ 
    public struct GiveawayEntry 
    { 
     string email, name; 

     public GiveawayEntry(string _email, string _name) 
     { 
      email = _email; 
      name = _name; 
     } 

     public string Email 
     { 
      get 
      { 
       return email; 
      } 
     } 

     public string Name 
     { 
      get 
      { 
       return name; 
      } 
     } 
    } 
} 

下面是从程序的控制台输出:

'Giveaway Program.vshost.exe' (CLR v4.0.30319: Giveaway Program.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'Giveaway Program.vshost.exe' (CLR v4.0.30319: Giveaway Program.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'Giveaway Program.vshost.exe' (CLR v4.0.30319: Giveaway Program.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'Giveaway Program.vshost.exe' (CLR v4.0.30319: Giveaway Program.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'Giveaway Program.vshost.exe' (CLR v4.0.30319: Giveaway Program.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'Giveaway Program.vshost.exe' (CLR v4.0.30319: Giveaway Program.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'Giveaway Program.vshost.exe' (CLR v4.0.30319: Giveaway Program.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'Giveaway Program.vshost.exe' (CLR v4.0.30319: Giveaway Program.vshost.exe): Loaded 'C:\Users\Overlord Nate\Google Drive\Projects\Giveaway Program\Giveaway Program\bin\Debug\Giveaway Program.vshost.exe'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'Giveaway Program.vshost.exe' (CLR v4.0.30319: Giveaway Program.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'Giveaway Program.vshost.exe' (CLR v4.0.30319: Giveaway Program.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'Giveaway Program.vshost.exe' (CLR v4.0.30319: Giveaway Program.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'Giveaway Program.vshost.exe' (CLR v4.0.30319: Giveaway Program.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'Giveaway Program.vshost.exe' (CLR v4.0.30319: Giveaway Program.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'Giveaway Program.vshost.exe' (CLR v4.0.30319: Giveaway Program.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Deployment\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'Giveaway Program.vshost.exe' (CLR v4.0.30319: Giveaway Program.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'Giveaway Program.vshost.exe' (CLR v4.0.30319: Giveaway Program.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
The thread 0xd4c has exited with code 0 (0x0). 
The thread 0x28e8 has exited with code 0 (0x0). 
'Giveaway Program.vshost.exe' (CLR v4.0.30319: Giveaway Program.vshost.exe): Loaded 'C:\Users\Overlord Nate\Google Drive\Projects\Giveaway Program\Giveaway Program\bin\Debug\Giveaway Program.exe'. Symbols loaded. 
'Giveaway Program.vshost.exe' (CLR v4.0.30319: Giveaway Program.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
Name: , Email: 
The thread 0x2ec0 has exited with code 0 (0x0). 
The thread 0x1630 has exited with code 0 (0x0). 
The program '[6500] Giveaway Program.vshost.exe' has exited with code 0 (0x0). 

'姓名:,电子邮件:'是我的价值观应该达到的地方。

非常感谢您的帮助,如果您需要更多信息,只需说出我将提供的信息。

回答

1
private void addEntry(GiveawayEntry newEntry) 
    { 
     GiveawayEntry[] newEntries = new GiveawayEntry[entries.Length + 1]; 
     Array.Copy(entries, newEntries, entries.Length); 
     entries = newEntries; 

     for (int i = 0; i < entries.Length; i++) 
     { 
      Console.WriteLine("Name: " + entries[i].Name + ", Email: " + entries[i].Email); 
     } 
    } 
  1. 您没有添加newEntry到数组
  2. 如果你只是使用List<GiveawayEntry>
  3. 没有必要使它成为一个struct这会容易得多。只需使用class,除非您有令人信服的理由使其成为struct
+0

非常感谢您的帮助和解决问题。一个问题,从结构到类的变化,我可以简单地替换它说的结构与类,或者我应该改变一些关于代码? – TheAustralianBirdEatingLouse

+0

不,那就是这一块代码 – JakeGill70