问题描述
大家好,
我有一个C#Windows应用程序,它用于按时显示一些消息(每小时)。
此应用程序在任务栏中隐藏,仅显示在系统托盘中。
当时间到达显示消息时,窗口应打开,并且应显示在所有打开的应用程序的顶部(例如chrome,adobe)读者等等。
我将如何实现这一点,Plz帮助。
谢谢
Magesh.M
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
推荐答案
Me.Location = New System.Drawing.Point(0, 0)
Me.WindowState = Windows.Forms.FormWindowState.Maximized
Me.TopMost = True
Me.ShowDialog()
this.Location = new System.Drawing.Point(0, 0);
this.WindowState = Windows.Forms.FormWindowState.Maximized;
this.TopMost = true;
this.ShowDialog();
此外,
试试看这个:
[]
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只是实例化ProcessManager类,如
i just instantiate the ProcessManager class like
proc = new ProcessManager();
谢谢和问候
Magesh.M
Thanks and Regards
Magesh.M
这篇关于从系统托盘打开Windows应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!