我有这个财富之轮application。轮子是整个图像。 当车轮停止旋转时,我能够旋转并检测角度。 这是代码:
private void SpinBtn_Click(object sender, RoutedEventArgs e)
{
var ease = new PowerEase { EasingMode = EasingMode.EaseOut };
Random rng = new Random(Guid.NewGuid().GetHashCode());
//DoubleAnimation(FromValue. ToValue, Duration)
double degree = rng.Next(360, 720);
DoubleAnimation myanimation = new DoubleAnimation
(0, degree, new Duration(TimeSpan.FromSeconds(3)));
double resultAngle = degree - 360;
double num = resultAngle % 45;
double quadrant = num + 1;
data.Content = resultAngle;
//Adding Power ease to the animation
myanimation.EasingFunction = ease;
RotateTransform rotate = new RotateTransform();
img.RenderTransform = rotate;
img.RenderTransformOrigin = new Point(0.5, 0.5);
rotate.BeginAnimation(RotateTransform.AngleProperty, myanimation);
}
但是,如何检查用户是否将文字拖到文本框中,并指向指针指向的图像?我的讲师要求我将单词(我从数据库中获取)存储到数组中,将对象编号存储在数组中,但我不知道该怎么做。 例如,对象编号1将落在角度范围0-45,对象编号2落入46-90等等。我如何进行检查?
答案 0 :(得分:0)
我不太确定我是否完全明白这里的问题是什么!
但您只需使用Dictionary
来保存每个45度切片的字符串值,并将其与用户拖动一词进行检查。
Dictionary<int, string> dict = new Dictionary<int, string>();
dict.Add(1, "Eraser");
dict.Add(2, "Glue");
dict.Add(3, "Pen");
dict.Add(4, "Scissors");
dict.Add(5, "Stapler");
dict.Add(6, "Sharpener");
dict.Add(7, "Ruler");
dict.Add(8, "Pencil");
并将您的代码更改为:
double degree = rng.Next(360, 720);
double resultAngle = degree - 360;
int num = (int)Math.Ceiling(resultAngle / 45);
然后,指针当前指向的元素的名称将是:
string currentElem = dict[num];