Search blog.co.uk

Notepad search functionality

by battula32 @ 2007-08-14 - 18:34:38

Few months back, I had a problem of coding Find functionality in C#. I should work like notepad Find dailog box.

I used SetForegroundWindow(...), Actually this is not dialogbox, also this is not seperate window. Perhaps this is called from main window as objSubForm.Show(this).

the Idea I got from
http://www.codeguru.com/forum/showthread.php?t=417099&highlight=Find+Functionality+Notepad
Hereby I am presenting sample code behind this.

      1.   Create windows application, add one more new  form to this project.
      2.   Declare one emplty object for second from.
                        Test.Form2 frm; // Test is namespace
      3.   In the constructor of main from create instance for second from like
                       ex. frm = new Test.Form2(this);  
      4.  In the second from you need to define on perameterised constructor and the parameter should be the object of main form 
      5. The second form code will be like

using System.Runtime.InteropServices;

namespace Test
{
    public partial class Form2 : Form
    {
        Test.Form1 m_frm=null;
        [DllImport("user32.dll")] private static extern
            bool SetForegroundWindow(IntPtr hWnd);
       
        public Form2(Test.Form1 frm)
        {
            m_frm = frm;
            InitializeComponent();
        }
    }
}

       6. In main from Find event the code should be

frm.Show(this);


 
 

Trackback address for this post:

authimage

Comments, Trackbacks:

No Comments/Trackbacks for this post yet...

Leave a comment :

Your email address will not be displayed on this site.
Your URL will be displayed.
Allowed XHTML tags: <!, p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, a, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small, img>
URLs, email, AIM and ICQs will be converted automatically.
Options:
 
(Line breaks become <br />)
(Set cookies for name, email & url)
Validation code:
Please enter the above code here:
For protection from spambots (case-sensitive).

Footer

The content of this website belongs to a private person, blog.co.uk is not responsible for the content of this website.