Click here to Skip to main content
15,887,350 members
Home / Discussions / C#
   

C#

 
GeneralMessage Closed Pin
17-Mar-15 22:24
Abdulnazark17-Mar-15 22:24 
GeneralRe: Question regarding C# Pin
Pete O'Hanlon18-Mar-15 0:03
mvePete O'Hanlon18-Mar-15 0:03 
GeneralRe: Question regarding C# Pin
Abdulnazark18-Mar-15 2:16
Abdulnazark18-Mar-15 2:16 
GeneralRe: Question regarding C# Pin
Richard Deeming18-Mar-15 3:00
mveRichard Deeming18-Mar-15 3:00 
GeneralRe: Question regarding C# Pin
Abdulnazark18-Mar-15 3:25
Abdulnazark18-Mar-15 3:25 
GeneralRe: Question regarding C# Pin
Abdulnazark17-Mar-15 23:04
Abdulnazark17-Mar-15 23:04 
QuestionRLDC Report error : An error occurred during report processing. Pin
jasonalien17-Mar-15 0:13
jasonalien17-Mar-15 0:13 
QuestionC# Notepad Clone using a Textbox (not RichTextBox) Find / Find Next Function help? Pin
Member 1153148716-Mar-15 23:04
Member 1153148716-Mar-15 23:04 
Hi i have recently moved into IT at work and am having to learn C# from scratch as fast as possible with little help. As practise I have to create a notepad clone in VS 2010 using c#. I know that using a 'RichTextBox' would be alot easier but i HAVE to use a 'Textbox' for my first version.
I have completed all the usual menu functions on the main form (form1) up to Find/Find Next/Replace. This is where i am a little stuck.

I have created a 2nd form(frmfind) to be the dialog box that appears when you click file->Find and i have coded enough that when you click on file frmfind appears but now i am not sure how to get form1 to take the search text entered and make it actually search my textBox1 and highlight the first found word etc. I am a visual learner so examples really help.

I have been told that using a for loop is the best option.

Here is my code i have not included the other file menu parts.

Form1

C#
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.Drawing.Printing;

namespace SamsNotePad
{
    public partial class Form1 : Form

    {
        frmFind FindForm = new frmFind();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            FindForm.FindClicked +=new frmFind.FindClickEventHandler(FindForm_FindClicked);
        }

 private void findToolStripMenuItem_Click(object sender, EventArgs e)
        {
           // **old Find findForm = new Find(textBox1.Text);
           // **old findForm.Show();


         //   Find findForm = new Find();
         //   findForm.ShowDialog();
            
            

        // if (textBox1.Text.IndexOf(
            FindForm.Show();
            FindForm.Focus();
          

        }
        void FindForm_FindClicked(string strToFind)
        {
          //  MessageBox.Show("this is where i would now find what you wrote like innit");
            int index = textBox1.Text.IndexOf(strToFind);
            if (index >= 0)
            {
                textBox1.SelectionStart = index;
                textBox1.SelectionLength = strToFind.Length;
                textBox1.Focus();
            }



            

        }


        private void findNextToolStripMenuItem_Click(object sender, EventArgs e)
        {
           

        }

        private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }






//frmFind

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

namespace SamsNotePad
{
    public partial class frmFind : Form    {
        public frmFind()
        {
            InitializeComponent();

         //   findTextBox1.Text = Message;

        }
        public string strToFind
        {
            get { return searchTxt.Text; }
            
        }

         public delegate void FindClickEventHandler(string strToFind);
         public event FindClickEventHandler FindClicked;
       
      //  public string searchText
     //   {
     //       get { return findTextBox1.Text; }
     //       set { findTextBox1.Text = value; }
     //   }

                   
       
        void cancel_Click(object sender, EventArgs e)
        {
            this.Close();

        }

        private void cmdFind_Click(object sender, EventArgs e)
        {
            FindClicked(searchTxt.Text);
        }

        private void strToFind_TextChanged(object sender, EventArgs e)
        {
            
        }

     

                 
      

        

       

        
    }
}


modified 17-Mar-15 6:25am.

AnswerRe: C# Notepad Clone using a Textbox (not RichTextBox) Find / Find Next Function help? Pin
OriginalGriff17-Mar-15 0:01
mveOriginalGriff17-Mar-15 0:01 
GeneralRe: C# Notepad Clone using a Textbox (not RichTextBox) Find / Find Next Function help? Pin
Member 1153148717-Mar-15 0:24
Member 1153148717-Mar-15 0:24 
GeneralRe: C# Notepad Clone using a Textbox (not RichTextBox) Find / Find Next Function help? Pin
Freak3017-Mar-15 2:03
Freak3017-Mar-15 2:03 
GeneralRe: C# Notepad Clone using a Textbox (not RichTextBox) Find / Find Next Function help? Pin
OriginalGriff17-Mar-15 2:36
mveOriginalGriff17-Mar-15 2:36 
AnswerRe: C# Notepad Clone using a Textbox (not RichTextBox) Find / Find Next Function help? Pin
BillWoodruff17-Mar-15 4:56
professionalBillWoodruff17-Mar-15 4:56 
GeneralRe: C# Notepad Clone using a Textbox (not RichTextBox) Find / Find Next Function help? Pin
Member 1153148717-Mar-15 5:24
Member 1153148717-Mar-15 5:24 
GeneralRe: C# Notepad Clone using a Textbox (not RichTextBox) Find / Find Next Function help? Pin
Member 1153148717-Mar-15 5:38
Member 1153148717-Mar-15 5:38 
GeneralRe: C# Notepad Clone using a Textbox (not RichTextBox) Find / Find Next Function help? Pin
BillWoodruff17-Mar-15 7:46
professionalBillWoodruff17-Mar-15 7:46 
GeneralRe: C# Notepad Clone using a Textbox (not RichTextBox) Find / Find Next Function help? Pin
BillWoodruff17-Mar-15 22:11
professionalBillWoodruff17-Mar-15 22:11 
GeneralRe: C# Notepad Clone using a Textbox (not RichTextBox) Find / Find Next Function help? Pin
Member 1153148717-Mar-15 23:49
Member 1153148717-Mar-15 23:49 
GeneralRe: C# Notepad Clone using a Textbox (not RichTextBox) Find / Find Next Function help? Pin
BillWoodruff18-Mar-15 17:01
professionalBillWoodruff18-Mar-15 17:01 
Questionhow to send any file from server to client in c# Pin
Member 1149066016-Mar-15 21:32
Member 1149066016-Mar-15 21:32 
AnswerRe: how to send any file from server to client in c# Pin
Eddy Vluggen16-Mar-15 23:27
professionalEddy Vluggen16-Mar-15 23:27 
AnswerRe: how to send any file from server to client in c# Pin
F-ES Sitecore16-Mar-15 23:40
professionalF-ES Sitecore16-Mar-15 23:40 
QuestionProblem parsing rss feed Pin
Member 1022623016-Mar-15 19:25
Member 1022623016-Mar-15 19:25 
AnswerRe: Problem parsing rss feed Pin
Pete O'Hanlon16-Mar-15 22:19
mvePete O'Hanlon16-Mar-15 22:19 
QuestionHow to call protected override void OnPaint(PaintEventArgs e) in another method in C# Pin
Member 1068390216-Mar-15 8:47
Member 1068390216-Mar-15 8:47 

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.