向 vb.net 应用程序发送通知消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13285808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Send a notification message to vb.net application
提问by BunnyRiven
I'm developing a vb.net windows application and I want some my users will be notified when a new event occurs.(for example: update a field in table, or add a new row in a table) This notification should have same UI as my other vb forms.( I'd like to show it on a seperate form, not any windows messageboxes)
我正在开发一个 vb.net windows 应用程序,我希望我的一些用户在发生新事件时收到通知。(例如:更新表中的字段,或在表中添加新行)此通知应具有相同的 UI作为我的其他 vb 表单。(我想在单独的表单上显示它,而不是任何 Windows 消息框)
I don't know the easiest solution for the problem.
我不知道解决这个问题的最简单的方法。
Thanks in advance.
提前致谢。
-Edited-
-编辑-
The 'notification' i'm trying to explain is something like facebook. For example: While surfing facebook, a friend comments on a status and there is a notification on the top left corner of the page. I'm trying to develop this windows application that uses live data when a record in sql is added, deleted or edited. This application is being run concurrently in many computers(so far only 2) and when 1 user modifies a record the other user will be notified through this 'notification pop-up".
我试图解释的“通知”类似于 facebook。例如:在浏览 facebook 时,朋友对状态发表评论,页面左上角有一个通知。我正在尝试开发此 Windows 应用程序,该应用程序在添加、删除或编辑 sql 中的记录时使用实时数据。此应用程序在多台计算机上同时运行(目前只有 2 台),当 1 个用户修改记录时,其他用户将通过此“通知弹出窗口”收到通知。
And yes using windows forms.
是的,使用 Windows 窗体。
采纳答案by deltu100
In addition to Fabian's answer.
除了法比安的回答。
In the database you should have a boolean, False = unread and True = read "notification".
在数据库中,您应该有一个布尔值,False = 未读和 True = 已读“通知”。
You can make a linq query which gets all the False notifications. To which you edit the numbers, colors and UI.
您可以进行 linq 查询以获取所有 False 通知。您可以编辑数字、颜色和 UI。
Dim getUnread = (From rec In db.Notifications
Where rec.messageBoolean = False
Select rec).toList()
'number of notifications
dim numberOfNotifications as Integer = getUnread.count
If numberOfNotifications >0 Then
labalNotify.text = numberOfNotifications.tostring()
'change colors, add icons, make the world go round.
End If
I think you get the picture
我想你明白了
Have fun
玩得开心
回答by Fabian Tamp
I take it you're using Winforms?
我认为您正在使用 Winforms?
The steps are:
步骤是:
- Make a new form
When the event occurs (i.e. in your event handler), use:
var myForm = new NotificationForm(); NotificationForm.Show();
- 制作新表格
当事件发生时(即在您的事件处理程序中),使用:
var myForm = new NotificationForm(); NotificationForm.Show();
See also To show a new Form on click of a button in C#
另请参阅在 C# 中单击按钮时显示新表单
If you want the notification to appear in an unobtrusive fashion, add a Labelsomewhere on the form and update the Label.Textproperty.
如果您希望通知以不显眼的方式出现,请Label在表单的某处添加一个并更新该Label.Text属性。
To check for a change in SQL database records, you'd want to look at using a web service (if the application needs to be scalable) or, to access a SQL Server database directly, take a look at the SqlConnectionclass.
要检查 SQL 数据库记录中的更改,您需要考虑使用 Web 服务(如果应用程序需要可扩展),或者要直接访问 SQL Server 数据库,请查看SqlConnection类。
Best of luck.
祝你好运。

