예제 #1
0
        private void Del_Text()
        {
            TextBlock tb  = path_Con.FindName("newTextBlock" + (path_num - 1)) as TextBlock;
            TextBox   tbx = path_Con.FindName("newTextBox" + (path_num - 1)) as TextBox;

            if (tb != null && tbx != null && path_num > 1) //判断是否找到,以免在未添加前就误点了
            {
                path_Con.Children.Remove(tb);              //移除对应TextBlock控件
                path_Con.UnregisterName("newTextBlock" + (path_num - 1));
                path_Con.Children.Remove(tbx);             //移除对应TextBox控件
                path_Con.UnregisterName("newTextBox" + (path_num - 1));
                path_num--;
            }
            else if (path_num == 1)
            {
                box.Text = "点击地图输入路径点";
                path_num--;
            }
            else if (path_num == 0)
            {
                MessageBox.Show("路径已清空");
            }
            else
            {
                MessageBox.Show("找不到路径error:" + "\nnewTextBlock" + (path_num - 1) + "\nnewTextBox" + (path_num - 1) + "\n" + path_num);
            }
        }
        public static void Gap(WrapPanel wrapPanel, int left_lim, int right_lim, string name, int margin_left, bool flag)
        {
            TextBox txtBox;

            for (int j = left_lim; j <= right_lim; j++)
            {
                if (flag)
                {
                    txtBox = new TextBox()
                    {
                        Name = name + j, Margin = new Thickness(margin_left, 0, 0, 0), FontSize = 14, FontFamily = new FontFamily("Segoe UI")
                    };
                    if (margin_left != 0)
                    {
                        txtBox.PreviewTextInput += TxtBox_PreviewTextInput;
                    }
                    wrapPanel.Children.Add(txtBox);
                    wrapPanel.RegisterName(txtBox.Name, txtBox);
                }
                else
                {
                    if (wrapPanel.FindName(name + j) != null)
                    {
                        txtBox = (TextBox)wrapPanel.FindName(name + j);
                        wrapPanel.Children.Remove(txtBox);
                        wrapPanel.UnregisterName(txtBox.Name);
                    }
                }
            }
        }
        public static void Remove(WrapPanel wrapPanel, string name)
        {
            TextBox txtBox;
            var     i = 1;

            while (wrapPanel.FindName(name + i) != null)
            {
                txtBox = (TextBox)wrapPanel.FindName(name + i);
                wrapPanel.Children.Remove(txtBox);
                wrapPanel.UnregisterName(txtBox.Name);
                i++;
            }
        }