private void Click_Push(object sender, RoutedEventArgs e) { input = textInput.Text; if (input.Length != 0) { numOfBlocks += 1; if (numOfBlocks >= 7) { label4.Content = "你输入超过了6个数!"; label4.FontSize = 20; label4.Foreground = new SolidColorBrush(Colors.Red); label4.FontWeight = FontWeights.Bold; label4.Margin = new Thickness(200, 200, 0, 0); numOfBlocks--; return; } label4.Content = "(push最多6个数)"; blocks[numOfBlocks - 1] = new MovingBlock(); label3.Content = "Pushing Value: "; textInput.Clear(); textInput.IsEnabled = false; button1.IsEnabled = false; button2.IsEnabled = false; button3.IsEnabled = false; blocks[numOfBlocks - 1].movingNumber.Content = input; blocks[numOfBlocks - 1].movingNumber.Margin = new Thickness(140, 53, 0, 0); canvas.Children.Add(blocks[numOfBlocks - 1].movingNumber); blocks[numOfBlocks - 1].dataArea.Margin = new Thickness(243, 110, 0, 0); blocks[numOfBlocks - 1].dataLeft = blocks[numOfBlocks - 1].dataArea.Margin.Left; blocks[numOfBlocks - 1].dataTop = blocks[numOfBlocks - 1].dataArea.Margin.Top; canvas.Children.Add(blocks[numOfBlocks - 1].dataArea); blocks[numOfBlocks - 1].pointerArea.Margin = new Thickness(blocks[numOfBlocks - 1].dataArea.Margin.Left + blocks[numOfBlocks - 1].dataArea.Width, blocks[numOfBlocks - 1].dataArea.Margin.Top, 0, 0); blocks[numOfBlocks - 1].pointerLeft = blocks[numOfBlocks - 1].dataArea.Margin.Left + blocks[numOfBlocks - 1].dataArea.Width; blocks[numOfBlocks - 1].pointerTop = blocks[numOfBlocks - 1].dataArea.Margin.Top; canvas.Children.Add(blocks[numOfBlocks - 1].pointerArea); blocks[numOfBlocks - 1].arrow.X1 = label2.Margin.Left + label2.Width / 2; blocks[numOfBlocks - 1].arrow.Y1 = label2.Margin.Top + label2.Height / 2; blocks[numOfBlocks - 1].arrow.X2 = blocks[numOfBlocks - 1].dataArea.Margin.Left; blocks[numOfBlocks - 1].arrow.Y2 = blocks[numOfBlocks - 1].dataArea.Margin.Top + blocks[numOfBlocks - 1].dataArea.Height / 2; canvas.Children.Add(blocks[numOfBlocks - 1].arrow); //创建DispatcherTimer对象 System.Windows.Threading.DispatcherTimer tmr1 = new System.Windows.Threading.DispatcherTimer(); //设置间隔时间 tmr1.Interval = TimeSpan.FromSeconds(0.01); //绑定函数 tmr1.Tick += new EventHandler(Tmr1_Tick); tmr1.Start();//启动计时器 } }
private void Click_Enqueue(object sender, RoutedEventArgs e) { input = textInput.Text; if (input.Length != 0) { numOfBlocks += 1; if (numOfBlocks > 6) { label5.Content = "你输入超过了6个数!"; label5.FontSize = 20; label5.Foreground = new SolidColorBrush(Colors.Red); label5.FontWeight = FontWeights.Bold; label5.Margin = new Thickness(200, 200, 0, 0); numOfBlocks--; return; } label5.Content = "(enqueue不超过6个数)"; blocks[numOfBlocks - 1] = new MovingBlock(); label4.Content = "Enqueuing Value: "; textInput.Clear(); textInput.IsEnabled = false; button1.IsEnabled = false; button2.IsEnabled = false; button.IsEnabled = false; blocks[numOfBlocks - 1].movingNumber.Content = input; blocks[numOfBlocks - 1].movingNumber.Margin = new Thickness(160, 55, 0, 0); canvas.Children.Add(blocks[numOfBlocks - 1].movingNumber); blocks[numOfBlocks - 1].dataArea.Margin = new Thickness(265, 113, 0, 0); blocks[numOfBlocks - 1].dataLeft = blocks[numOfBlocks - 1].dataArea.Margin.Left; blocks[numOfBlocks - 1].dataTop = blocks[numOfBlocks - 1].dataArea.Margin.Top; canvas.Children.Add(blocks[numOfBlocks - 1].dataArea); blocks[numOfBlocks - 1].pointerArea.Margin = new Thickness(blocks[numOfBlocks - 1].dataArea.Margin.Left + blocks[numOfBlocks - 1].dataArea.Width, blocks[numOfBlocks - 1].dataArea.Margin.Top, 0, 0); blocks[numOfBlocks - 1].pointerLeft = blocks[numOfBlocks - 1].dataArea.Margin.Left + blocks[numOfBlocks - 1].dataArea.Width; blocks[numOfBlocks - 1].pointerTop = blocks[numOfBlocks - 1].dataArea.Margin.Top; canvas.Children.Add(blocks[numOfBlocks - 1].pointerArea); //第一个block,head的指针指向它 blocks[0].arrow.X1 = label2.Margin.Left + (label2.Width / 2); blocks[0].arrow.Y1 = label2.Margin.Top + (label2.Height / 2); if (numOfBlocks > 1)//X1,Y1默认为0,不指定会指向左上角 { blocks[numOfBlocks - 1].arrow.X1 = blocks[numOfBlocks - 1 - 1].pointerLeft + blocks[numOfBlocks - 1 - 1].pointerArea.Width; blocks[numOfBlocks - 1].arrow.Y1 = blocks[numOfBlocks - 1 - 1].pointerTop + (blocks[numOfBlocks - 1 - 1].pointerArea.Height / 2); } blocks[numOfBlocks - 1].arrow.X2 = blocks[numOfBlocks - 1].dataArea.Margin.Left; blocks[numOfBlocks - 1].arrow.Y2 = blocks[numOfBlocks - 1].dataArea.Margin.Top + (blocks[numOfBlocks - 1].dataArea.Height / 2); canvas.Children.Add(blocks[numOfBlocks - 1].arrow); //arrow from tail //tailArrow.X1 = label3.Margin.Left + (label3.Width / 2); //tailArrow.Y1 = label3.Margin.Top + (label3.Height / 2); tailArrow.X2 = blocks[numOfBlocks - 1].dataArea.Margin.Left + (blocks[numOfBlocks - 1].dataArea.Width / 2); tailArrow.Y2 = blocks[numOfBlocks - 1].dataArea.Margin.Top + blocks[numOfBlocks - 1].dataArea.Height; //tailArrow.HeadWidth = 8; //tailArrow.HeadHeight = 4; tailArrow.Stroke = new SolidColorBrush(Colors.Black); System.Windows.Threading.DispatcherTimer tmr1 = new System.Windows.Threading.DispatcherTimer(); tmr1.Interval = TimeSpan.FromSeconds(0.01); tmr1.Tick += new EventHandler(Tmr1_Tick); tmr1.Start(); } }