Click here to Skip to main content
15,900,325 members
Home / Discussions / C#
   

C#

 
AnswerRe: Keyboard Layout Pin
RaviRanjanKr9-Mar-11 17:39
professionalRaviRanjanKr9-Mar-11 17:39 
Questiona strange question Pin
_Q12_5-Mar-11 16:05
_Q12_5-Mar-11 16:05 
AnswerRe: a strange question Pin
OriginalGriff5-Mar-11 21:17
mveOriginalGriff5-Mar-11 21:17 
GeneralRe: a strange question Pin
_Q12_6-Mar-11 1:22
_Q12_6-Mar-11 1:22 
GeneralRe: a strange question Pin
OriginalGriff6-Mar-11 1:25
mveOriginalGriff6-Mar-11 1:25 
GeneralRe: a strange question Pin
_Q12_6-Mar-11 1:34
_Q12_6-Mar-11 1:34 
GeneralRe: a strange question Pin
OriginalGriff6-Mar-11 1:36
mveOriginalGriff6-Mar-11 1:36 
GeneralRe: a strange question Pin
_Q12_6-Mar-11 1:45
_Q12_6-Mar-11 1:45 
Ok, no problem, Ill give you the code, but not about it is the problem, but the feeling of the program itself and what it does... I really cant have words to explain better.
here is the entire project source: http://www.sendspace.com/file/vg2fq5

and here is its content:
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Reflection;
namespace testu3
{
    public partial class Form1 : Form
    {
        public List<testu4.UserControl1> UC = new List<testu4.UserControl1>();
        List<string> lrtb = new List<string>();
        string path = Application.StartupPath;
        int oneAfter = 0, posTxt = 0, multiFile = 0;
    }
}


xEvents.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;

namespace testu3
{
    public partial class Form1
    {
        public Form1()
        {
            InitializeComponent();
            userControl0Test.Visible = false;
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            DirectoryInfo di = new DirectoryInfo(path);
            foreach (var item in di.GetFiles())
            {
                if (item.Extension.ToLower() == ".txt")
                {
                    testu4.UserControl1 uc = new testu4.UserControl1();
                    uc.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
                    uc.Location = new Point(10, oneAfter);
                    uc.linkLabel0.LinkClicked += new LinkLabelLinkClickedEventHandler(linkLabelUC_LinkClicked);//title
                    uc.linkLabel1.LinkClicked += new LinkLabelLinkClickedEventHandler(linkLabelUCopen_LinkClicked);//open

                    uc.linkLabel0.Text = item.Name;



                    #region <_____ OPENfile _____>
                    // codul 1(comentat) deskide txtfile
                    //uc.linkLabel1.Links[0].LinkData = uc.linkLabel0.Text;//open txtFile
                    // codul 2 deskide originalFile
                    foreach (var item1 in di.GetFiles())
                    {
                        string original = item.Name.Replace(".txt", "");
                       
                        if (multiFile == 0)
                        {
                            if (item1.Name.Contains(original))
                            {
                                uc.linkLabel1.Links[0].LinkData = uc.linkLabel0.Text;//open txtFile
                                multiFile++;
                            }
                        }
                        if (multiFile > 0)
                        {
                            if (item1.Extension != ".txt")
                            {
                                if (item1.Name.Contains(original))
                                {
                                    uc.linkLabel1.Links[0].LinkData = item1.FullName;
                                }
                            }
                        }
                        
                    }
                    multiFile = 0;
                    #endregion >OPENfile-END<
                   

                    uc.richTextBox1.Text = item.OpenText().ReadToEnd();

                    panel0.Controls.Add(uc);//how many controls are added.
                    UC.Add(uc);


                    oneAfter += uc.Height;//increment space
                    

                    //
                    //[EntireChapterFiles] ////EX: this.linkLabel1.Links.Add(24, 9, "www.microsoft.com");
                    //      title          ////    this.linkLabel1.Links[0].LinkData = "Register";
                    string pureName = item.Name.ToLower().Replace(".txt", "");
                    linkLabel0.Text += pureName + " | ";
                    linkLabel0.Links.Add(linkLabel0.Text.IndexOf(pureName), pureName.Length, item.FullName);
                }
            }

            //change the appearance for linkLabel_BackNext
            int indexOfNext = linkLabel_BackNext.Text.IndexOf("Next");
            linkLabel_BackNext.Links.Add(0, 4);
            linkLabel_BackNext.Links.Add(indexOfNext, 4);
        }

