Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C#: Avoiding Overlapping Labels using getChildAtPoint()

  • 26-04-2006 2:17pm
    #1
    Registered Users, Registered Users 2 Posts: 354 ✭✭


    Edit: After each label is created and added to the display the references to that label are recycled for the next label to tbe created. Could that be the source of my problem? The only Label I have been able to manipulate using getChildAtPoint was an instance variable so does the program need a reference to the label to exist somewhere even if that reference wasn't needed to identify it?

    I'm working on a project which involves drawing up a timeline. The problem I'm having is when two events on the timeline are too close and the Label connected to the first covers that of the second.
    What I'm trying to do to get around this is shift the second Label to the right when it is created useing exceptions to locate the first. However I can't get this working and my code doesn't seem to be having any effect at all; it simply runs through to the "return new point .." every time.
    I'm very new at C# and trying to learn it by myself so it might well be I'm making a simple error or making things difficult for myself. I'ld welcome any hints and tips.
    This is the method for generating the Point for the new Label location.

    All Labels are 100 x 80.
    xVal, yVal indicate centre-top of the Label.
    private Point clearSpace( int xVal, int yVal )
    	{
    		int xValue = xVal;
    		int yValue = yVal;
                              // Try to find a Label on the left
    		Label Left = (Label)this.GetChildAtPoint( new Point( xValue - 45, yValue - 40 ) );
                              // Try to find a Label on the right.
    		Label Right = (Label)this.GetChildAtPoint( new Point( xValue + 45, yValue -40 ) );
    		Point spot = new Point( 0, 0 );
    		try
    		{
    			Left.Text = Left.Text;
    			return clearSpace( xValue + 10, yValue );
    		}
    		catch( NullReferenceException )
    		{
    			try
    			{
    				Right.Text = Right.Text;
    				return clearSpace( xValue, yValue + 10 );
    			}
    			catch( NullReferenceException )
    			{
    				return new Point( xValue - 50, yValue );
    			}
    		}
    		return spot;
    	}
    


Advertisement