【问题标题】:Replacing obsolete VisualBasic.Compatibility.VB6.Support替换过时的 VisualBasic.Compatibility.VB6.Support
【发布时间】:2010-11-15 15:48:08
【问题描述】:

我们最近将旧的 VB6 Windows 应用程序升级到 C# .NET 4.0。我希望替换对 Microsoft.VisualBasic.Compatibility.VB6.Support 类的引用,因为 Visual Basic 2010 警告我“Microsoft.VisualBasic.Compatibility.* 类已过时,仅在 32 位进程中受支持。 http://go.microsoft.com/fwlink/?linkid=160862'

本文向我保证:“创建兼容性命名空间中的函数是为了解决 .NET Framework 1.0 版中的缺陷。在大多数情况下,可以使用后续框架版本中添加的功能来重写功能,从而提高性能。'

我的问题是,我需要在以后的框架版本中添加哪些内容来取消 Compatibility.* 类?我需要逐步淘汰 TwipsToPixelX、TwipsToPixelY 等。此外,FontChangeUnderline、FontChangeSize 和其他与字体相关的东西。

【问题讨论】:

  • .NET 不再使用缇。改写你的程序以依赖像素,你应该没问题。
  • 我需要一种可靠的方法将旧的缇值从旧版应用程序转换为像素。对于大多数设备来说,这很简单:像素 * 15 = 缇。但是,并非在所有设备上都是如此。这个 VisualBasic.Compatibility 类有进行这种转换的方法;我需要在 C# 中重新执行这些方法并删除对 VisualBasic.Compatibility 的依赖。
  • 乘数是 1440 除以 Graphics.DpiX/Y 属性值。

标签: c# vb6 .net-4.0


【解决方案1】:

感谢大家的帮助。只是为了跟进,这就是我在处理 twips-to-pixels 转换时所做的。

    private const float TWIPS_PER_INCH = 1440f;
    private static Form _form = new Form();
    private static Graphics _graphics = _form.CreateGraphics();

    public static float TwipsPerPixelX()
    {
        return TWIPS_PER_INCH/_graphics.DpiX;
    }

    public static double TwipsToPixelsY(double twips)
    {
        float dpiy = _graphics.DpiY;
        return twips * dpiy / TWIPS_PER_INCH;
    }

    public static double TwipsToPixelsX(double twips)
    {
        float dpix = _graphics.DpiX;
        return twips * dpix / TWIPS_PER_INCH;
    }

    public static double PixelsToTwipsY(double pixels)
    {
        float dpiy = _graphics.DpiY;
        return pixels * TWIPS_PER_INCH / dpiy;
    }

    public static double PixelsToTwipsX(double pixels)
    {
        float dpix = _graphics.DpiX;
        return pixels * TWIPS_PER_INCH / dpix;
    }

希望有人觉得这很有趣和/或有用

【讨论】:

  • @Booberyy 你救了我的命!
【解决方案2】:

字体相关的功能可以很容易地替换。例如:

Function FontChangeBold(f As Font, bold As Boolean) As Font
    Dim alreadySet = (f.Style And FontStyle.Bold) = FontStyle.Bold
    If bold = alreadySet Then Return f
    If bold Then Return New Font(f, f.Style Or FontStyle.Bold)
    Return New Font(f, f.Style And Not FontStyle.Bold)
End Function

这会检查是否已经设置了所需的样式。如果是,则返回旧字体。否则会返回一个新的字体,除了bold的样式外,它的样式是一样的,现在根据需求设置了。

【讨论】:

    【解决方案3】:

    您可以通过写new Font(oldFont, FontStyle.Underline)new Font(oldFont, 12)来创建不同风格的字体。

    【讨论】:

      【解决方案4】:

      不再需要缇。您现在可以简单地使用原始像素作为尺寸。

      字体请查看Font Class

      【讨论】:

        【解决方案5】:

        对于那些 VB 人来说,这对我有用,能够切换粗体、斜体和/或下划线。

        Private Function SetNewFont(ByRef f As Font, Optional ByVal bToggleBold As Boolean = False, Optional ByVal bToggleItalics As Boolean = False, Optional ByVal bToggleUnderLine As Boolean = False) As Font
        
            Dim fs As FontStyle
        
            If bToggleBold = True Then
                If f.Bold = False Then
                    fs = FontStyle.Bold
                End If
            Else
                If f.Bold = True Then
                    fs = FontStyle.Bold
                End If
            End If
        
            If bToggleItalics = True Then
                If f.Italic = False Then
                    fs += FontStyle.Italic
                End If
            Else
                If f.Italic = True Then
                    fs += FontStyle.Italic
                End If
            End If
        
            If bToggleUnderLine = True Then
                If f.Underline = False Then
                    fs += FontStyle.Underline
                End If
            Else
                If f.Underline = True Then
                    fs += FontStyle.Underline
                End If
            End If
        
            Return New Font(f, fs)
        
        End Function
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-01-03
          • 1970-01-01
          • 2011-11-30
          • 1970-01-01
          相关资源
          最近更新 更多