Exemplo n.º 1
0
        private void LoadWords(string[] words)
        {
            Random r = new Random();

            foreach (string word in words)
            {
                if (!string.IsNullOrWhiteSpace(word))
                {
                    WordButton button = new WordButton {
                        Content = word
                    };
                    button.PreviewMouseLeftButtonDown += btn_PreviewMouseLeftButtonDown;
                    button.PreviewMouseLeftButtonUp   += btn_PreviewMouseLeftButtonUp;
                    button.PreviewMouseMove           += btn_PreviewMouseMove;
                    button.KeyUp += Button_KeyUp;

                    button.SetFont(fontFamily, fontSize);

                    buttons.Add(button);
                    WordCanvas.Children.Add(button);

                    Canvas.SetLeft(button, r.Next(0, (int)(this.Width - button.Width - 50)));
                    Canvas.SetTop(button, r.Next(0, (int)((this.Height - 250) - button.Height)));
                }
            }
        }
Exemplo n.º 2
0
 static public void BringToFront(Canvas pParent, WordButton pToMove)
 {
     try
     {
         int        currentIndex = Canvas.GetZIndex(pToMove);
         int        zIndex       = 0;
         int        maxZ         = 0;
         WordButton child;
         for (int i = 0; i < pParent.Children.Count; i++)
         {
             if (pParent.Children[i] is WordButton &&
                 pParent.Children[i] != pToMove)
             {
                 child  = pParent.Children[i] as WordButton;
                 zIndex = Canvas.GetZIndex(child);
                 maxZ   = Math.Max(maxZ, zIndex);
                 if (zIndex > currentIndex)
                 {
                     Canvas.SetZIndex(child, zIndex - 1);
                 }
             }
         }
         Canvas.SetZIndex(pToMove, maxZ);
     }
     catch (Exception ex)
     {
     }
 }
Exemplo n.º 3
0
 private void btn_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     IsDragging           = true;
     draggedItem          = (WordButton)sender;
     itemRelativePosition = e.GetPosition(draggedItem);
 }