Click here to Skip to main content
15,355,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a C# Windows Application, it is used to display some messages on time basis(Hourly).
This application is hidden from taskbar and only shown in system tray.
When the time reaches to display messages the window should open, and it should diplay in top of all opened Application(such as chrome, adobe reader , etc.).
How will i Achieve this , Plz Help.


Thanks
Magesh.M
Posted
Comments
Dev O'Connor 18-Jun-15 6:44am
   
Please provide your code you are using to try and open the window.
Magesh M N 18-Jun-15 6:52am
   
i just using show();
and for hide , just hide();
Dev O'Connor 18-Jun-15 12:21pm
   
Please mark the answer as the solution if this has resolved your problem.

Have you made sure your form window state and position is accurate?

Can you try the below and let me know how it goes ?

VB
Me.Location = New System.Drawing.Point(0, 0)
Me.WindowState = Windows.Forms.FormWindowState.Maximized
Me.TopMost = True
Me.ShowDialog()

C#
this.Location = new System.Drawing.Point(0, 0);
this.WindowState = Windows.Forms.FormWindowState.Maximized;
this.TopMost = true;
this.ShowDialog();


Also,

Try looking into this too:
Create a System Tray Application in VB.NET[^]
   
v3
Comments
Magesh M N 18-Jun-15 7:08am
   
I tried this, the form opens but it doesn't displays top of all other application....
Dev O'Connor 18-Jun-15 7:10am
   
Try this:

Dim frm as Form = New MyFormName
frm.Show()
Magesh M N 18-Jun-15 7:11am
   
FYI,
i am creating application with C# not with VB...
Dev O'Connor 18-Jun-15 7:12am
   
Form frm = new MyFormName();
frm.Show();
Magesh M N 18-Jun-15 7:14am
   
Again , the form Opens but not on top of all other opened applications..
Dev O'Connor 18-Jun-15 7:17am
   
Ah sorry i get you now. Misunderstood you

I have update the solution for you in C#

Add Me.TopMost = True, that should sort it
Dev O'Connor 18-Jun-15 7:12am
   
Form frm = new MyFormName();
frm.Show();
Hi all,

At last, however i find the solution to this,

i had used the following class to bring my application front of all other opened applicatios..

C#
public class ProcessManager
   {
       [DllImport("user32.dll")]
       private static extern bool ShowWindow(IntPtr hWnd, uint windowStyle);

       [DllImport("user32.dll")]
       private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);

       public ProcessManager()
       {
           string processName = "your process name here, if your process is something.exe then give 'something' ..";
           SearchProcessAndModifyState(processName);
       }

       private void SearchProcessAndModifyState(string targetProcessName)
       {
           Process specifiedProcess = null;
           var pro = Process.GetProcessesByName(targetProcessName);
           if (pro.Length > 0)
           {
               specifiedProcess = pro[0];
           }

           if (specifiedProcess != null)
           {
               ProcessManager.ShowWindow(specifiedProcess.MainWindowHandle, 1u);
               ProcessManager.SetWindowPos(specifiedProcess.MainWindowHandle, new IntPtr(-1), 0, 0, 0, 0, 3u);
           }
       }
   }



Then whenever i needs to open the form along with
Form.Show()

i just instantiate the ProcessManager class like
proc = new ProcessManager();



Thanks and Regards
Magesh.M
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900