        private void button0Search_Click(object sender, EventArgs e)
        {
            panel0.Controls.Clear(); UC.Clear(); oneAfter = 0; linkLabel0.Links.Clear();//reset values
            DirectoryInfo di = new DirectoryInfo(path);
            foreach (var item in di.GetFiles())
            {
                if (item.Extension.ToLower() == ".txt")
                {
                    posTxt = 0;
                    string searchText = textBox1.Text.ToLower();

                    // Search File_Names 
                    if (item.Name.ToLower().Contains(searchText))
                    {
                        string pureName = item.Name.ToLower().Replace(".txt", "");
                        linkLabel0.ForeColor = Color.Gray;
                        linkLabel0.Links.Add(linkLabel0.Text.IndexOf(pureName), pureName.Length, item.FullName);
                    }


                    // Search content in Files
                    StreamReader sr = new StreamReader(item.FullName);
                    string alltxt = sr.ReadToEnd();
                    if (alltxt.ToLower().Contains(searchText))
                    {
                        #region <_____ addControls _____>
                        testu4.UserControl1 uc = new testu4.UserControl1();
                        uc.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
                        uc.Location = new Point(10, oneAfter);
                        uc.Size = new System.Drawing.Size(panel0.Width, uc.defaultHeight);
                        uc.linkLabel0.LinkClicked += new LinkLabelLinkClickedEventHandler(linkLabelUC_LinkClicked);//title
                        uc.linkLabel1.LinkClicked += new LinkLabelLinkClickedEventHandler(linkLabelUCopen_LinkClicked);//open

                        uc.linkLabel0.Text = item.Name;
                        #region <_____ OPENfile _____>
                        // codul 1(comentat) deskide txtfile
                        //uc.linkLabel1.Links[0].LinkData = uc.linkLabel0.Text;//open txtFile
                        // codul 2 deskide originalFile
                        foreach (var item1 in di.GetFiles())
                        {
                            string original = item.Name.Replace(".txt", "");

                            if (multiFile == 0)
                            {
                                if (item1.Name.Contains(original))
                                {
                                    uc.linkLabel1.Links[0].LinkData = uc.linkLabel0.Text;//open txtFile
                                    multiFile++;
                                }
                            }
                            if (multiFile > 0)
                            {
                                if (item1.Extension != ".txt")
                                {
                                    if (item1.Name.Contains(original))
                                    {
                                        uc.linkLabel1.Links[0].LinkData = item1.FullName;
                                    }
                                }
                            }
                        }
                        multiFile = 0;
                        #endregion >OPENfile-END<
                        #endregion >addControls-END<

                        #region <_____ Context _____>
                        if (button1Concentrated.Text == "Concentrated")//this is for Context 
                        {

                            uc.richTextBox1.Text = alltxt.ToLower();//add text.ToLower to viewer
                            while (posTxt != -1)
                            {
                                // inside richTextBox1 sunt A si a. El cauta numai in el insusi.
                                posTxt = uc.richTextBox1.Find(searchText, posTxt, RichTextBoxFinds.MatchCase);
                                if (uc.richTextBox1.SelectedText == searchText)
                                {
                                    uc.richTextBox1.SelectionLength = searchText.Length;
                                    uc.richTextBox1.SelectionColor = Color.Red;
                                }
                                posTxt = uc.richTextBox1.Find(searchText, posTxt + 1, RichTextBoxFinds.MatchCase);
                            }

                        }
                        #endregion >Context-END<
                        //
                        #region <_____ Concentrated _____>
                        if (button1Concentrated.Text == "Context")//this is for Concentrated 
                        {
                            uc.richTextBox1.Text = alltxt.ToLower();
                            for (int i = 0; i < uc.richTextBox1.Lines.Length; i++)
                            {
                                if (uc.richTextBox1.Lines[i].Contains(searchText))
                                {
                                    string line = "[line:" + (i + 1) + "/" + uc.richTextBox1.Lines.Length + "]  " + uc.richTextBox1.Lines[i];
                                    lrtb.Add(line);
                                }
                            }
                            uc.richTextBox1.Text = "";
                            foreach (var item1 in lrtb)
                            {
                                uc.richTextBox1.Text += item1 + "\r\n";
                            }
                            while (posTxt != -1)
                            {
                                posTxt = uc.richTextBox1.Find(searchText, posTxt, RichTextBoxFinds.MatchCase);
                                if (uc.richTextBox1.SelectedText == searchText)
                                {
                                    uc.richTextBox1.SelectionLength = searchText.Length;
                                    uc.richTextBox1.SelectionColor = Color.SpringGreen;
                                }
                                posTxt = uc.richTextBox1.Find(searchText, posTxt + 1, RichTextBoxFinds.MatchCase);
                            }
                        }
                        #endregion >Concentrated-END<


                        panel0.Controls.Add(uc);//how many controls are added.
                        UC.Add(uc);
                        oneAfter += uc.Height;//increment space
                        lrtb.Clear();
                    }
                }
            }
        }

