我在 .Net Framework 项目中使用了 Syetem.Windows.Forms 库,但现在我已将其迁移到 .Net7.0,现在“System.Windows.Forms”在 .net7.0 中不可用。 因为我想让我的项目兼容跨平台,所以我不想在我的 .csproj 文件中添加此属性 -
<UseWindowsForms>true</UseWindowsForms>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
这将使其仅适用于特定于窗口的项目。
下面是代码,我在其中使用 Window.Form 库 PropertyTab 类并重写 Bitmap、TagName、GetProperties 属性和方法。
using System;
using System.Diagnostics;
using System.Collections;
using System.Drawing;
using System.Reflection;
using System.ComponentModel;
using System.Windows.Forms.Design;
namespace MARKEM.LocalisationServices
{
/// <summary>
/// LocalisedPropertyTab inherits from PropertyTab so to allow customization of
/// the properties displayed in the PropertyGrid.
/// </summary>
public class LocalisedPropertyTab : PropertyTab
{
/// <summary>
/// The Property Tab's display name.
/// </summary>
private string m_tabName;
/// <summary>
/// Constructs a new PropertyTab with a specified display name.
/// </summary>
/// <param name="tabName">Name of the PropertyTab.</param>
public LocalisedPropertyTab(string tabName) : base()
{
m_tabName = tabName;
}
/// <summary>
/// Get the name of the tab.
/// </summary>
public override string TabName {
get {
return m_tabName;
}
}
/// <summary>
/// Get a Bitmap for the Tab.
/// Currently returns an empty 16x16 bitmap as we don't need a visual display
/// when there is only one tab.
/// </summary>
public override Bitmap Bitmap {
get {
return new Bitmap(16,16);
}
}
public override PropertyDescriptorCollection GetProperties(object component, Attribute[] attrs) {
//Removed the code
}
}//end of class
}//end of namespace
微软是否提供任何替代库来代替 System.Windows.Forms
检查替代方案,仍然没有找到任何解决方案。