在用户输入上动态删除表单中的按钮

时间:2014-02-04 21:39:42

标签: c# forms button

我有问题。我正在使用C#Windows窗体制作Web浏览器,并且我添加了书签。我的问题?删除它们。我似乎无法获得将删除书签的好代码!这是我的代码:

private void button2_Click_1(object sender, EventArgs e)
    {
        int removeBookmarkI = 0;
        string removeBookmarkName = Microsoft.VisualBasic.Interaction.InputBox("Which bookmark would you like to delete?", "Delete Bookmark", "Google");

        for (int i = 0; i < bookmark_names.Length; i++)
        {
            if (bookmark_names[i] == removeBookmarkName)
            {
                removeBookmarkI = i;
                string[] holdBookmark_names_temp = new string[bookmark_names.Length];
                string[] holdBookmark_url_temp = new string[bookmark_names.Length];
                for (int j = i; j < bookmark_names.Length - 1; j++)
                {
                    bookmark_names[j] = bookmark_names[j + 1];
                    bookmark_url[j] = bookmark_url[j + 1];
                }
                int skipNum = 0;
                for (int j = 0; j < bookmark_names.Length - 1; j++)
                {
                    if (bookmark_names[j] == removeBookmarkName)
                    {
                        skipNum = 1;
                    }
                    holdBookmark_names_temp[j] = bookmark_names[j + skipNum];
                    holdBookmark_url_temp[j] = bookmark_url[j + skipNum];
                }
                bookmark_names = new string[bookmark_names.Length - 1];
                bookmark_url = new string[bookmark_url.Length - 1];
                for (int j = 0; j < bookmark_names.Length; j++)
                {
                    bookmark_names[j] = holdBookmark_names_temp[j];
                    bookmark_url[j] = holdBookmark_url_temp[j];
                }
                this.Controls.Remove(buttonsAdded[removeBookmarkI]);
                buttonsAdded.Remove(buttonsAdded[bookmark_names.Length - 1]);
                this.Controls.Remove(buttonsAdded[bookmark_names.Length - 1]);

                System.IO.File.WriteAllLines("C:\\Users\\Public\\IAmAPerson_Web_Explorer\\bookmarks\\bookmark_names.txt", bookmark_names);
                System.IO.File.WriteAllLines("C:\\Users\\Public\\IAmAPerson_Web_Explorer\\bookmarks\\bookmarks.txt", bookmark_url);
                bookmark_names = new string[bookmark_names.Length - 1];
                bookmark_url = new string[bookmark_url.Length - 1];
                bookmark_names = System.IO.File.ReadAllLines(@"C:\Users\Public\IAmAPerson_Web_Explorer\bookmarks\bookmark_names.txt");
                bookmark_url = System.IO.File.ReadAllLines(@"C:\Users\Public\IAmAPerson_Web_Explorer\bookmarks\bookmarks.txt");
                bookmarkButtonSpacing -= 100;
                break;
            }
            if (i == bookmark_names.Length - 1)
            {
                System.Windows.Forms.MessageBox.Show("You do not have a bookmark named " + removeBookmarkName + "!");
            }
        }
    }

提示您要删除哪个书签,将其删除,将所有其他书签移过,并将其从Web资源管理器目录文件中删除。这是怎么回事?我怎样才能解决这个问题?我正在使用名为buttonsAdded的按钮列表。另外,我知道这段代码可能是C#EVER中看起来最糟糕的代码,但我是新手,我还没有学习最好的编码方法。

0 个答案:

没有答案