        public void linkLabelUC_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            for (int i = 0; i < UC.Count; i++)
            {
                //if UC[i] nu-i UC[maxim]
                if ((i + 1) < UC.Count)//inafara de ultimul UC(UserControl)
                {
                    int firstHeight = UC[i].Height;
                    int firstPosition = UC[i].Location.Y;

                    int secondHeight = UC[i + 1].Height;
                    int secondPosition = UC[i + 1].Location.Y;

                    //UC[0].Location.Y +
                    if (firstPosition == 0)
                    {
                        //secondPosition
                        UC[i + 1].Location = new Point(10, firstHeight);
                    }
                    //UC[i].Location.Y +
                    if (firstPosition != 0)
                    {
                        //secondPosition
                        UC[i + 1].Location = new Point(10, firstHeight + firstPosition);
                    }
                }
            }
        }



        //a mai ramas ghimpele cu [una=true restu=false] de rezolvat. (Fa-le Toate true/false)
        private void linkLabel0ShowAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            for (int i = 0; i < UC.Count; i++)
            {
                if (UC[i].richTextBox1.Lines.Length > 1)
                {
                    if (UC[i].linkLabel0.LinkVisited)//clicked
                    {
                        UC[i].Height = UC[i].defaultHeight;
                        UC[i].linkLabel0.LinkVisited = false;
                        linkLabel0ShowAll.Text = "Show All";
                    }
                    else//notClicked
                    {
                        UC[i].Height = UC[i].Height + (UC[i].richTextBox1.Lines.Length * UC[i].richTextBox1.Font.Height);
                        UC[i].linkLabel0.LinkVisited = true;
                        linkLabel0ShowAll.Text = "Close All";
                    }

                }

                //if UC[i] nu-i UC[maxim]
                if ((i + 1) < UC.Count)//inafara de ultimul UC(UserControl)
                {
                    int firstHeight = UC[i].Height;
                    int firstPosition = UC[i].Location.Y;

                    int secondHeight = UC[i + 1].Height;
                    int secondPosition = UC[i + 1].Location.Y;

                    //UC[0].Location.Y +
                    if (firstPosition == 0)
                    {
                        //secondPosition
                        UC[i + 1].Location = new Point(10, firstHeight);
                    }
                    //UC[i].Location.Y +
                    if (firstPosition != 0)
                    {
                        //secondPosition
                        UC[i + 1].Location = new Point(10, firstHeight + firstPosition);
                    }
                }
            }
        }

        void linkLabelUCopen_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string target = e.Link.LinkData as string;
            if (null != target) System.Diagnostics.Process.Start(target);
        }

        private void linkLabel0_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            // Display the appropriate link based on the value of the LinkData property of the Link object.
            this.linkLabel0.Links[linkLabel0.Links.IndexOf(e.Link)].Visited = true;
            string target = e.Link.LinkData as string;

            if (null != target) System.Diagnostics.Process.Start(target);
        }

        private void button1Concentrated_Click(object sender, EventArgs e)
        {
            if (button1Concentrated.Text == "Concentrated")
            {
                button1Concentrated.Text = "Context";
                button0Search.PerformClick();
            }
            else
            {
                button1Concentrated.Text = "Concentrated";
                button0Search.PerformClick();
            }
        }
    }
}


