在C#中使用跟踪器的Poggendorf Illusion实验 [英] Poggendorf Illusion experiment using a trackerbar in C#

查看:137
本文介绍了在C#中使用跟踪器的Poggendorf Illusion实验的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助来设计涉及 Poggendorf光学错觉的实验 [ ^ ]用户必须移动以下位置之一使用 trackerbar(slider)绘制线,当他认为它与第二条线完全对齐时,(程序现在将记录trackerbar的值以及第1条线的点),他将单击下一个按钮,它将重置程序,并再次记录跟踪器和点数据.有人可以帮我弄清楚如何正确编写此代码.

谢谢..

[edit]链接已添加-OriginalGriff [/edit]

I need some help designing an experiment involving the Poggendorf optical illusion[^] The user has to move one of the lines using a trackerbar(slider) and when he thinks it is perfectly aligning with the 2nd line,(the program now records the trackerbar value and also the point of the line 1) he will click the next button which will reset the program and again records the trackerbar and point data. Can someone help me figure out how to properly code this.

Thanks..

[edit]link added - OriginalGriff[/edit]

推荐答案

用户单击NEXT按钮后,应该会出现另一个示例我实现下一个按钮并记录数据"

这取决于您要执行的操作:最简单的方法是让List< T>在您的表单的班级级别上,并每次都向其添加适当的值:
"an other sample should appear to the user once he click a NEXT button, so how can i implement this next button and record the data"

It depends on what you want to do with it: the simplest way is to have a List<T> at class level in your form, and add the appropriate value to it each time:
List<int> values = new List<int>();
public void Next_Click(object sender, EventArgs e)
   {
   values.Add(mySliderBar.Value);
   //Draw new sample, reset your slider, etc.
   }

这不会在程序成功执行之间保留数据,但是如果需要,有一些方法可以解决.

然后,当您要分析结果时,列表已准备就绪,正在等待!


非常感谢您对这个问题的关注,这对C#来说是新的,甚至对图形用户界面设计也很新.我了解您要使用该列表做什么,但是如果您不介意的话,您可以在意吗?我还需要弄清楚如何通过滑动滑块来移动一条直线,以及如何在单击下一个按钮之前仅捕获直线的点和滑块值."

好的.实际上并不太难,只需逐步进行即可.

1)使TrackBar正常工作.将其放在表单上,​​并将其设置为垂直方向".适当调整大小.给它起一个明智的名字! trackLineHeight可能是个好主意.
1.1)在窗体的Load事件中,将Maximum属性设置为TrackBar的高度.这允许用户方面的最佳区分.当您在那里时,将LargeChange属性设置为Maximum的10%,并且您可能还希望同时使用TickFrequency.
1.2)在表单中添加标签-这仅用于测试,因此将其保留为默认名称.
1.3)处理Trackbar Scroll事件:将Lable.Text属性设置为TrackBar.Value
1.4)运行它.移动指针时,值应在标签中更改.

2)画一些线!
2.1)在面板中添加一个面板-使它与TrackBar的高度相同.称之为明智的做法-您将在其中画出所有的线条!
2.2)处理面板的Paint事件.
2.3)在这种情况下,请在面板的整个高度上画两条线.
2.4)测试一下!

3)现在,复杂的位!
3.1)您需要弄清楚它们要匹配的采样线在做什么.它有一个角度吗?还是坡度和位置都是随机的?无论哪种方式,您都需要将起点(如果要更改它,则将坡度)存储为私有的,类级别的变量.当您在那里时,创建一个私有的Random变量:

This won''t persist the data between sucessive executions of the program, but there are ways round that if you need it.

Then, when you want to analyze the results, the list is ready and waiting!


"Thank you very much for your interest in this question, im kind of new to C# and even new to the graphical user interface designing. I understand what you are trying to do with the list but if you dont mind could you care to elaborate a little bit on that. I also need to figure out how to move one of the lines by sliding the slider and also how to capture only the point of the line and the slider value right before he clicks the next button."

Ok. It''s not actually too difficult, just take it stage by stage.

1) Get the TrackBar working. Drop it on your form, and set it to Vertical Orientation. Size it appropriately. Give it a sensible name! trackLineHeight is probably a good idea.
1.1) In your form Load event, set the Maximum property to the height of the TrackBar. This allows for the finest discrimination on the part of the user. While you are there, set the LargeChange property to 10% of Maximum, and you mioght want to play with the TickFrequency as well.
1.2) Add a label to your form - this is only for testing, so leave it as the default name.
1.3) Handle the Trackbar Scroll event: Set the Lable.Text property to the TrackBar.Value
1.4) Run it. When you move the pointer, the value should change in the label.

2) Draw some lines!
2.1) Add a Panel to you form - make it the same height as the TrackBar. Call it something sensible - you will draw all your lines in this!
2.2) Handle the panel Paint event.
2.3) In the event, draw your two lines the full height of the panel.
2.4) Test it!

3) Now, the complicated bits!
3.1) You need to work out what you are doing with the sample line they are to match. Does it have a single angle? Or is the slope random as well as the position? Either way, you need to store the start point (and slope if you are going to change it) as private, class level variables. While you are there, create a private Random variable:

private Random rand = new Random();


3.2)创建一种方法来生成新的匹配线".它使用rand生成斜率和起始高度,并将其存储在类变量中.它还会调用您的面板Invalidate方法.
3.3)在面板的Paint事件中,使用变量绘制实际的匹配线.
3.4)测试!放置一个按钮,每次单击该按钮时都会调用您的匹配行创建方法.确保图形始终有效并且可见...您可能需要微调可以生成的值,以确保匹配线和用户线均可见!

接下来的一点是使用斜率和轨迹栏中的值绘制用户线-但我暂时将其留给您,因为它是您在上面所做的工作的扩展! :laugh:


3.2) Create a method to generate a new "match line". It uses rand to generate a slope and a start height, and stores these in the class variables. It also calls your panel Invalidate method.
3.3) In your panel Paint event, use the variables to draw the actual match line.
3.4) Test it! Drop a button on which calls your match line create method each time it is clicked. Make sure that your drawing is always valid, and visible... You may need to fine tune the values you can generate to make sure that both the match line and the user line will be visible!

The next bit will be to draw the user line, using the slope and the value from the track bar - but I''ll leave that to you for the moment, as it is an extension of what you have done above! :laugh:


这篇关于在C#中使用跟踪器的Poggendorf Illusion实验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