将形式分成相等的部分并选择标签 [英] divide form into equal parts and select label
问题描述
我有一个带有6个标签的Windows窗体(可以添加更多标签)和一个TextBox。不使用XAML。
我想做什么:
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.
推荐答案
在构造函数中:
In the constructor:
- 创建一个计时器。对于此应用程序,您可以使用System.Windows.Timer。
- 将计时器的间隔设置为3000.
- 启动计时器。
创建计时器的Tick事件处理程序。在处理程序中只调用Invalidate方法。
Create the timer's Tick event handler. In the handler just invoke the Invalidate method.
创建一个Paint事件处理程序。使用表格声明它
Create a Paint event handler. Declare it using the form
protected override void OnPaint ( PaintEventArgs e )
在油漆事件处理程序中
In the Paint event handler
- 划分表格进入象限。象限的尺寸为
- Divide form into quadrants. The quadrant's dimensions will be
new Size ( this.ClientRectangle.Width / 2,
this.ClientRectangle.Height / 2 );
创建一个MouseClick事件处理程序。使用表格声明它
Create a MouseClick event handler. Declare it using the form
protected override void OnMouseClick ( MouseEventArgs e )
在鼠标单击事件处理程序中
In the Mouse Click event handler
- 停止计时器。
- 在文本框中显示突出显示的象限中的标签(如果有)。
- 启动计时器。
如果您对此解决方案有疑问,请询问。
If you have questions regarding this solution, just ask.
希望有所帮助。
Hope that helps.
这篇关于将形式分成相等的部分并选择标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!