Results 1 to 4 of 4

Thread: Beginner Problem (Accessibility Issues)

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    2

    Beginner Problem (Accessibility Issues)

    Hey all,

    I just started with C# today, I downloaded Borland C# Builder and tried making a simple form. I'm familiar with both C++ and Visual Basic, so there are many similarities that i'm noticing. I am trying to make a form that when clicking one button (btnUp) it adds 1 to the value of a label (lblValue). When you click another button (btnDown) it minuses 1 from the value of a label. Here's my code.

    Code:
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    
    namespace First_Project
    {
    	/// <summary>
    	/// This is my first project in C#. I am seeing the similarities between this, Visual Basic, and C++
    	/// </summary>
    	public class WinForm : System.Windows.Forms.Form
    	{
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    		public System.ComponentModel.Container components = null;
    		public System.Windows.Forms.Label lblValue;
    		public System.Windows.Forms.Button btnUp;
    		public System.Windows.Forms.Button btnDown;
    		/*
    		Originally:
    		private System.ComponentModel.Container components = null;
    		private System.Windows.Forms.Label lblValue;
    		private System.Windows.Forms.Button btnUp;
    		private System.Windows.Forms.Button btnDown;
    		*/
    		public WinForm()
    		{
    			//
    			// Required for Windows Form Designer support
    			//
    			InitializeComponent();
    
    			//
    			// TODO: Add any constructor code after InitializeComponent call
    			//
    		}
    
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		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()
    		{
    			this.lblValue = new System.Windows.Forms.Label();
    			this.btnUp = new System.Windows.Forms.Button();
    			this.btnDown = new System.Windows.Forms.Button();
    			this.SuspendLayout();
    			// 
    			// lblValue
    			// 
    			this.lblValue.Location = new System.Drawing.Point(32, 88);
    			this.lblValue.Name = "lblValue";
    			this.lblValue.Size = new System.Drawing.Size(240, 48);
    			this.lblValue.TabIndex = 0;
    			this.lblValue.Text = "0";
    			// 
    			// btnUp
    			// 
    			this.btnUp.Location = new System.Drawing.Point(32, 176);
    			this.btnUp.Name = "btnUp";
    			this.btnUp.Size = new System.Drawing.Size(72, 24);
    			this.btnUp.TabIndex = 1;
    			this.btnUp.Text = "Up";
    			this.btnUp.Click += new System.EventHandler(this.btnUp_Click);
    			// 
    			// btnDown
    			// 
    			this.btnDown.Location = new System.Drawing.Point(128, 176);
    			this.btnDown.Name = "btnDown";
    			this.btnDown.Size = new System.Drawing.Size(80, 24);
    			this.btnDown.TabIndex = 2;
    			this.btnDown.Text = "Down";
    			// 
    			// WinForm
    			// 
    			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    			this.ClientSize = new System.Drawing.Size(292, 273);
    			this.Controls.Add(this.btnDown);
    			this.Controls.Add(this.btnUp);
    			this.Controls.Add(this.lblValue);
    			this.Name = "WinForm";
    			this.Text = "My First Project";
    			this.ResumeLayout(false);
    		}
    		#endregion
    
    		/// <summary>
    		/// The main entry point for the application.
    		/// </summary>
    		[STAThread]
    		static void Main() 
    		{
    			Application.Run(new WinForm());
    		}
    		
    		private void btnUp_Click(object sender, System.EventArgs e)
    		{
    			lblValue.text = lblValue.Text + 1;
    		}
    
    	}
    }
    It would seem to me that I fixed the problem when changing the designer variable limitations from private to public, but it doesn't seem to be working.

    Error it's giving out: [C# Error] WinForm.cs(111): 'System.Windows.Forms.Control.text' is inaccessible due to its protection level

    Thanks in advance,
    Mike

  2. #2

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    2

    Re: Beginner Problem (Accessibility Issues)

    RESOLVED
    It's supposed to be .Text not .text.

  3. #3
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    Re: Beginner Problem (Accessibility Issues)

    this is one thing i'm having problems with coming from vb fortunately, the Intellisense usually helps me

  4. #4
    Junior Member
    Join Date
    Feb 2005
    Posts
    31

    Re: Beginner Problem (Accessibility Issues)

    Also, you shouldn't be adding an integer to a string. It looks like it's working fine, but at the very least do:

    Code:
    Label1.Text = (string)((int)Label1.Text + 1));
    Dan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width