通过应用程序使表单全局可访问
在我的 VS-2008 Windows 应用程序中,我想显示一个带有进度条的弹出表单。在后台运行的类应该直接向其发送进度条值。我希望可以通过键入其名称而不是通过创建实例来直接访问此表单。
如果我将其 Accessible Role 属性设置为 Dialog,它将出现在顶部并干扰用户的工作。我希望此窗体在屏幕的某个角落运行,并且应该显示为 MDI 窗体的子窗体,但应该可以直接访问。
In my VS-2008 Windows application, I want to show a popup form with progress bar on it. A class running in the background should directly send progress bar values to it. I want this Form to be accessible directly by typing its name and not by creating instances.
If I set it's Accessible Role property to Dialog, it will come on top and will interfere with user's work. I want this Form to run in some corner of the screen and should appear as a child of the MDI form but should be accessible directly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://en.wikipedia.org/wiki/Singleton_pattern
最简单的方法就是让你的整个class static,并将所有实例变量和方法更改为static。然后您可以通过类名调用方法,例如
MyFormClass.UpdateProgress(2);
对于某些希望您存储单个非静态实例的人(包括我)来说,这样做是丑陋的您的类的某处并通过控制对象/方法控制对其的访问。我不确定这种观点在 C# 的无忧编程世界中是否合理。
另外,如果您计划从后台线程更新进度条,请记住 winform 不是线程安全的。
http://en.wikipedia.org/wiki/Singleton_pattern
The simplest way is to make your whole class static, and change all instance variables and methods to static. Then you can call the methods by class name, like
MyFormClass.UpdateProgress(2);
Doing it this way is ugly to some people (including me) who would prefer you to store a single non-static instance of your class somewhere and control access to it through a control object/method. I'm not sure how much of that opinion is legitimate in the C# world of implementation-worries-free programming.
Also if you're planning on updating the progress bar from a background thread keep in mind that winforms are not threadsafe.