示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            // listbox1.Clear();

            listbox1.Items.Clear();
            Find(richtext, textBox1.Text, x, y);
            startIndex = 0;
            clicked    = true;
            var           lines = richtext.Lines;
            int           count = 0;
            List <string> items = new List <string>();

            foreach (var x in lines)
            {
                count++;
                if (x.Contains(textBox1.Text))
                {
                    SearchedItems s = new SearchedItems();
                    s.LineNumber = count;
                    s.LineText   = x;
                    s.findForm   = true;
                    // Items.Add(s);
                    listbox1.Items.Add(s);
                    //listbox1.AppendText(Items.ToString());
                    //richtext2.AppendText("Line" + s.LineNumber + ":  ");
                    Console.WriteLine(x + "\n");
                    // richtext2.AppendText(s.LineText + "\n");
                    listbox1.Visible = true;
                    items.Add(x);
                }
            }
            Select(listbox1, textBox1.Text, Color.Yellow, FontStyle.Bold);
        }
示例#2
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            listBox.Items.Clear();
            int    hits = 0;
            string line;
            int    count = 0;

            listBox.Items.Add("Path: " + filePath);
            using (StreamReader file = new StreamReader(filePath))
            {
                while ((line = file.ReadLine()) != null)
                {
                    count++;
                    if (line.Contains(searchTextBox.Text))
                    {
                        hits++;
                        SearchedItems s = new SearchedItems();
                        s.LineNumber = count;
                        s.LineText   = line;
                        s.findForm   = false;
                        listBox.Items.Add(s);
                        listBox.Visible = true;
                    }
                }
            }
            var text = "Searched: " + searchTextBox.Text + "(" + hits + " hits)";

            listBox.Items.Add(text);
        }
示例#3
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            count = 0;
            if (string.IsNullOrWhiteSpace(searchTextBox.Text))
            {
                return;
            }



            foreach (string file in files)
            {
                Console.WriteLine(file.ToString());
                listBox.Items.Add("Path: " + file.ToString());
                string[] lines = File.ReadAllLines(file);
                foreach (var line in lines)
                {
                    count++;
                    if (line.Contains(searchTextBox.Text))
                    {
                        hits++;
                        SearchedItems s = new SearchedItems();
                        s.LineNumber = count;
                        s.LineText   = line;
                        s.findForm   = false;
                        s.path       = file.ToString();
                        listBox.Items.Add(s);
                        listBox.Visible = true;
                    }
                }


                count = 0;
            }
            listBox.Items.Add("Total Matches:  " + hits);
        }
示例#4
0
        private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var         selectedTab1         = tabFiles.SelectedTab;
            RichTextBox selectedRichTextBox1 = selectedTab1.Controls[0] as RichTextBox;

            selectedRichTextBox1.SelectionBackColor = Color.White;
            selectedRichTextBox1.SelectionFont      = richTextBox1.Font;
            SearchedItems searchedItems = listBox1.SelectedItem as SearchedItems;

            if (searchedItems != null)
            {
                string file = searchedItems.path;
                if (files.ContainsKey(file))
                {
                    TabPage     page = files[file];
                    RichTextBox rtb  = page.Controls[0] as RichTextBox;
                    rtb.Text             = File.ReadAllText(file);
                    tabFiles.SelectedTab = page;
                }
                else
                {
                    TabPage     first = tabFiles.TabPages[0];
                    RichTextBox txt   = first.Controls[1] as RichTextBox;
                    RichTextBox txt2  = first.Controls[0] as RichTextBox;
                    if (txt.TextLength == 0 && first.Text == "New")
                    {
                        FileInfo info = new FileInfo(file);
                        first.Text = info.Name;
                        txt.Text   = File.ReadAllText(file);
                        files.Remove("New");
                        files[file]          = first;
                        tabFiles.SelectedTab = first;
                    }
                    else
                    {
                        TabPage     page = new TabPage();
                        RichTextBox rtb  = new RichTextBox();
                        RichTextBox rtb2 = new RichTextBox();
                        page.Bounds           = first.Bounds;
                        rtb.Bounds            = txt.Bounds;
                        rtb2.Bounds           = txt2.Bounds;
                        richTextBox           = rtb;
                        lineTextBox           = rtb2;
                        rtb2.ScrollBars       = 0;
                        rtb.Click            += richTextBox1_ClickTabs;
                        rtb.FontChanged      += richTextBox1_FontChangedTabs;
                        rtb.SelectionChanged += richTextBox1_SelectionChangedTabs;
                        rtb.TextChanged      += richTextBox1_TextChangedTabs;
                        rtb.VScroll          += richTextBox1_VScrollTabs;
                        page.Controls.Add(rtb);
                        page.Controls.Add(rtb2);

                        FileInfo info = new FileInfo(file);
                        page.Text   = info.Name;
                        rtb.Text    = File.ReadAllText(file);
                        files[file] = page;
                        tabFiles.TabPages.Add(page);
                        tabFiles.SelectedTab = page;
                    }
                }
                AddLineNumbersTabs();
                int         lineNumber          = searchedItems.LineNumber;
                var         selectedTab         = tabFiles.SelectedTab;
                RichTextBox selectedRichTextBox = selectedTab.Controls[0] as RichTextBox;
                if (selectedRichTextBox.SelectionStart >= 0)
                {
                    selectedRichTextBox.SelectionStart     = selectedRichTextBox.GetFirstCharIndexFromLine(lineNumber - 1);
                    selectedRichTextBox.SelectionLength    = searchedItems.LineText.Count();
                    selectedRichTextBox.SelectionBackColor = Color.LightGreen;
                    selectedRichTextBox.ScrollToCaret();
                }
            }
        }