Thread: accessing windows forms textbox properties

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    budding software engineer luigi40's Avatar
    Join Date
    Jun 2004
    Location
    South Coast UK
    Posts
    61

    accessing windows forms textbox properties

    i have a class that outputs text to the console, i want to output the same text to a textbox, however the console method is in a different class, i have been raeding Deitel C# how to program and see various ways to achieve this but im not sure which way is best. here are the classes involved in outputing the text

    Code:
    using System;
    using System.Collections;
    
    namespace TrafficControlSim
    {
    public class TrafficQueue
    	{
    	private Queue vehicleQueue;//fifo object
        
    	// constructor - one integer input  
    	public TrafficQueue(int maximumQueueSize)
    		{
    		vehicleQueue = new Queue(maximumQueueSize);
    		}
    
    	public void Arrive(Vehicle arrival)
    		{
    		vehicleQueue.Enqueue(arrival);//add vehicle to queue
    		}
    
    	public int TrafficQueueSize()
    		{
    		return vehicleQueue.Count;
    		}
    
    	
    	public Vehicle Depart()
    	{
    		Vehicle aVehicle;
    		if (vehicleQueue.Count>0)
    		{	
    			aVehicle=(Vehicle)vehicleQueue.Dequeue();
    			vehicleQueue.TrimToSize();
    			return (aVehicle);
    		}
    		else
    			return null;
    	}
    
    	public int TrafficInQueue()
    		{
    		if (vehicleQueue.Count>0)
    			foreach(Vehicle aVehicle in vehicleQueue)
    				aVehicle.ShowType();/* i want to send this text to the textbox in Form1 class */
    
    		else
    			
    			Console.WriteLine("Traffic Queue is Empty.");
    		return vehicleQueue.Count;
    		}
    	}
    }
    Code:
    using System;
    
    namespace TrafficControlSim
    {
    	public class Vehicle
    	{
    		private string registrationNumber;
    		private string vehicleType;
    
    		public Vehicle()
    		{
    			registrationNumber="TBD";
    			vehicleType="TBC"; 
    		}
    		public virtual void ShowDetails()
    		{
    			Console.WriteLine("Vehicle is a "+vehicleType);
    			Console.WriteLine("Registration number is "+registrationNumber);
    		}
    
    		public void SetRegistrationNumber(string number)
    		{
    			registrationNumber=number;
    		}
    		public void SetVehicleType(string type)
    		{
    			vehicleType=type;
    		}
    		public string GetRegistrationNumber()
    		{
    			return registrationNumber;
    		}
    		public string GetVehicleType()
    		{
    			return vehicleType;
    		}
    		public string ShowType()
    		{
    			return vehicleType+" ";
    		}
    
    	}/* end class */
    
    }/* end namespace */
    the Form1 class is rather large which inherits from System.Windows.Forms.Form this class has the textboxs i want to display . I have been working on this for a few days now and am getting quite frustrated due to my lack on knowledge around OOP

    thanks in advance
    Last edited by luigi40; 04-11-2005 at 02:42 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Good introduction to Windows Forms?
    By jcafaro10 in forum C# Programming
    Replies: 1
    Last Post: 05-19-2009, 06:11 PM
  2. accessing file properties
    By subodh_dg in forum Windows Programming
    Replies: 2
    Last Post: 12-26-2005, 12:23 AM
  3. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM