我们最近将旧的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版中的缺点而创建的。在大多数情况下,后续框架版本中添加的功能可用于重写功能,从而提高性能。“
我的问题是,我需要使用什么来添加后续框架版本以取消兼容性。*类?我需要逐步淘汰TwipsToPixelX,TwipsToPixelY等等。此外,FontChangeUnderline,FontChangeSize和其他与字体相关的东西。
答案 0 :(得分:8)
感谢所有人的帮助。只是为了跟进,这是我在处理缇到像素转换时所做的事情。
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;
}
希望有人发现这个有趣和/或有用的
答案 1 :(得分:3)
字体相关功能可以轻松更换。例如:
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
样式除外,该样式现在根据要求设置。
答案 2 :(得分:0)
您可以通过撰写new Font(oldFont, FontStyle.Underline)
或new Font(oldFont, 12)
来创建不同风格的字体。
答案 3 :(得分:0)
对于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
答案 4 :(得分:-1)
不再需要缇。您现在可以简单地使用原始像素作为尺寸。
至于字体,请查看Font Class。