gpt4 book ai didi

c# - 强制自定义系统类使用

转载 作者:行者123 更新时间:2023-11-30 17:04:30 24 4
gpt4 key购买 nike

我创建了类 MyToolStrip:ToolStrip{}。我的项目已经有大约 60 个工具条实例。

有没有办法(签名查找/替换除外):

  1. 强制我创建的所有表单使用 MyToolStrip 而不是 ToolStrip?
  2. 强制将来使用 MyToolStrip 而不是 ToolStrip(编译器警告足够好但不是最好的)?

我相信既没有将 ToolStrip 标记为过时也没有“覆盖”或隐藏系统类的正确方法。那么什么是最佳实践?谢谢。

最佳答案

Is there a way (except signature find/replace) to force all my created forms to use MyToolStrip instead ToolStrip?

不是我能想到的 - 如果您的表单使用 ToolStrip 控件,则无法在其位置“注入(inject)”您的控件。即使您尝试使用巧妙的 #using 别名来隐藏标准控件,设计人员也会默认将完整的命名空间添加到控件声明中:

private System.Windows.Forms.ToolStrip toolStrip1;

Is there a way (except signature find/replace) to force future MyToolStrip usage instead of ToolStrip (compiler warning is good enough but not the best)?

再说一遍,我想不出来。如果您控制了 ToolStrip,您可以将其标记为 [Obsolete],这会导致编译器警告或错误(取决于您希望如何使用它),但由于它是框架类你没有那么奢侈。

恕我直言,60 个实例并不会太多,无法通过查找/替换...

关于c# - 强制自定义系统类使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17433232/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com