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