简体   繁体   中英

Error reading TextBox value in C#

I'm having some problems making a program that will read the text from a TextBox. I'm reading two values from two TextBoxes but it seems like nothing is actually reading. What ends up happening is that I enter values into the TextBoxes and press the button to enter the values into the program. I have it set up to print out the values that were in my TextBoxes, but when it prints, it looks like it didn't read anything from the TextBoxes.

Here's my code for the window:

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);
            }
        }
    }
}

Here's the struct that the values go into:

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;
            }
        }
    }
}

And here's the console output from the program:

'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).

The 'Name: , Email: ' thing is where my values were supposed to be.

Thank you in advance for your help, and if you need anymore information, simply say and I will provide.

    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. You are not adding the newEntry to the array
  2. It would be much easier if you just used a List<GiveawayEntry>
  3. There's no need to make it a struct . Just use a class unless you have a compelling reason to make it a struct

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM