Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing obsolete VisualBasic.Compatibility.VB6.Support

Tags:

c#

.net-4.0

vb6

we have recently upgraded an old VB6 windows app to C# .NET 4.0. I am looking to replace references to the Microsoft.VisualBasic.Compatibility.VB6.Support class, as Visual Basic 2010 is warning me that 'Microsoft.VisualBasic.Compatibility.* classes are obsolete and supported within 32 bit processes only. http://go.microsoft.com/fwlink/?linkid=160862'

This article assures me that: 'Functions in the Compatibility namespaces were created to work around shortcomings in version 1.0 of the .NET Framework. In most cases, functionality added in later framework versions can be used to rewrite the functions, resulting in improved performance.'

My question is, what are the additions to later framework versions that I need to use to do away with the Compatibility.* classes? I need to phase out TwipsToPixelX, TwipsToPixelY, and so forth. Also, FontChangeUnderline, FontChangeSize, and other font-related stuff.

like image 567
Booberry Avatar asked Nov 15 '10 15:11

Booberry


People also ask

Is VB6 still supported by Microsoft?

Support Statement for Visual Basic 6.0 | Microsoft Learn. This browser is no longer supported. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Will Windows 11 support VB6?

Microsoft has confirmed in a support statement on Microsoft Docs that it will not stop supporting VB6 applications on Windows 11 by including it in the list of operating systems that can run Visual Basic apps.

Is VB Net compatible with VB6?

It is true that VB.NET is an evolved version of Visual Basic 6, but it's not compatible with it. If you write your code in Visual Basic 6, you cannot compile it under VB.NET.

Is VB Net still supported?

Both Visual Basic and C# customers can continue to use . NET Framework and need to port to . NET Core only if you want features like those listed above. If your application uses technologies that aren't supported on .


2 Answers

Thanks for all the help everyone. Just to follow up, here's what I cooked up in dealing with the twips-to-pixels conversions.

    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;
    }

Hope that someone finds this interesting and/or useful

like image 98
Booberry Avatar answered Oct 21 '22 12:10

Booberry


The font related functions can be replaced easily enough. For example:

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

This checks whether the desired style is already set. If it is, it returns the old font. Otherwise it will return a new font that has the same style, except for the bold style, which is now set according to the requirement.

like image 3
Konrad Rudolph Avatar answered Oct 21 '22 11:10

Konrad Rudolph