CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2000
    Location
    Germany, Franken
    Posts
    257

    My UserControl is only displayed once.

    Hi, I've got a simple UserControl:
    Code:
    	public class CtlStandardPlace : System.Windows.Forms.UserControl
    	{
    		private SimuObject m_place;
    		public SimuObject Place
    		{
    			get
    			{
    				return m_place;				
    			}
    			set
    			{
    				m_place = value;	
    			}
    		}
    		public CtlStandardPlace()
    		{
    			//
    			// The InitializeComponent() call is required for Windows Forms designer support.
    			//
    			InitializeComponent();
    			
    /*			m_place = new SimuStandardPlace();
    			m_place.X = 1;
    			m_place.Y = 1;
    			m_place.Dx = 10;
    			m_place.Dy = 10;			
    		*/
    		}
    
    		
    		public CtlStandardPlace(SimuObject place)
    		{
    			m_place = (SimuStandardPlace)place;
    		}
    		
    	
    		#region Windows Forms Designer generated code
    		/// <summary>
    		/// This method is required for Windows Forms designer support.
    		/// Do not change the method contents inside the source code editor. The Forms designer might
    		/// not 
    		/// 
    		private void InitializeComponent() {
    		
    		this.Name = "CtlStandardPlace";
    			this.Size = new System.Drawing.Size(10, 10);
    		}
    		#endregion
    		
    		protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs e)
    		{
    			base.OnPaintBackground(e);
    			BrushFactory bf = new BrushFactory();
    			SolidBrush brush;
    			if(m_place != null)
    			{				
    				System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Black);
    				Rectangle rect = new Rectangle(m_place.X,m_place.Y,m_place.Dx,m_place.Dy);
    				System.Diagnostics.Debug.WriteLine(rect.ToString());
    				e.Graphics.DrawRectangle(pen, rect);				
    				brush = bf.CreateBrush(m_place) as SolidBrush;
    				System.Diagnostics.Debug.WriteLine(System.DateTime.Now.ToString() + brush.ToString() + brush.Color.ToString());
    				if(brush == null)
    					return;
    				e.Graphics.FillRectangle(brush, rect.Left+1,rect.Top+1,rect.Right-1,rect.Bottom-1);
    				e.Graphics.DrawString(this.ToString(), this.Font,
              brush, rect.Width + 3,
              (rect.Height - this.Font.Height) / 2);
    
    			}		
    		}
    		
    		protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    		{
    			base.OnPaint(e);
    			BrushFactory bf = new BrushFactory();
    			SolidBrush brush;
    			if(m_place != null)
    			{				
    				System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Black);
    				Rectangle rect = new Rectangle(m_place.X,m_place.Y,m_place.Dx,m_place.Dy);
    				System.Diagnostics.Debug.WriteLine(rect.ToString());
    				e.Graphics.DrawRectangle(pen, rect);				
    				brush = bf.CreateBrush(m_place) as SolidBrush;
    				System.Diagnostics.Debug.WriteLine(System.DateTime.Now.ToString() + brush.ToString() + brush.Color.ToString());
    				if(brush == null)
    					return;
    				e.Graphics.FillRectangle(brush, rect.Left+1,rect.Top+1,rect.Right-1,rect.Bottom-1);
    			}
    		}
    	}
    and a simple testing programm:

    Code:
    		public MainForm()
    		{
    			//
    			// The InitializeComponent() call is required for Windows Forms designer support.
    			//
    			InitializeComponent();
    			
    			//
    			// TODO: Add constructor code after the InitializeComponent() call.
    			//
    			
    			SimuEntryPlace dummy1 = new SimuEntryPlace();
    			dummy1.X = 1;
    			dummy1.Y = 1;
    			dummy1.Dx = 10;
    			dummy1.Dy = 10;		
    			SimuBuilderControls.CtlStandardPlace place;			
    			place = new SimuBuilderControls.CtlStandardPlace();		
    			place.Place = dummy1;		  
    		    this.Controls.Add(place);
    		
    			SimuStandardPlace dummy2 = new SimuStandardPlace();
    			dummy2.X = 11;
    			dummy2.Y = 1;
    			dummy2.Dx = 10;
    			dummy2.Dy = 10;
    			place = new SimuBuilderControls.CtlStandardPlace();		
    			place.Place = dummy2;		  
    		    this.Controls.Add(place);
    		    this.Invalidate();
    
    		}
    If i run that programm the first dummy-place is shown but the second is missing. It seems that I made something wrong, but I have no idea what it could be.

    Anyone here got an idea?

    Thanks
    Akademos

  2. #2
    Join Date
    Dec 2003
    Location
    http://map.search.ch/zuerich.en.html
    Posts
    1,074

    Re: My UserControl is only displayed once.

    Would be easier if you'd put the code in a file that would compile.

    Just looking at the code looks like the UserControl is 10x10 and dummy2.X = 11 ie. out of view.

    I take it you are not using Visual Studio to create these examples?
    Useful? Then click on (Rate This Post) at the top of this post.

  3. #3
    Join Date
    Mar 2000
    Location
    Germany, Franken
    Posts
    257

    Re: My UserControl is only displayed once.

    Sorry for late reply, but I was on a buisness trip.
    In the attachment there is my project. It is a #develop-project but it should also be easy to create a VS.NET-project from the files. Perhaps some sees what I was oversee.

    Thanks in Advance

    Akademos
    Attached Files Attached Files

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

Featured