1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| 1. public partial class Form1 : Form
2. {
3. public Form1()
4. {
5. InitializeComponent();
6. }
7.
8. public delegate void ChangeTitleDelegate();
9.
10. [DllImport("user32.dll", EntryPoint = "SetWindowText", CharSet = CharSet.Ansi)]
11. public static extern bool SetWindowText(IntPtr hWnd, String strNewWindowName);
12.
13. [DllImport("user32.dll", EntryPoint = "FindWindow", CharSet = CharSet.Ansi)]
14. public static extern IntPtr FindWindow(string className, string windowName);
15.
16. private void button1_Click(object sender, EventArgs e)
17. {
18. //Change FolderBrowserBox Title.
19. this.BeginInvoke(new ChangeTitleDelegate(ChangeFolderBrowserBoxTitle));
20.
21. //Show FolderBrowserBox
22. FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
23. folderBrowserDialog.RootFolder = System.Environment.SpecialFolder.MyComputer;
24. folderBrowserDialog.ShowDialog();
25. }
26.
27. /// <summary>
28. /// Change FolderBrowserBox Title.
29. /// </summary>
30. private static void ChangeFolderBrowserBoxTitle()
31. {
32. bool titleChanged = false;
33.
34. TimerCallback timerCallback = delegate
35. {
36. try
37. {
38. IntPtr ptr = FindWindow(null, "Browse For Folder");
39. if (ptr != IntPtr.Zero)
40. {
41. SetWindowText(ptr, "Hi, i am Tarannum Banu");
42. titleChanged = true;
43. }
44. }
45. catch (Exception exception)
46. {
47. System.Diagnostics.Debug.WriteLine(exception.Message);
48. }
49. catch
50. {
51. }
52. };
53.
54. System.Threading.Timer timer = null;
55. try
56. {
57. timer = new System.Threading.Timer(timerCallback, null, 500, 500);
58. while (!titleChanged)
59. {
60. System.Windows.Forms.Application.DoEvents();
61. System.Threading.Thread.Sleep(0);
62. }
63. }
64. catch (Exception exception)
65. {
66. System.Diagnostics.Debug.WriteLine(exception.Message);
67. }
68. finally
69. {
70. if (timer != null) timer.Dispose();
71. }
72. } |
Partager