Click here to Skip to main content
15,886,137 members
Home / Discussions / C#
   

C#

 
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 
Hi again your response is excellent as always the original code you sent me did indeed highlight the chosen word perfectly but now i have changed it to your most recent suggestion it is stopped at the line
FindAction(strToFind, LastSearchText == strToFind);

stating 'Object reference not set to an instance of an object.'

//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();

        }

        public Action<string, bool> FindAction;

        private string LastSearchText;
        

      //  public string strToFind {private set; get; }

        private string strToFind;

        private void Cancel_Click(object sender, EventArgs e)
        {
        // this.DialogResult = DialogResult.Cancel;
            this.Hide();
        }

        private void cmdFind_Click(object sender, EventArgs e)
        {
            strToFind = searchTxt.Text;
            if (string.IsNullOrWhiteSpace(strToFind))
            {
                MessageBox.Show("Please enter search text");
                return;
            }
            FindAction(strToFind, LastSearchText == strToFind);
            LastSearchText = strToFind;
        }

           // this.DialogResult = DialogResult.OK;
           // this.Show();        
            
        }

        }


//Form1 


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.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.Visible = false;
            FindForm.Owner = this;
            FindForm.FindAction = findAction;

        }

        private void findAction(string strToFind, bool isSameSearch)
        {
            int searchStartIndex = (isSameSearch)
               ? textBox1.SelectionStart + textBox1.SelectionLength : 0;

            int ndx = textBox1.Text.IndexOf(strToFind, searchStartIndex);

            if (ndx == -1) return;
            textBox1.SelectionStart = ndx;
            textBox1.SelectionLength = strToFind.Length;
        }
        

        private void findToolStripMenuItem_Click(object sender, EventArgs e)
        {
          //  if (FindForm.ShowDialog() == DialogResult.OK)
          //  {
             //   string searchTxt = FindForm.strToFind;


              //  int ndx = textBox1.Text.IndexOf(searchTxt);

              //  if (ndx == -1) return; // nothing found

              //  textBox1.SelectionStart = ndx;
              //  textBox1.SelectionLength = searchTxt.Length;
             //   this.FindForm.Show();
              //  this.Focus();
            FindForm.Show();
                
            
        }

         

       

        private void findNextToolStripMenuItem_Click(object sender, EventArgs e)
        {
           

            
        }

        private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void goToToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.SelectAll();
        }

        private void timeDateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Text += DateTime.Now;


        }

        private void statusToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void wordWrapToolStripMenuItem_Click(object sender, EventArgs e)
        {
            wordWrapToolStripMenuItem.Checked = !(wordWrapToolStripMenuItem.Checked); textBox1.WordWrap = wordWrapToolStripMenuItem.Checked;
        }

        private void fontToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (fontDialog1.ShowDialog() == DialogResult.OK)

                textBox1.Font = fontDialog1.Font; 
        }




       

        public Action<string, bool> FindAction { get; set; }
    }
}

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 
AnswerRe: How to call protected override void OnPaint(PaintEventArgs e) in another method in C# Pin
Eddy Vluggen16-Mar-15 9:08
professionalEddy Vluggen16-Mar-15 9:08 
GeneralRe: How to call protected override void OnPaint(PaintEventArgs e) in another method in C# Pin
Member 1068390216-Mar-15 9:48
Member 1068390216-Mar-15 9:48 
Questionask about windorms and containers Pin
fsdsc216-Mar-15 4:56
fsdsc216-Mar-15 4:56 
AnswerRe: ask about windorms and containers Pin
OriginalGriff16-Mar-15 5:04
mveOriginalGriff16-Mar-15 5:04 
GeneralRe: ask about windorms and containers Pin
fsdsc216-Mar-15 11:21
fsdsc216-Mar-15 11:21 
GeneralRe: ask about windorms and containers Pin
fsdsc217-Mar-15 9:12
fsdsc217-Mar-15 9:12 
Questioncreate PPPoe connection in c# Pin
KARFER16-Mar-15 4:38
KARFER16-Mar-15 4:38 
AnswerRe: create PPPoe connection in c# Pin
OriginalGriff16-Mar-15 5:05
mveOriginalGriff16-Mar-15 5:05 
QuestionDoubt about netinventory Pin
Raghuraman.tm1916-Mar-15 1:32
professionalRaghuraman.tm1916-Mar-15 1:32 
AnswerRe: Doubt about netinventory Pin
OriginalGriff16-Mar-15 2:18
mveOriginalGriff16-Mar-15 2:18 

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.