Click here to Skip to main content
15,901,283 members
Please Sign up or sign in to vote.
2.64/5 (4 votes)
See more:
I have a windows form with 6 labels (more could be added) and a TextBox. without using XAML.

what i want to do :
1) Divide the form into 4 equal quadrants (Quadrants 1,2,3,4). (drawing two colored lined)
2) Color each quadrant for 3 seconds and turn it back to transparent in a sequence. It implies that Form quadrant 1 is red for 3 second then transparent. quadrant 2 is then red for 3 seconds and then transparent and so on infinately.
 
3) Once a mouse click event is encountered (could be anywhere on the form). Find the quadrant which was colored red at that time.
 
4) Check in this quadrant if (number of labels == 1) if yes-> show the label.text in the textbox. if not-> then start from step 1 by taking input as the coordinates and size of the currently colored quadrant.

I am a new at this. Can anyone please tell me how i do this.
Posted
Updated 6-Jun-14 21:35pm
v2
Comments
You should search on Google and try yourself. If you face any specific issue, then come back and ask another question.
gggustafson 7-Jun-14 10:44am    
You state "6 labels". Do you mean the Label WinForm control? Or something else?

At the end of step 4 you state to "start from step 1". This will increase the number of "quadrants". Did you mean to return to step 2?

If the form has been divided into 4 equal quadrants, where is the TextBox?
gggustafson 7-Jun-14 10:52am    
You seem to imply that the labels are placed in various locations on the form. Then the form has its quadrants defined. One quadrant is colored. Does any label in the colored quadrant show through? What happend if the label occupies nore than one quadrant?

1 solution


In the constructor:



  • Create a timer. For this application, you can use System.Windows.Timer.
  • Set the timer's Interval to 3000.
  • Start the timer.


Create the timer's Tick event handler. In the handler just invoke the Invalidate method.



Create a Paint event handler. Declare it using the form


C#
protected override void OnPaint ( PaintEventArgs e )


In the Paint event handler



  • Divide form into quadrants. The quadrant's dimensions will be
    C#
    new Size ( this.ClientRectangle.Width / 2,
               this.ClientRectangle.Height / 2 );
    

  • Draw the quadrant separator lines.
  • Draw the quadrants.
  • Revise quadrant colors. The colors of each quadrant should be maintained in an array of colors.


Create a MouseClick event handler. Declare it using the form


C#
protected override void OnMouseClick ( MouseEventArgs e )


In the Mouse Click event handler



  • Stop the timer.
  • Display the Label in highlighted quadrant, if any, in the TextBox.
  • Start the timer.


If you have questions regarding this solution, just ask.



Hope that helps.

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900