Jump to content
  • Advertisement
Sign in to follow this  
phil05

C# need help

This topic is 5463 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The idea is to check if the user entered a name. If he didn't, alert the user that he didn't do so. Currently it's giving me this error... \MainForm.cs(94,7): error CS0122: 'System.Windows.Forms.Control.text' is inaccessible due to its protection level
using System;
using System.Drawing;
using System.Windows.Forms;

class MyForm : Form
{
	Label lblName, lblAge, lblRace;
	TextBox tbName, tbAge;
	ComboBox cbRace;
	Button btnSubmit;
	
	public static void Main(string[] args)
	{
		Application.Run(new MyForm());
	}
	
	public MyForm()
	{
		#region Form Properties
		this.Text = "C# Programming";
		this.Name = "MainForm";
		this.StartPosition = FormStartPosition.CenterScreen;
		this.Size = new System.Drawing.Size(800,600);
		this.BackColor = System.Drawing.Color.AliceBlue;
		#endregion
		
		#region Label: lblName
		this.lblName = new Label();
		lblName.Text = "Name:";
		lblName.Name = "lblName";
		lblName.Location = new System.Drawing.Point(10,10);
		lblName.ClientSize = new System.Drawing.Size(40, 15);
			
		// TextBox: tbName
		this.tbName = new TextBox();
		tbName.Name = "tbName";
		tbName.Location = new System.Drawing.Point(65,7);
		tbName.Size = new System.Drawing.Size(100,25);
		#endregion
		
		#region Label: lblAge
		lblAge = new Label();
		lblAge.Text = "Age:";
		lblAge.Name = "lblAge";
		lblAge.Location = new System.Drawing.Point(10,40);
		lblAge.ClientSize = new System.Drawing.Size(40,15);
		
		// TextBox: tbAge
		tbAge = new TextBox();
		tbAge.Name = "tbAge";
		tbAge.Location = new System.Drawing.Point(65,40);
		tbAge.Size = new System.Drawing.Size(100,45);
		#endregion
		
		#region Label: lblRace
		lblRace = new Label();
		lblRace.Text = "Race:";
		lblRace.Name = "lblRace";
		lblRace.Location = new System.Drawing.Point(10,70);
		lblRace.ClientSize = new System.Drawing.Size(40,15);
		
		// ComboBox: cbRace
		cbRace = new ComboBox();
		cbRace.Location = new System.Drawing.Point(65, 70);
		cbRace.Size = new System.Drawing.Size(100, 15);
		cbRace.DropDownStyle = ComboBoxStyle.DropDownList;
		cbRace.Items.Add("Human");
		cbRace.Items.Add("Dark Elf");
		cbRace.Items.Add("Wood Elf");
		#endregion
		
		this.btnSubmit = new Button();
		btnSubmit.Text = "Submit";
		btnSubmit.BackColor = System.Drawing.Color.LightGreen;
		btnSubmit.Location = new System.Drawing.Point(170, 70);
		btnSubmit.Size = new System.Drawing.Size(100, 21);
		btnSubmit.Click += new System.EventHandler(this.btnSubmitClick);
			
		#region Controls
		this.Controls.Add(this.lblName);
		this.Controls.Add(this.tbName);
		this.Controls.Add(this.lblAge);
		this.Controls.Add(this.tbAge);
		this.Controls.Add(this.lblRace);
		this.Controls.Add(this.cbRace);
		this.Controls.Add(this.btnSubmit);
		#endregion
		
	}
	
	void btnSubmitClick(object sender, System.EventArgs e)
	{
		if (tbName.text == "")
		{
			MessageBox.Show("You must enter a name.", "Character Creation", 
			               MessageBoxButtons.OK);
		}
	}
	
}


Share this post


Link to post
Share on other sites
Advertisement
The field 'text' is the private or protected backer of the 'Text' property. You need the property, thus 'Text'. Watch the uppercase T!

Change

if (tbName.text == "")

to

if (tbName.Text == "")

Share this post


Link to post
Share on other sites
Looking at your recent topics, have you made a switch from C++/Win32 to .NET? If so, and also if not so, good luck with .NET :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!