Ejemplo n.º 1
0
        public WorkGrid(int height, int width)
        {
            InitializeComponent();
            WorkingGrid.ShowGridLines = false;
            ToolBar eventHandler = new ToolBar();

            eventHandler.Topmost = true;
            eventHandler.Show();
            AppWindow = this;

            canvas_height = height;
            canvas_width  = width;

            // Check user's computer to see if they have terrible resolution...
            double screenHeight = SystemParameters.PrimaryScreenHeight;

            // Declare variables to set offset of the grid window.
            double windowWidth;
            double windowHeight;

            if (screenHeight >= 900)
            {
                // Declare variables to make the canvas larger based on values.
                // If height is 25 or less.
                if (height <= 25)
                {
                    if (width <= 25)
                    {
                        this.Height = height * 24;
                        this.Width  = width * 24;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 24;
                        windowWidth  = width * 24;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else if (width > 25 && width <= 50)
                    {
                        this.Height = height * 23;
                        this.Width  = width * 22;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 23;
                        windowWidth  = width * 22;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else if (width > 50 && width <= 75)
                    {
                        this.Height = height * 17;
                        this.Width  = width * 15;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 17;
                        windowWidth  = width * 15;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else
                    {
                        this.Height = height * 15.5;
                        this.Width  = width * 11.5;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 15.5;
                        windowWidth  = width * 11.5;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }
                }

                // If height is between 26 and 50.
                if (height > 25 && height <= 50)
                {
                    if (width <= 25)
                    {
                        this.Height = height * 12;
                        this.Width  = width * 16;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 12;
                        windowWidth  = width * 16;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else if (width > 25 && width <= 50)
                    {
                        this.Height = height * 12;
                        this.Width  = width * 12;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 12;
                        windowWidth  = width * 12;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else if (width > 50 && width <= 75)
                    {
                        this.Height = height * 12;
                        this.Width  = width * 12;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 12;
                        windowWidth  = width * 12;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else
                    {
                        this.Height = height * 11.5;
                        this.Width  = width * 10.5;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 11.5;
                        windowWidth  = width * 10.5;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }
                }

                // If height is between 51 and 75.
                if (height > 50 && height <= 75)
                {
                    if (width <= 25)
                    {
                        this.Height = height * 8;
                        this.Width  = width * 10;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 8;
                        windowWidth  = width * 10;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else if (width > 25 && width <= 50)
                    {
                        this.Height = height * 8;
                        this.Width  = width * 9.5;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 8;
                        windowWidth  = width * 9.5;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else if (width > 50 && width <= 75)
                    {
                        this.Height = height * 8;
                        this.Width  = width * 8;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 8;
                        windowWidth  = width * 8;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else
                    {
                        this.Height = height * 8;
                        this.Width  = width * 9.5;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 8;
                        windowWidth  = width * 9.5;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }
                }

                // If height is between 76 and 100.
                if (height > 75 && height <= 100)
                {
                    if (width <= 25)
                    {
                        this.Height = height * 6;
                        this.Width  = width * 8.5;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 6;
                        windowWidth  = width * 8.5;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else if (width > 25 && width <= 50)
                    {
                        this.Height = height * 6;
                        this.Width  = width * 8.5;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 6;
                        windowWidth  = width * 8.5;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else if (width > 50 && width <= 75)
                    {
                        this.Height = height * 6;
                        this.Width  = width * 8.5;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 6;
                        windowWidth  = width * 8.5;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else
                    {
                        this.Height = height * 6;
                        this.Width  = width * 6;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 6;
                        windowWidth  = width * 6;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }
                }
            }

            if (screenHeight < 900)
            {
                // Declare variables to make the canvas larger based on values.
                // If height is 25 or less.
                if (height <= 25)
                {
                    if (width <= 25)
                    {
                        this.Height = height * 22;
                        this.Width  = width * 22;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 22;
                        windowWidth  = width * 22;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else if (width > 25 && width <= 50)
                    {
                        this.Height = height * 17;
                        this.Width  = width * 20;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 17;
                        windowWidth  = width * 20;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 1.25;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else if (width > 50 && width <= 75)
                    {
                        this.Height = height * 15;
                        this.Width  = width * 13;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 15;
                        windowWidth  = width * 13;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 1.3;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else
                    {
                        this.Height = height * 13.5;
                        this.Width  = width * 9.5;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 13.5;
                        windowWidth  = width * 9.5;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 1.3;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }
                }

                // If height is between 26 and 50.
                if (height > 25 && height <= 50)
                {
                    if (width <= 25)
                    {
                        this.Height = height * 10;
                        this.Width  = width * 14;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 10;
                        windowWidth  = width * 14;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else if (width > 25 && width <= 50)
                    {
                        this.Height = height * 10;
                        this.Width  = width * 10;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 10;
                        windowWidth  = width * 10;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 1.75;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else if (width > 50 && width <= 75)
                    {
                        this.Height = height * 10;
                        this.Width  = width * 10;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 10;
                        windowWidth  = width * 10;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 1.5;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else
                    {
                        this.Height = height * 9.5;
                        this.Width  = width * 8.5;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 9.5;
                        windowWidth  = width * 8.5;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 1.4;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }
                }

                // If height is between 51 and 75.
                if (height > 50 && height <= 75)
                {
                    if (width <= 25)
                    {
                        this.Height = height * 6;
                        this.Width  = width * 8;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 6;
                        windowWidth  = width * 8;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else if (width > 25 && width <= 50)
                    {
                        this.Height = height * 6;
                        this.Width  = width * 7.5;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 6;
                        windowWidth  = width * 7.5;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else if (width > 50 && width <= 75)
                    {
                        this.Height = height * 6;
                        this.Width  = width * 6;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 6;
                        windowWidth  = width * 6;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 1.75;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else
                    {
                        this.Height = height * 6;
                        this.Width  = width * 7.5;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 6;
                        windowWidth  = width * 7.5;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 1.75;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }
                }

                // If height is between 76 and 100.
                if (height > 75 && height <= 100)
                {
                    if (width <= 25)
                    {
                        this.Height = height * 5.5;
                        this.Width  = width * 6.5;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 5.5;
                        windowWidth  = width * 6.5;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }

                    else if (width > 25 && width <= 50)
                    {
                        this.Height = height * 5.5;
                        this.Width  = width * 6.5;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 4;
                        windowWidth  = width * 6.5;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 4;
                    }

                    else if (width > 50 && width <= 75)
                    {
                        this.Height = height * 5.5;
                        this.Width  = width * 6.5;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 4;
                        windowWidth  = width * 6.5;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 4;
                    }

                    else
                    {
                        this.Height = height * 5.5;
                        this.Width  = width * 5.5;

                        // Dyanmically set grid window position based on window size.
                        windowHeight = height * 5.5;
                        windowWidth  = width * 5.5;
                        this.Left    = (SystemParameters.PrimaryScreenWidth - windowWidth) / 2;
                        this.Top     = (SystemParameters.PrimaryScreenHeight - windowHeight) / 3;
                    }
                }
            }


            for (int i = 0; i < width; i++)
            {
                WorkingGrid.ColumnDefinitions.Add(new ColumnDefinition());
            }
            for (int i = 0; i < height; i++)
            {
                WorkingGrid.RowDefinitions.Add(new RowDefinition());
            }

            for (int row = 0; row < WorkingGrid.RowDefinitions.Count; row++)
            {
                for (int col = 0; col < WorkingGrid.ColumnDefinitions.Count; col++)
                {
                    Button MyControl1 = new Button();
                    MyControl1.Content    = "";
                    MyControl1.Name       = "Button" + col.ToString();
                    MyControl1.Background = Brushes.White;
                    MyControl1.Click     += new RoutedEventHandler(eventHandler.Button_Click);
                    Grid.SetColumn(MyControl1, col);
                    Grid.SetRow(MyControl1, row);
                    WorkingGrid.Children.Add(MyControl1);
                }
            }
        }
Ejemplo n.º 2
0
        private void CreateButton_Click(object sender, RoutedEventArgs e)
        {
            int width  = Convert.ToInt32(WidthBox.Text);
            int height = Convert.ToInt32(HeightBox.Text);

            Canvas_Height = height;
            Canvas_Width  = width;

            if (Convert.ToString(Version.Content) == "Version: Basic")
            {
                //app.GRID_100.ShowGridLines = false; These seem redundant because i forgot what my plans with them were
                //app.GRID_75.ShowGridLines = false;
                //app.GRID_50.ShowGridLines = false;
                //app.GRID_25.ShowGridLines = false;



                if (width == height) //Checks if grid is a square (this is ideal)
                {
                    if (width == 25) // in the case that width does equal height and either is equal to 25
                    {
                        int count = 1;

                        for (int i = 0; i < height; i++)
                        {
                            for (int j = 0; j < width; j++)
                            {
                                Button MyControl1 = new Button();
                                MyControl1.Content    = "";
                                MyControl1.Name       = "Button" + count.ToString();
                                MyControl1.Background = Brushes.White;
                                MyControl1.Click     += new RoutedEventHandler(app.Button_Click);

                                Grid.SetColumn(MyControl1, j);
                                Grid.SetRow(MyControl1, i);
                                app.GRID_25.Children.Add(MyControl1);
                            }
                        }
                    } //End of if statement for 25

                    if (width == 50) // in the case that width does equal height and either is equal to 50
                    {
                        int count = 1;

                        for (int i = 0; i < height; i++)
                        {
                            for (int j = 0; j < width; j++)
                            {
                                Button MyControl1 = new Button();
                                MyControl1.Content    = "";
                                MyControl1.Name       = "Button" + count.ToString();
                                MyControl1.Background = Brushes.White;
                                MyControl1.Click     += new RoutedEventHandler(app.Button_Click);

                                Grid.SetColumn(MyControl1, j);
                                Grid.SetRow(MyControl1, i);
                                app.GRID_50.Children.Add(MyControl1);

                                count++;
                            }
                        }
                    }//End of if statement for 50

                    if (width == 75) // in the case that width does equal height and either is equal to 75
                    {
                        int count = 1;

                        for (int i = 0; i < height; i++)
                        {
                            for (int j = 0; j < width; j++)
                            {
                                Button MyControl1 = new Button();
                                MyControl1.Content    = "";
                                MyControl1.Name       = "Button" + count.ToString();
                                MyControl1.Background = Brushes.White;
                                MyControl1.Click     += new RoutedEventHandler(app.Button_Click);

                                Grid.SetColumn(MyControl1, j);
                                Grid.SetRow(MyControl1, i);
                                app.GRID_75.Children.Add(MyControl1);

                                count++;
                            }
                        }
                    }//End of if statement for 75

                    if (width == 100) // in the case that width does equal height and either is equal to 100
                    {
                        int count = 1;

                        for (int i = 0; i < height; i++)
                        {
                            for (int j = 0; j < width; j++)
                            {
                                Button MyControl1 = new Button();
                                MyControl1.Content    = "";
                                MyControl1.Name       = "Button" + count.ToString();
                                MyControl1.Background = Brushes.White;
                                MyControl1.Click     += new RoutedEventHandler(app.Button_Click);

                                Grid.SetColumn(MyControl1, j);
                                Grid.SetRow(MyControl1, i);
                                app.GRID_100.Children.Add(MyControl1);

                                count++;
                            }
                        }
                    } //End of if statement for 100
                }     //End of large if statement that checks for squares and reacts accordingly
                else  //incase the canvas is not a perfect square and the 100x100 grid has to be use to ensure all pixels fit
                {
                    int count = 1;

                    for (int i = 0; i < height; i++)
                    {
                        for (int j = 0; j < width; j++)
                        {
                            Button MyControl1 = new Button();
                            MyControl1.Content    = "";
                            MyControl1.Name       = "Button" + count.ToString();
                            MyControl1.Background = Brushes.White;
                            MyControl1.Click     += new RoutedEventHandler(app.Button_Click);

                            Grid.SetColumn(MyControl1, j);
                            Grid.SetRow(MyControl1, i);
                            app.GRID_100.Children.Add(MyControl1);

                            count++;
                        }
                    }
                }
                app.Height_Label.Content = "Height: " + HeightBox.Text;
                app.Width_Label.Content  = "Width: " + WidthBox.Text;
                app.Show();   //Shows PARTY_WINDOW once the canvas is loaded
                this.Close(); //closes MainWindow
            }
            else if (Convert.ToString(Version.Content) == "Version: Advanced")
            {
                Advanced adv = new Advanced();

                WorkGrid work = new WorkGrid(height, width);

                work.Topmost = true;
                adv.Show();

                work.Show();
                this.Close();
            }
        }