我有一个VSTO Outlook加载项,我想在特定时间(例如5秒钟)弹出一个带有自定义文本消息的通知(浮动窗口),然后自动消失。我想从撰写窗口中显示此通知。我该如何实现?一些例子将高度赞赏。
更新:我希望通知窗口成为撰写窗口的孩子。
更新29.06.2022:
我已经完成了以下操作:
Outlook.Inspector currentInspector = this.Window as Outlook.Inspector;
IOleWindow ioleWnd = (IOleWindow)currentInspector;
ioleWnd.GetWindow(out IntPtr phwnd);
NativeWindow nativeWnd = new System.Windows.Forms.NativeWindow();
nativeWnd.AssignHandle(phwnd);
// frm is my notification window, borderless and without maximize, minimize and close buttons and without title bar.
Form frm = new Form();
frm.ControlBox = false;
frm.FormBorderStyle = FormBorderStyle.None;
NativeMethods.Rect rect = new NativeMethods.Rect();
NativeMethods.GetWindowRect(phwnd, ref rect);
frm.Left = rect.Right - 85;
frm.Top = rect.Bottom - 55;
frm.Width = 80;
frm.Height = 50;
frm.Location = new System.Drawing.Point(rect.Right - 85, rect.Bottom - 55);
frm.BackColor = System.Drawing.Color.Red;
TextBox txtBox = new TextBox();
txtBox.BackColor = System.Drawing.Color.Red;
txtBox.ForeColor = System.Drawing.Color.White;
txtBox.Location = new System.Drawing.Point(5, 5);
txtBox.Visible = true;
txtBox.Text = "This is a notification message";
frm.Controls.Add(txtBox);
frm.Show(nativeWnd);
上面代码发生了什么:
- 通知窗口未位于右下方
撰写窗口的角。
- 如果我移动组合窗口,则通知窗口保持相同的位置,并且在我移动组合窗口时不会移动。
- 在Windows任务栏中,它显示为“通知窗口”是一个不同的过程/程序,而不是同一组合窗口的一部分,也许我需要做类似frm.Onterer =本机=本机的事情,但它不起作用。
有什么想法吗?
I have an VSTO Outlook Add-in and I would like to popup a notification (floating window) with a custom text message for a specific time (5 seconds for example) and then disappear automatically. I want to show this notification from within the compose window. How can I achieve this? some example will highly appreciated.
UPDATED: I would like the notification window to be a child of the compose window.
UPDATE 29.06.2022:
I have done the following:
Outlook.Inspector currentInspector = this.Window as Outlook.Inspector;
IOleWindow ioleWnd = (IOleWindow)currentInspector;
ioleWnd.GetWindow(out IntPtr phwnd);
NativeWindow nativeWnd = new System.Windows.Forms.NativeWindow();
nativeWnd.AssignHandle(phwnd);
// frm is my notification window, borderless and without maximize, minimize and close buttons and without title bar.
Form frm = new Form();
frm.ControlBox = false;
frm.FormBorderStyle = FormBorderStyle.None;
NativeMethods.Rect rect = new NativeMethods.Rect();
NativeMethods.GetWindowRect(phwnd, ref rect);
frm.Left = rect.Right - 85;
frm.Top = rect.Bottom - 55;
frm.Width = 80;
frm.Height = 50;
frm.Location = new System.Drawing.Point(rect.Right - 85, rect.Bottom - 55);
frm.BackColor = System.Drawing.Color.Red;
TextBox txtBox = new TextBox();
txtBox.BackColor = System.Drawing.Color.Red;
txtBox.ForeColor = System.Drawing.Color.White;
txtBox.Location = new System.Drawing.Point(5, 5);
txtBox.Visible = true;
txtBox.Text = "This is a notification message";
frm.Controls.Add(txtBox);
frm.Show(nativeWnd);
What happens with above code is below:
- Notification window is not positioned on the bottom right hand
corner of the compose window.
- If I move compose window, notification window keeps in the same position and it is not moving while I move the compose window.
- In windows task bar it appears as the notification window is a different process/program, not being part of the same compose window, maybe I need to do something like frm.Owner = nativeWnd but it is not working.
Any ideas?
发布评论
评论(2)
使用一个计时器,该计时器在主线程(UI)上启动
tick
事件,您可以在其中调用表单的CLOSE
方法。system.windows.forms.timer
的事件是通过消息循环从UI线程中提出的,当它收到wm_timer
消息时。因此,您很高兴呼叫关闭方法。请注意,可以运行计时器,并在表单外部或表单内部(内置的表单内)从您的代码上封闭表单。
Use a timer which fires the
Tick
event on the main thread (UI) where you can call theClose
method of your form. TheSystem.Windows.Forms.Timer
's event is raised from the UI thread by the message loop when it receives aWM_TIMER
message. So, you are good to calling the Close method.Note, the timer can be run and the form is closed from your code outside of the form or inside the form (built-in to the form).
您可以创建一个自定义的窗口表单,该表单在超时后自动关闭。
要使您的表格成为Outlook Inspector的孩子,请Q/code> Inspector 对象(例如
application.activeInspector
)到iolewindow
接口,调用iolewindow.getWindow
获取hwnd
。创建一个System.windows.forms.nativewindow
类的实例,并调用nativalwindow.assignhandle
。然后,您可以将本地窗口
对象传递到form.show
或form.showmodal
(antibalwindow
object objock obsiteiwin32window
接口)。You can create a custom Windows form that closes itself automatically after a timeout.
To make your form a child of an Outlook inspector, Q/cast the
Inspector
object (e.g. fromApplication.ActiveInspector
) to theIOleWindow
interface, callIOleWindow.GetWindow
to get theHWND
. Create an instance of theSystem.Windows.Forms.NativeWindow
class and callNativeWindow.AssignHandle
. You can then pass theNativeWindow
object toForm.Show
orForm.ShowModal
(NativeWindow
object implements theIWin32Window
interface).