private void GenerateGrid(object sender, RoutedEventArgs e) { w = Convert.ToUInt16(Width.Text); h = Convert.ToUInt16(Height.Text); grid = new TextBlock[w, h]; line = new Oneline(w, h); /// /// // SolidColorBrush brush = new SolidColorBrush(new Color { A = 255, R = Convert.ToByte(R.Value), G = Convert.ToByte(G.Value), B = Convert.ToByte(B.Value) }); // color.Background = brush; int linew = 50 * (int)w; int lineh = 50 * (int)h; Grid MainG = new Grid(); MainG.HorizontalAlignment = HorizontalAlignment.Center; MainG.Width = linew + w; MainG.Height = lineh + h; BorderG.Width = linew + w; BorderG.Height = lineh + h; canvas.Children.Clear(); sphere.Width = linew + w; sphere.Height = lineh + h; col.Children.Clear(); row.Children.Clear(); all.Children.Clear(); for (int i = 0; i < h; i++) { MainG.RowDefinitions.Add(new RowDefinition()); if (i == h - 1) { col.Children.Add(new Border() { BorderThickness = new Thickness(1, 0, 1, 0), BorderBrush = new SolidColorBrush(new Color { A = 255, R = 0, G = 0, B = 0 }), Height = lineh + h, Width = 51 }); } else { col.Children.Add(new Border() { BorderThickness = new Thickness(1, 0, 0, 0), BorderBrush = new SolidColorBrush(new Color { A = 255, R = 0, G = 0, B = 0 }), Height = lineh + h, Width = 51 }); } } // col.Children.Add(new Border() { BorderThickness = new Thickness(1, 0, 1, 0), BorderBrush = new SolidColorBrush(new Color { A = 255, R = 0, G = 0, B = 0 }), Height = linew, Width = 50 }); for (int i = 0; i < w; i++) { MainG.ColumnDefinitions.Add(new ColumnDefinition()); if (i == w - 1) { row.Children.Add(new Border() { BorderThickness = new Thickness(0, 1, 0, 1), BorderBrush = new SolidColorBrush(new Color { A = 255, R = 0, G = 0, B = 0 }), Height = 51, Width = linew + w }); } else { row.Children.Add(new Border() { BorderThickness = new Thickness(0, 1, 0, 0), BorderBrush = new SolidColorBrush(new Color { A = 255, R = 0, G = 0, B = 0 }), Height = 51, Width = linew + w }); } } for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { grid[i, j] = new TextBlock { Text = "", Width = 50, Height = 50 }; grid[i, j].Background = new SolidColorBrush(Colors.DarkGray); grid[i, j].Name = "T" + (i + j * w).ToString(); grid[i, j].MouseDown += blockDown; grid[i, j].Margin = new Thickness(1, 1, 1, 1); grid[i, j].Opacity = 0.5; Grid.SetRow(grid[i, j], j); Grid.SetColumn(grid[i, j], i); MainG.Children.Add(grid[i, j]); } } Grid.SetColumn(MainG, 0); all.Children.Add(MainG); //row.Children.Add(new Border() { BorderThickness = new Thickness(0, 1, 0, 0), BorderBrush = new SolidColorBrush(new Color { A = 255, R = 0, G = 0, B = 0 }), Height = 50, Width = lineh }); }