Windows 窗体有什么可以唯一标识它的吗?

发布于 2024-10-05 05:26:27 字数 176 浏览 0 评论 0原文

我有一堆表格,需要将其放入列表中,并知道表格是否已在其中。

由于与这个问题无关的原因,我实际上无法引用列表中的表格。

winform 上有我可以使用的 ID 或 Guid 吗?或者我应该在我的所有表单中添加一个指南?

请注意,这是紧凑框架。因此“ID”需要在.NETCF 3.5 中可用。

I have a bunch of forms that I need to put in a list and know if the form is already in there.

For reasons not relevant to this question, I cannot actually have a reference to the form in the list.

Is there a ID or Guid that is on a winform that I could use? Or should I just add a Guid to all my forms?

Note that this is Compact Framework. So the "ID" needs to be available in the .NETCF 3.5.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

无人问我粥可暖 2024-10-12 05:26:28

窗口句柄 (hWnd) 应该可以解决问题。查找表单的 Handle 属性。

The window handle (hWnd) should do the trick. Look for the Handle property of your forms.

我ぃ本無心為│何有愛 2024-10-12 05:26:28

我不知道 winform 中存在任何 ID。因此,我相信为每个表单实例提供 GUID 的方法可能是一个可行的解决方案。你的表单只是一个类,一个具有属性的对象,我没有看到 MS 添加 ID 来标识特定表单的特殊原因,因为这确实是一个特定的要求,只是我的意见。

I'm not aware of any ID present in a winform. Thus I believe your approach of having a GUID for each form instance could be a viable solution. Your form is just a class, an object with properties, I don't see a particular reason why MS would of added an ID to identify a particular form, since this is really a specific requirement, just my opinion.

你列表最软的妹 2024-10-12 05:26:28

我对紧凑框架了解不多。我会寻找 Form.Tag 属性。如果有的话,就使用它。该属性旨在按照程序员的意愿使用。

否则,您可以概括一个 FormBase 类,其他表单将从该类继承。将 Guid 属性放入其中,以便您可以访问它来验证列表中表单是否存在。

此外,Contains 方法接受一个对象作为参数,因此传递预期表单的实例将告诉您您的表单是否在列表中。尽管这可能有点矫枉过正,因为您必须实例化表单才能验证其是否存在于列表中。

另一种方法是使用 Dictionary,您可以在其中为字典的 TKey 部分添加表单名称,并为 TValue 添加您的表单。

I don't know much about the Compact Framework. I would look for the Form.Tag property. If there is one, use it. This property is meant to be used for programmer's will.

Otherwise, you could just generalize a FormBase class from which your other forms would inherit. Put in it the Guid property so that you will access it to verify a form's existance in the list.

Besides, the Contains method takes an object as an argument, so passing an instance of your expected form would tell you whether your form is in the list. Although this might be a bit overkill, since you have to instantiate your form to verify its existance into the list.

Another way around is the use of a Dictionary<Tkey, TValue>, where you can add the name of a form for the TKey part of the dictionary, and your form as for the TValue.

素染倾城色 2024-10-12 05:26:28

Form.Name(继承自 Control)也能达到这个目的。

Form.Name (inherited from Control) can also do the trick.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文