初步效果图:
xaml代码
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfDragMoveTest"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" x:Class="WpfDragMoveTest.TestBarCode"
mc:Ignorable="d"
Title="TestBarCode" Height="450" Width="800" Loaded="Window_Loaded" KeyDown="Window_KeyDown" KeyUp="Window_KeyUp" >
后台代码
public partial class TestBarCode : Window
{
int oldRows = 0;
int newRow = 0;
int oldCol = 0;
int newCol = 0;
private string checkPanel = "";
public TestBarCode()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
}
private void btn_AddRow_Click(object sender, RoutedEventArgs e)
{
oldRows = newRow;
newRow = newRow +2;
foreach (var item in this.grid_1.Children)
{
if (item is Grid)
{
Grid grid = item as Grid;
foreach (var item2 in grid.Children)
{
if (item2 is Grid)
{
Grid MainGrid = item2 as Grid;
//gridtab.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Pixel) });
//gridtab.RowDefinitions.Add(new RowDefinition());
for (int i = oldRows + 1; i <= newRow; i++)//行 for (int i = 1; i <= 5; i++)
{
if (i % 2 != 0)
MainGrid.RowDefinitions.Add(new RowDefinition());
else
MainGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Pixel) });
}
RichTextBox rtb = default(RichTextBox);
for (int r = newRow-1; r > oldRows-1; r--)
{
for (int c = 0; c < newCol; c++)
{
if (c % 2 == 0 && r % 2 == 0)
{
string name = "a_" + r + "_" + c;
rtb = new RichTextBox()
{
Name = name,
Margin = new Thickness(0),
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch,
BorderBrush = System.Windows.Media.Brushes.Transparent,
};
rtb.Document = new FlowDocument() { LineHeight = 1, PagePadding = new Thickness(0) };//修改行间距
rtb.MouseEnter += Rtb_MouseEnter;
rtb.Document.MouseLeftButtonDown += Document_MouseLeftButtonDown;
Grid.SetColumn(rtb, c);
Grid.SetRow(rtb, r);
MainGrid.Children.Add(rtb);
MainGrid.RegisterName(name, rtb);
}
if (r % 2 != 0 && c == 0)
{
string gsName = "gs_" + r + "_" + c;
GridSplitter splitter = new GridSplitter {Name=gsName, Height = 1, HorizontalAlignment = HorizontalAlignment.Stretch, BorderThickness = new Thickness(0), Background = System.Windows.Media.Brushes.Black };
Grid.SetColumn(splitter, c);
Grid.SetRow(splitter, r);
Grid.SetColumnSpan(splitter, 20);
MainGrid.Children.Add(splitter);
MainGrid.RegisterName(gsName, splitter);
}
}
}
}
}
}
}
}
private int x1 = 0;
private int y1 = 0;
private int x2 = 0;
private int y2 = 0;
private string isFirstPoint = "";
private void Document_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (isShift)
{
FlowDocument flowDocument = sender as FlowDocument;
RichTextBox richTextBox = flowDocument.Parent as RichTextBox;
if (string.IsNullOrEmpty(isFirstPoint))
{
isFirstPoint = richTextBox.Name;
string[] arr = richTextBox.Name.Split('_');
x1 = Convert.ToInt32(arr[1]);
y1 = Convert.ToInt32(arr[2]);
}
else
{
string[] arr = richTextBox.Name.Split('_');
x2 = Convert.ToInt32(arr[1]);
y2 = Convert.ToInt32(arr[2]);
int r1, r2, c1, c2 = 0;
if (x2 >= x1)
{
r2 = x2;
r1 = x1;
}
else
{
r2 = x1;
r1 = x2;
}
if (y2>=y1)
{
c2 = y2;
c1 = y1;
}
else
{
c2 = y1;
c1 = y2;
}
lb_x1.Content = r1;
lb_x2.Content = r2;
lb_y1.Content = c1;
lb_y2.Content = c2;
Grid MainGrid = GetGridMain();
foreach (UIElement item3 in MainGrid.Children)
{
if (item3 is RichTextBox)
{
RichTextBox rtb = item3 as RichTextBox;
rtb.Background = System.Windows.Media.Brushes.White;
}
}
for (int i = r1; i <= r2; i++)
{
for (int j = c1; j <= c2; j++)
{
string rtbName = "a_" + i + "_" + j;
RichTextBox rtb = MainGrid.FindName(rtbName) as RichTextBox;
if (rtb != null)
{
rtb.Background = System.Windows.Media.Brushes.Black;
}
}
}
}
checkPanel += richTextBox.Name + " _ ";
richTextBox.Background = System.Windows.Media.Brushes.Black;
}
else
{
checkPanel = "";
isFirstPoint = "";
x1 = x2 = y1 = y2 = 0;
foreach (var item in this.grid_1.Children)
{
if (item is Grid)
{
Grid grid = item as Grid;
foreach (var item2 in grid.Children)
{
if (item2 is Grid)
{
Grid MainGrid = item2 as Grid;
foreach (UIElement item3 in MainGrid.Children)
{
if (item3 is RichTextBox)
{
RichTextBox richTextBox = item3 as RichTextBox;
richTextBox.Background = System.Windows.Media.Brushes.White;
}
}
}
}
}
}
}
lbl_check.Content = checkPanel;
}
private Grid GetGridMain()
{
foreach (var item in this.grid_1.Children)
{
if (item is Grid)
{
Grid grid = item as Grid;
foreach (var item2 in grid.Children)
{
if (item2 is Grid)
{
Grid MainGrid = item2 as Grid;
return MainGrid;
}
}
}
}
return null;
}
private void SetGrid(int oldRows,int oldCol, int newRow, int newCol)
{
Grid MainGrid = default(Grid);
foreach (var item in this.grid_1.Children)
{
if (item is Grid)
{
Grid grid = item as Grid;
foreach (var item2 in grid.Children)
{
if (item2 is Grid)
{
MainGrid = item2 as Grid;
}
}
}
}
for (int i = oldRows +1 ; i <= newRow; i++)//行 for (int i = 1; i <= 5; i++)
{
if (i % 2 != 0)
{
MainGrid.RowDefinitions.Add(new RowDefinition());
}
else
{
MainGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Pixel) });
}
}
for (int i = oldCol+1; i <= newCol; i++)
{
if (i % 2 != 0)
{
MainGrid.ColumnDefinitions.Add(new ColumnDefinition());
}
else
{
MainGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Pixel) });
}
}
RichTextBox rtb = default(RichTextBox);
for (int c = 0; c <= 4; c++)
{
for (int r = 0; r <= 4; r++)
{
if (r == 0 && c % 2 != 0)
{
GridSplitter splitter = new GridSplitter { Width = 1, HorizontalAlignment = HorizontalAlignment.Stretch, BorderThickness = new Thickness(0), Background = System.Windows.Media.Brushes.Black };
Grid.SetColumn(splitter, c);
Grid.SetRow(splitter, r);
Grid.SetRowSpan(splitter, 5);
MainGrid.Children.Add(splitter);
}
else
{
if (c % 2 == 0 && r % 2 == 0)
{
rtb = new RichTextBox()
{
Margin = new Thickness(2),
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch,
BorderBrush = System.Windows.Media.Brushes.Transparent,
};
rtb.Document = new FlowDocument() { LineHeight = 1, PagePadding = new Thickness(0) };//修改行间距
Grid.SetColumn(rtb, c);
Grid.SetRow(rtb, r);
MainGrid.Children.Add(rtb);
}
if (r % 2 != 0 && c == 0)
{
GridSplitter splitter = new GridSplitter { Height = 1, HorizontalAlignment = HorizontalAlignment.Stretch, BorderThickness = new Thickness(0), Background = System.Windows.Media.Brushes.Black };
Grid.SetColumn(splitter, c);
Grid.SetRow(splitter, r);
Grid.SetColumnSpan(splitter, 5);
MainGrid.Children.Add(splitter);
}
}
}
}
}
private void btn_new_Click(object sender, RoutedEventArgs e)
{
//grid_1.Children.Clear();
oldRows = 0; oldCol = 0; newRow = 5; newCol = 5;
Border border = new Border() { BorderBrush = System.Windows.Media.Brushes.Black, BorderThickness = new Thickness(2) };
Grid gridTable1 = new Grid() { Name = "gridTable1", Margin = new Thickness(2), Background = System.Windows.Media.Brushes.White, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch };
grid_1.RegisterName("gridTable1", gridTable1);
this.grid_1.Children.Add(gridTable1);
gridTable1.Children.Add(border);
Grid MainGrid = new Grid() { Name = "gridTable", Background = System.Windows.Media.Brushes.White, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch };
gridTable1.Children.Add(MainGrid);
gridTable1.RegisterName("gridTable", MainGrid);
for (int i = oldRows + 1; i <= newRow; i++)//行 for (int i = 1; i <= 5; i++)
{
if (i % 2 != 0)
MainGrid.RowDefinitions.Add(new RowDefinition());
else
MainGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Pixel) });
}
for (int i = oldCol + 1; i <= newCol; i++)
{
if (i % 2 != 0)
{
MainGrid.ColumnDefinitions.Add(new ColumnDefinition());
}
else
{
MainGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Pixel) });
}
}
RichTextBox rtb = default(RichTextBox);
for (int c = oldCol; c <= newCol - 1; c++)
{
for (int r = oldRows; r <= newRow - 1; r++)
{
if (r == 0 && c % 2 != 0)
{
string gsName = "gs_" + r + "_" + c;
GridSplitter splitter = new GridSplitter {Name=gsName, Width = 1, HorizontalAlignment = HorizontalAlignment.Stretch, BorderThickness = new Thickness(0), Background = System.Windows.Media.Brushes.Black };
Grid.SetColumn(splitter, c);
Grid.SetRow(splitter, r);
Grid.SetRowSpan(splitter, 20);
MainGrid.Children.Add(splitter);
MainGrid.RegisterName(gsName, splitter);
}
else
{
if (c % 2 == 0 && r % 2 == 0)
{
string name = "a_" + r + "_" + c;
rtb = new RichTextBox()
{
Name = name,
Margin = new Thickness(0),
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch,
BorderBrush = System.Windows.Media.Brushes.Transparent,
};
rtb.Document = new FlowDocument() { LineHeight = 1, PagePadding = new Thickness(0) };//修改行间距
rtb.MouseEnter += Rtb_MouseEnter;
rtb.Document.MouseLeftButtonDown += Document_MouseLeftButtonDown;
Grid.SetColumn(rtb, c);
Grid.SetRow(rtb, r);
MainGrid.Children.Add(rtb);
MainGrid.RegisterName(name, rtb);
}
if (r % 2 != 0 && c == 0)
{
string gsName = "gs_" + r + "_" + c;
GridSplitter splitter = new GridSplitter {Name=gsName, Height = 1, HorizontalAlignment = HorizontalAlignment.Stretch, BorderThickness = new Thickness(0), Background = System.Windows.Media.Brushes.Black };
Grid.SetColumn(splitter, c);
Grid.SetRow(splitter, r);
Grid.SetColumnSpan(splitter, 20);
MainGrid.Children.Add(splitter);
MainGrid.RegisterName(gsName, splitter);
}
}
}
}
//gridTable1.Children.Add(MainGrid);
//this.grid_1.Children.Add(gridTable1);
}
private void Rtb_MouseEnter(object sender, MouseEventArgs e)
{
RichTextBox richTextBox = sender as RichTextBox;
lbl_name.Content = richTextBox.Name;
}
private void btn_AddCol_Click(object sender, RoutedEventArgs e)
{
oldCol = newCol;
newCol = newCol + 2;
foreach (var item in this.grid_1.Children)
{
if (item is Grid)
{
Grid grid = item as Grid;
foreach (var item2 in grid.Children)
{
if (item2 is Grid)
{
Grid MainGrid = item2 as Grid;
//gridtab.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Pixel) });
//gridtab.RowDefinitions.Add(new RowDefinition());
for (int i = oldCol + 1; i <= newCol; i++)//行 for (int i = 1; i <= 5; i++)
{
if (i % 2 != 0)
{
MainGrid.ColumnDefinitions.Add(new ColumnDefinition());
}
else
{
MainGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Pixel) });
}
}
RichTextBox rtb = default(RichTextBox);
for (int c = newCol -1; c > oldCol -1; c--)
{
for (int r = 0; r < newRow; r++)
{
if (r == 0 && c % 2 != 0)
{
string gsName = "gs_" + r + "_" + c;
GridSplitter splitter = new GridSplitter { Name=gsName, Width = 1, HorizontalAlignment = HorizontalAlignment.Stretch, BorderThickness = new Thickness(0), Background = System.Windows.Media.Brushes.Black };
Grid.SetColumn(splitter, c);
Grid.SetRow(splitter, r);
Grid.SetRowSpan(splitter, 20);
MainGrid.Children.Add(splitter);
MainGrid.RegisterName(gsName, splitter);
}
else if (r%2 == 0 && c%2==0)
{
string name = "a_" + r + "_" + c;
rtb = new RichTextBox()
{
Name = name,
Margin = new Thickness(0),
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch,
BorderBrush = System.Windows.Media.Brushes.Transparent,
};
rtb.Document = new FlowDocument() { LineHeight = 1, PagePadding = new Thickness(0) };//修改行间距
rtb.MouseEnter += Rtb_MouseEnter;
rtb.Document.MouseLeftButtonDown += Document_MouseLeftButtonDown;
Grid.SetColumn(rtb, c);
Grid.SetRow(rtb, r);
MainGrid.Children.Add(rtb);
MainGrid.RegisterName(name, rtb);
}
}
}
}
}
}
}
}
private void btn_merge_Click(object sender, RoutedEventArgs e)
{
string rtbName = "a_" + lb_x1.Content + "_" + lb_y1.Content;
Grid MainGrid = GetGridMain();
if (MainGrid != null)
{
foreach (var item3 in MainGrid.Children)
{
if (item3 is RichTextBox)
{
RichTextBox rtb = item3 as RichTextBox;
if (rtb.Name == rtbName)
{
//Grid.SetColumn(rtb, 0);
//Grid.SetRow(rtb, 0);
int colSpan = Convert.ToInt32(lb_y2.Content) - Convert.ToInt32(lb_y1.Content) + 1;
int rowSpan = Convert.ToInt32(lb_x2.Content) - Convert.ToInt32(lb_x1.Content) + 1;
Grid.SetRowSpan(rtb, rowSpan);
Grid.SetColumnSpan(rtb, colSpan);
Grid.SetZIndex(rtb, 100);
//MainGrid.Children.Add(rtb);
}
}
}
}
}
private void btn_split_Click(object sender, RoutedEventArgs e)
{
string rtbName = "a_" + lb_x1.Content + "_" + lb_y1.Content;
Grid MainGrid = GetGridMain();
if (MainGrid != null)
{
foreach (var item3 in MainGrid.Children)
{
if (item3 is RichTextBox)
{
RichTextBox rtb = item3 as RichTextBox;
if (rtb.Name == rtbName)
{
Grid.SetRowSpan(rtb, 1);
Grid.SetColumnSpan(rtb, 1);
Grid.SetZIndex(rtb, 1);
}
}
}
}
}
private bool isShift = false;
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyboardDevice.Modifiers == ModifierKeys.Shift && e.Key == Key.LeftShift)
{
isShift = true;
}
}
private void Window_KeyUp(object sender, KeyEventArgs e)
{
isShift = false;
}
private void btn_DeleteRow_Click(object sender, RoutedEventArgs e)
{
string strRowCol = lbl_name.Content.ToString();
string [] arr = strRowCol.Split('_');
int rowNum = Convert.ToInt32(arr[1]);
int colNum = Convert.ToInt32(arr[2]);
foreach (var item in this.grid_1.Children)
{
if (item is Grid)
{
Grid grid = item as Grid;
foreach (var item2 in grid.Children)
{
if (item2 is Grid)
{
Grid MainGrid = item2 as Grid;
//删除指定行的 RowDefinitions 及 GridSplitter
for (int i = 0; i <= MainGrid.RowDefinitions.Count; i++)
{
if (i == rowNum)
{
MainGrid.RowDefinitions.RemoveAt(rowNum);
if (rowNum == MainGrid.RowDefinitions.Count)
{
MainGrid.RowDefinitions.RemoveAt(rowNum - 1);
}
}
if (i == rowNum+1)
{
MainGrid.RowDefinitions.RemoveAt(rowNum);
}
}
newRow = newRow - 2;//新的行数赋值
//移除删除行中的控件
for (int i = 0; i < MainGrid.Children.Count; i++)
{
int gr = Grid.GetRow(MainGrid.Children[i]);
if (rowNum==0 && gr == 0) // 删除第 0 行
{
if (MainGrid.Children[i] is GridSplitter)
{
continue;
}
else if (MainGrid.Children[i] is RichTextBox)
{
RichTextBox richTextBox = MainGrid.Children[i] as RichTextBox;
if (richTextBox != null)
{
richTextBox.UnregisterName(richTextBox.Name);
}
MainGrid.Children.Remove(MainGrid.Children[i]);
i--;//避免跳过 **
}
}
else if (gr == rowNum || gr == rowNum + 1)
{
if (MainGrid.Children[i] is RichTextBox)
{
RichTextBox richTextBox = MainGrid.Children[i] as RichTextBox;
if (richTextBox != null)
{
richTextBox.UnregisterName(richTextBox.Name);
}
}
else if (MainGrid.Children[i] is GridSplitter)
{
GridSplitter gridSplitter = MainGrid.Children[i] as GridSplitter;
if (gridSplitter != null)
{
gridSplitter.UnregisterName(gridSplitter.Name);
}
}
MainGrid.Children.Remove(MainGrid.Children[i]);
i--;//避免跳过 **
}
else if (gr % 2 != 0)
{
if (MainGrid.Children[i] is RichTextBox)
{
RichTextBox richTextBox = MainGrid.Children[i] as RichTextBox;
if (richTextBox != null)
{
richTextBox.UnregisterName(richTextBox.Name);
}
MainGrid.Children.Remove(MainGrid.Children[i]);
i--;//避免跳过 **
}
}
if (rowNum -1 == gr && rowNum - 1 == MainGrid.RowDefinitions.Count)//选中最后一行进行删除
{
if (MainGrid.Children[i] is GridSplitter)
{
GridSplitter gridSplitter = MainGrid.Children[i] as GridSplitter;
if (gridSplitter != null)
{
gridSplitter.UnregisterName(gridSplitter.Name);
}
MainGrid.Children.Remove(MainGrid.Children[i]);
i--;//避免跳过 **
}
}
}
//修改删除行后面的控件名称
for (int i = 0; i < MainGrid.Children.Count; i++)
{
int gr = Grid.GetRow(MainGrid.Children[i]);
if (gr % 2 != 0)
{
//MainGrid.Children.Remove(MainGrid.Children[i]);
}
if (gr > rowNum)
{
int row = gr - 2;
if (MainGrid.Children[i] is RichTextBox)
{
RichTextBox richTextBox = MainGrid.Children[i] as RichTextBox;
string rtbName = richTextBox.Name;
richTextBox.UnregisterName(rtbName);
string[] arrName = rtbName.Split('_');
string newName = arrName[0] + "_" + row.ToString() + "_" + arrName[2];
Grid.SetRow(richTextBox, row);
richTextBox.Name = newName;
MainGrid.RegisterName(newName, richTextBox);
}
if (MainGrid.Children[i] is GridSplitter)
{
GridSplitter gridSplitter = MainGrid.Children[i] as GridSplitter;
string gsName = gridSplitter.Name;
gridSplitter.UnregisterName(gsName);
string[] arrName = gsName.Split('_');
string newName = arrName[0] + "_" + row.ToString() + "_" + arrName[2];
Grid.SetRow(gridSplitter, row);
gridSplitter.Name = newName;
MainGrid.RegisterName(newName, gridSplitter);
}
}
}
}
}
}
}
}
private void btn_DeleteCol_Click(object sender, RoutedEventArgs e)
{
string strRowCol = lbl_name.Content.ToString();
string[] arr = strRowCol.Split('_');
int rowNum = Convert.ToInt32(arr[1]);
int colNum = Convert.ToInt32(arr[2]);
foreach (var item in this.grid_1.Children)
{
if (item is Grid)
{
Grid grid = item as Grid;
foreach (var item2 in grid.Children)
{
if (item2 is Grid)
{
Grid MainGrid = item2 as Grid;
//删除指定行的 ColumnDefinitions 及 GridSplitter
for (int i = 0; i <= MainGrid.ColumnDefinitions.Count; i++)
{
if (i == colNum)
{
MainGrid.ColumnDefinitions.RemoveAt(colNum);
if (colNum == MainGrid.ColumnDefinitions.Count)
{
MainGrid.ColumnDefinitions.RemoveAt(colNum - 1);
}
}
if (i == colNum + 1)
{
MainGrid.ColumnDefinitions.RemoveAt(colNum);
}
}
newCol = newCol - 2;//新的行数赋值
//移除删除列中的控件
for (int i = 0; i < MainGrid.Children.Count; i++)
{
int gc = Grid.GetColumn(MainGrid.Children[i]);
if (colNum == 0 && gc == 0)
{
if (MainGrid.Children[i] is GridSplitter)
{
continue;
}
}
else if (gc == colNum || gc == colNum + 1)
{
if (MainGrid.Children[i] is RichTextBox)
{
RichTextBox richTextBox = MainGrid.Children[i] as RichTextBox;
if (richTextBox != null)
{
richTextBox.UnregisterName(richTextBox.Name);
}
}
else if (MainGrid.Children[i] is GridSplitter)
{
GridSplitter gridSplitter = MainGrid.Children[i] as GridSplitter;
if (gridSplitter != null)
{
gridSplitter.UnregisterName(gridSplitter.Name);
}
}
MainGrid.Children.Remove(MainGrid.Children[i]);
i--;//避免跳过 **
}
else if (gc % 2 != 0)
{
if (MainGrid.Children[i] is RichTextBox)
{
RichTextBox richTextBox = MainGrid.Children[i] as RichTextBox;
if (richTextBox != null)
{
richTextBox.UnregisterName(richTextBox.Name);
}
MainGrid.Children.Remove(MainGrid.Children[i]);
i--;//避免跳过 **
}
}
if (colNum - 1 == gc && colNum - 1 == MainGrid.ColumnDefinitions.Count)
{
if (MainGrid.Children[i] is GridSplitter)
{
GridSplitter gridSplitter = MainGrid.Children[i] as GridSplitter;
if (gridSplitter != null)
{
gridSplitter.UnregisterName(gridSplitter.Name);
}
MainGrid.Children.Remove(MainGrid.Children[i]);
i--;//避免跳过 **
}
}
}
//修改删除行后面的控件名称
for (int i = 0; i < MainGrid.Children.Count; i++)
{
int gc = Grid.GetColumn(MainGrid.Children[i]);
if (gc > colNum)
{
int col = gc - 2;
if (MainGrid.Children[i] is RichTextBox)
{
RichTextBox richTextBox = MainGrid.Children[i] as RichTextBox;
string rtbName = richTextBox.Name;
richTextBox.UnregisterName(rtbName);
string[] arrName = rtbName.Split('_');
string newName = arrName[0] + "_" + arrName[1] + "_" + col.ToString();
Grid.SetColumn(richTextBox, col);
richTextBox.Name = newName;
MainGrid.RegisterName(newName, richTextBox);
}
if (MainGrid.Children[i] is GridSplitter)
{
GridSplitter gridSplitter = MainGrid.Children[i] as GridSplitter;
string gsName = gridSplitter.Name;
gridSplitter.UnregisterName(gsName);
string[] arrName = gsName.Split('_');
string newName = arrName[0] + "_" + arrName[1] + "_" + col.ToString();
Grid.SetColumn(gridSplitter, col);
gridSplitter.Name = newName;
MainGrid.RegisterName(gsName, gridSplitter);
}
}
}
}
}
}
}
}
}