Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.


haz33haz33 Posts: 11Member

I'm wondering if someone could help me with this. I've used VB6 for years and am just now moving over to VB 2005. One of the problems I found a workaround for in VB6 was large fonts vs. small fonts. Some machines I support used the large font system setting while a number of other ones use the small font system setting. I know that one would say to just make all machines one or the other. But we have such a large number of machines to support that it just isn't possible.

Anyways, with VB6, I was able to use the TwipsPerPixelX and TwipsPerPixelY functions to determine a machine's font size. Then, if the font size was different from my development machine's font size, my code would resize controls and fonts accordingly. It worked pretty slick.

The problem is that I want to do the same thing in VB 2005. Unfortunately, the TwipsPerPixel functions don't seem to be around anymore. I've read about them being available in the Microsoft.VisualBasic.Compatibility namespace, and I'm able to find Microsoft.VisualBasic in the object browser. However, it does not contain a Compatibility namespace inside of it.

Can anyone help? Thanks!


  • DrMartenDrMarten Posts: 748Member
    [b][red]This message was edited by DrMarten at 2006-9-18 5:47:44[/red][/b][hr]
    ScaleMode is not supportedSee Also
    Form Object Changes in Visual Basic .NET
    In Visual Basic 6.0, the ScaleMode property could be used to change the coordinate system for a form or PictureBox control from the default scale of twips.

    Visual Basic .NET does not support multiple coordinate systems; only pixels are supported. During upgrade, coordinates are automatically converted from twips to pixels; code that sets the ScaleMode property at run time will cause a compilation error and must be modified.

    Note The upgrade tool assumes that the design-time setting for the ScaleMode property was twips; if this is not the case, the conversion will be incorrect and must be fixed.
    What to do next

    Remove the line of code that sets the ScaleMode property.
    Review any code that was based on the ScaleMode property and modify any calculations as necessary. For example, the following code shows how to modify a procedure that used a ScaleMode of inches.
    ' Visual Basic 6.0
    Form1.ScaleMode = vbInches
    Text1.Move 2, 1
    'The above procedure moves the text box 2 inches right and 1 inch down from the upper left corner of the form.

    ' After upgrade to Visual Basic .NET
    'UPGRADE ISSUE: Constant vbInches was not upgraded.
    'UPGRADE ISSUE: Form property Form1.ScaleMode is not supported.
    ' The next line must be removed in order to compile.
    Form1.ScaleMode = vbInches
    ' Twips are converted to pixels, but the original inch values are used.
    Text1.SetBounds(VB6.TwipsToPixelsX(2), VB6.TwipsToPixelsX(1),...
    After upgrade, the procedure moves the text box right by 2 pixels and down by 1 pixel not the desired result.
    ' Modified Visual Basic .NET code
    ' Removed the ScaleMode line.
    ' Convert the scale (1 inch = 1440 twips).
    Text1.SetBounds(VB6.TwipsToPixelsX(2880), VB6.TwipsToPixelsX(1440),...
    'By multiplying the inches by 1440, the twips to pixel conversion now gives the same result as in the original Visual Basic 6.0 code.


    Dr M.

  • DrMartenDrMarten Posts: 748Member
    Matrix.Scale Method
    See Also
    Matrix Class | Matrix Members | System.Drawing.Drawing2D Namespace | Managed Extensions for C++ Programming



    Visual Basic

    Show All
    Applies the specified scale vector to this Matrix object by prepending the scale vector.

    Overload List
    Applies the specified scale vector to this Matrix object by prepending the scale vector.

    [Visual Basic] Overloads Public Sub Scale(Single, Single)
    [C#] public void Scale(float, float);
    [C++] public: void Scale(float, float);
    [JScript] public function Scale(float, float);
    Applies the specified scale vector (scaleX and scaleY) to this Matrix object using the specified order.

    [Visual Basic] Overloads Public Sub Scale(Single, Single, MatrixOrder)
    [C#] public void Scale(float, float, MatrixOrder);
    [C++] public: void Scale(float, float, MatrixOrder);
    [JScript] public function Scale(float, float, MatrixOrder);
    [Visual Basic, C#] The following example is designed for use with Windows Forms, and it requires PaintEventArgs e, an OnPaint event object. The code performs the following actions:

    Draws a rectangle to the screen prior to applying a scaling transform (the blue rectangle).
    Creates a matrix and scales it by 3 in the x-axis and 2 in the y-axis.
    Applies this matrix transform to the rectangle.
    Draws the transformed rectangle to the screen (the red rectangle).
    [Visual Basic, C#] Notice that the red rectangle has been scaled by a factor of 3 in the x-axis and by 2 in the y-axis, including the upper left-hand corner of the rectangle (the beginning point of the rectangle).

    [Visual Basic, C#] Note This example shows how to use one of the overloaded versions of Scale. For other examples that might be available, see the individual overload topics.
    [Visual Basic]
    Public Sub ScaleExample(e As PaintEventArgs)
    Dim myPen As New Pen(Color.Blue, 1)
    Dim myPen2 As New Pen(Color.Red, 1)
    ' Draw the rectangle to the screen before applying the
    ' transform.
    e.Graphics.DrawRectangle(myPen, 50, 50, 100, 100)
    ' Create a matrix and scale it.
    Dim myMatrix As New Matrix()
    myMatrix.Scale(3, 2, MatrixOrder.Append)
    ' Draw the rectangle to the screen again after applying the
    ' transform.
    e.Graphics.Transform = myMatrix
    e.Graphics.DrawRectangle(myPen2, 50, 50, 100, 100)
    End Sub


    Dr M.

Sign In or Register to comment.