UserControl1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace testu4
{
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }
        private void UserControl1_Load(object sender, EventArgs e)
        {
            label0.Location = new Point(linkLabel0.Location.X + linkLabel0.Width, linkLabel0.Location.Y + 4);
        }

        public int defaultHeight = 55;//static 
        //click Titlu
        private void linkLabel0_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (richTextBox1.Lines.Length > 1)
            {
                if (linkLabel0.LinkVisited == false)
                {
                    this.Height = this.Height + (richTextBox1.Lines.Length * richTextBox1.Font.Height);
                    linkLabel0.LinkVisited = true;//linkLabel0.LinkColor = Color.Maroon;
                }
                else
                {
                    this.Height = defaultHeight;
                    linkLabel0.LinkVisited = false;//linkLabel0.LinkColor = Color.DodgerBlue;
                }
            }
        }



        private void groupBox1_MouseHover(object sender, EventArgs e)
        {
           // groupBox1.Select();
        }

        private void richTextBox1_MouseHover(object sender, EventArgs e)
        {
           // richTextBox1.Select();
        }
    }
}

GeneralRe: a strange question [modified] Pin
_Q12_6-Mar-11 2:04
_Q12_6-Mar-11 2:04 
GeneralRe: a strange question Pin
_Q12_6-Mar-11 2:43
_Q12_6-Mar-11 2:43 
GeneralRe: a strange question Pin
Pete O'Hanlon6-Mar-11 10:59
mvePete O'Hanlon6-Mar-11 10:59 
QuestionCAS - Deny now obsolete and CAS is becoming out of favor, how can I deny "ReflectionPermission" (Need syntax) Pin
devvvy5-Mar-11 14:30
devvvy5-Mar-11 14:30 
Questionteeth detection from image using c# Pin
AhmedMasum5-Mar-11 2:43
AhmedMasum5-Mar-11 2:43 
AnswerRe: teeth detection from image using c# Pin
OriginalGriff5-Mar-11 3:26
mveOriginalGriff5-Mar-11 3:26 
GeneralRe: teeth detection from image using c# Pin
AhmedMasum5-Mar-11 19:09
AhmedMasum5-Mar-11 19:09 
AnswerRe: teeth detection from image using c# Pin
Not Active5-Mar-11 3:48
mentorNot Active5-Mar-11 3:48 
GeneralRe: teeth detection from image using c# Pin
OriginalGriff5-Mar-11 3:58
mveOriginalGriff5-Mar-11 3:58 
GeneralRe: teeth detection from image using c# Pin
PIEBALDconsult5-Mar-11 9:15
mvePIEBALDconsult5-Mar-11 9:15 
GeneralRe: teeth detection from image using c# Pin
AhmedMasum5-Mar-11 19:11
AhmedMasum5-Mar-11 19:11 
AnswerRe: teeth detection from image using c# Pin
AhmedMasum5-Mar-11 19:23
AhmedMasum5-Mar-11 19:23 
GeneralRe: teeth detection from image using c# Pin
Richard MacCutchan5-Mar-11 21:27
mveRichard MacCutchan5-Mar-11 21:27 
GeneralRe: teeth detection from image using c# Pin
AhmedMasum6-Mar-11 0:30
AhmedMasum6-Mar-11 0:30 
GeneralRe: teeth detection from image using c# Pin
Richard MacCutchan6-Mar-11 1:20
mveRichard MacCutchan6-Mar-11 1:20 
AnswerRe: teeth detection from image using c# Pin
Alan Balkany7-Mar-11 7:05
Alan Balkany7-Mar-11 7:05 
QuestionDo not show DOS window when callinf DOS command from C# Pin
Member 77263854-Mar-11 6:55
Member 77263854-Mar-11 6:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.