Example #1
0
        private void CanvasDrop_Event(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("deKleur"))
            {
                Brush   gesleepteKleur = (Brush)e.Data.GetData("deKleur");
                Ellipse bal            = new Ellipse();
                bal.Width  = 40;
                bal.Height = 40;
                bal.Fill   = gesleepteKleur;
                SolidColorBrush black = new SolidColorBrush(Colors.Black);
                bal.Stroke          = black;
                bal.StrokeThickness = 3;
                Point coordinaten = e.GetPosition(canvas);
                Canvas.SetLeft(bal, coordinaten.X - 20);
                Canvas.SetTop(bal, coordinaten.Y - 20);

                //Add drag event to each bal
                bal.MouseMove += DragBall_Event;

                canvas.Children.Add(bal);


                Bal balInLijst = new Bal(gesleepteKleur.ToString(), Convert.ToInt32(coordinaten.X), Convert.ToInt32(coordinaten.Y), "EmptyTag");
                BallenOpCanvas.Add(balInLijst);
            }
        }
Example #2
0
        private void CanvasRemoveBall_Event(object sender, DragEventArgs e)
        {
            List <UIElement> BallenLijstRemove = new List <UIElement>();

            if (e.Data.GetDataPresent("deKleur") && e.Data.GetDataPresent("CoordinatenX") && e.Data.GetDataPresent("CoordinatenY") && e.Data.GetDataPresent("Tag"))
            {
                Brush  gesleepteKleur = (Brush)e.Data.GetData("deKleur");
                Double X   = (Double)e.Data.GetData("CoordinatenX");
                Double Y   = (Double)e.Data.GetData("CoordinatenY");
                string tag = (string)e.Data.GetData("Tag").ToString();


                Bal bal = new Bal(Convert.ToString(gesleepteKleur), Convert.ToInt32(X), Convert.ToInt32(Y), "RemoveBalTag");

                foreach (UIElement removeBal in canvas.Children)
                {
                    //Point coordinaten = e.GetPosition(removeBal);
                    if (bal.xPos == X && bal.yPos == Y && removeBal.GetType() == typeof(Ellipse))
                    {
                        BallenLijstRemove.Add(removeBal);
                    }
                }

                foreach (Ellipse removeBal in BallenLijstRemove)
                {
                    if (bal.Tag == removeBal.Tag)
                    {
                        canvas.Children.Remove(removeBal);
                    }
                }

                BallenLijstRemove.Clear();
            }


            MessageBox.Show("test");
        }
Example #3
0
        private void CommandOpen_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            BallenOpCanvas.Clear();
            Controls.Visibility = Visibility.Visible;
            int Aantal = 0;

            try
            {
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.FileName   = "";
                dlg.DefaultExt = ".txt";
                dlg.Filter     = "Text Documents |*.txt";

                if (dlg.ShowDialog() == true)
                {
                    using (StreamReader bestand = new StreamReader(dlg.FileName))
                    {
                        //Lees de afbeelding in
                        string     ImagePath = bestand.ReadLine();
                        ImageBrush imgBrush  = new ImageBrush();
                        imgBrush.ImageSource = new BitmapImage(new Uri(ImagePath));
                        ImageRect.Fill       = imgBrush;
                        ImageRect.Tag        = ImagePath;
                        //Lees aantal ballen in
                        Aantal = Convert.ToInt32(bestand.ReadLine());


                        //Lees de gegevens van de ballen in
                        for (int i = 0; i < Aantal; i++)
                        {
                            string balKleur = bestand.ReadLine();
                            int    xPos     = Convert.ToInt32(bestand.ReadLine());
                            int    yPos     = Convert.ToInt32(bestand.ReadLine());

                            Ellipse bal = new Ellipse();
                            bal.Width  = 40;
                            bal.Height = 40;
                            var converter = new System.Windows.Media.BrushConverter();
                            var brush     = (Brush)converter.ConvertFromString(balKleur);
                            bal.Fill = brush;
                            SolidColorBrush black = new SolidColorBrush(Colors.Black);
                            bal.Stroke          = black;
                            bal.StrokeThickness = 3;

                            Canvas.SetLeft(bal, xPos - 20);
                            Canvas.SetTop(bal, yPos - 20);
                            canvas.Children.Add(bal);

                            Bal balInLijst = new Bal(balKleur, Convert.ToInt32(xPos), Convert.ToInt32(yPos), "EmptyTag");
                            BallenOpCanvas.Add(balInLijst);
                        }


                        //Lees de tekstboodschap in
                        WensBoodschap.Text = bestand.ReadLine();
                        //Lees de fontFamily in
                        ComboBoxLetterType.SelectedValue = new FontFamily(bestand.ReadLine());
                        //Lees de fontSize in
                        string Fontsize = bestand.ReadLine();
                        FontSizeLabel.Content  = Fontsize;
                        WensBoodschap.FontSize = Convert.ToInt32(Fontsize);

                        MenuOpslaan.IsEnabled = true;
                        MenuAfdruk.IsEnabled  = true;
                        StatusLabel.Content   = dlg.FileName;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Fout bij het openen van de wenskaart: " + ex.Message, "Openen error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }