Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › I need C# form help!!!!
New Posts  All Forums:Forum Nav:

I need C# form help!!!!

post #1 of 3
Thread Starter 
Here is my code:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            Label lblTitle;
            lblTitle = new Label();
            lblTitle.Location = new Point(70, 10);
            lblTitle.Text = "Zombie Application Form";
            lblTitle.Size = new Size(lblTitle.PreferredWidth, lblTitle.PreferredHeight);
            Controls.Add(lblTitle);

            Label lblName;
            lblName = new Label();
            lblName.Location = new Point(10, 30);
            lblName.Text = "Name: ";
            lblName.Size = new Size(lblName.PreferredWidth, lblName.PreferredHeight);
            Controls.Add(lblName);

            TextBox txtUser;
            txtUser = new TextBox();
            txtUser.Location = new Point(lblName.Size.Width + 10, 30);
            Controls.Add(txtUser);

            Label lblRunSpeed;
            lblRunSpeed = new Label();
            lblRunSpeed.Location = new Point(10, 60);
            lblRunSpeed.Text = "Running Speed: ";
            lblRunSpeed.Size = new Size(lblRunSpeed.PreferredWidth, lblRunSpeed.PreferredHeight);
            Controls.Add(lblRunSpeed);

            TextBox txtUserSpeed;
            txtUserSpeed = new TextBox();
            txtUserSpeed.Location = new Point(lblName.Size.Width + 55, 60);
            Controls.Add(txtUserSpeed);

            Button btnApply;
            btnApply = new Button();
            btnApply.Location = new Point(100, 350);
            btnApply.Text = "Apply";
            Controls.Add(btnApply);
            Size = new Size(300, 300);
            btnApply.Click += new EventHandler(btnEventHandler_Apply);

            Button btnExit;
            btnExit = new Button();
            btnExit.Location = new Point(200, 350);
            btnExit.Text = "Exit";
            Controls.Add(btnExit);
            Size = new Size(400, 450);
            btnExit.Click += new EventHandler(btnEventHandler_Exit);

            Label lblHunters;
            lblHunters = new Label();
            lblHunters.Location = new Point(10, 90);
            lblHunters.Text = "Likes Zombie Hunters: ";
            lblHunters.Size = new Size(lblHunters.PreferredWidth, lblHunters.PreferredHeight);
            Controls.Add(lblHunters);

            RadioButton Yes; 
            Yes = new RadioButton();
            Yes.Location = new Point(150, 85);
            Yes.Text = "Yes";
            Controls.Add(Yes);

            RadioButton No;
            No = new RadioButton();
            No.Location = new Point(300, 85);
            No.Text = "No";
            Controls.Add(No);

            Label lblEat;
            lblEat = new Label();
            lblEat.Location = new Point(10, 120);
            lblEat.Text = "Will Eat: ";
            lblEat.Size = new Size(lblEat.PreferredWidth, lblEat.PreferredHeight);
            Controls.Add(lblEat);

            CheckBox HumanBrains;
            HumanBrains = new CheckBox();
            HumanBrains.Location = new Point(60, 120);
            HumanBrains. Text = "Human Brains: ";
            Controls.Add(HumanBrains);

            CheckBox SheepBrains;
            SheepBrains = new CheckBox();
            SheepBrains.Location = new Point(60, 140);
            SheepBrains.Text = "Sheep Brains: ";
            Controls.Add(SheepBrains);

            CheckBox Vegetables;
            Vegetables = new CheckBox();
            Vegetables.Location = new Point(60, 160);
            Vegetables.Text = "Vegetables: ";
            Controls.Add(Vegetables);   
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }
        private void btnEventHandler_Apply(object sender, EventArgs e)
        {  
            if ( )
                MessageBox.Show(txtUser.Text + " you are a Zombie!");
            else
                MessageBox.Show(txtName.Text + " you are NOT a Zombie~");
        }
        private void btnEventHandler_Exit(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

How do I access the form I made and read in the input I put in the form to decide if a person is a zombie or not???

Thanks in advance

~Zax
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
post #2 of 3
Thread Starter 
Here is what the form looks like
477
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
post #3 of 3
The code you've written is your form. The C# class you wrote inherits from the Form class, and the Form class displays a GUI, so your class, Form1, displays a GUI. Accessing your form is simply accessing your class.

Reading input from a textbox is done via the Text property of the textbox instance; e.g., string name = txtUser.Text. Other classes' data are accessed in different ways.

It looks like you're using Visual C#... why aren't you using the GUI builder for those GUI elements? It stops you from having to write excessive boilerplate code. You can still access the elements; you just edit their Name property (also from the GUI builder) and then refer to them by that.
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › I need C# form help!!!!