none
Textbox rotation or display horizontal vs vertical

    Question

  • Is it possible to align a text box to display text with rotation?  For example can I display it rotated 90 degrees left so that it reads from the bottom towards the top of the page?  All I can find is left/right alignment and top/middle/bottom alignment.  I want to rotate the text.

    Thanks.

    Tuesday, June 20, 2006 9:08 PM

Answers

  • 1Dave,

    This is something that I have been working on in vs2005.  It hasn't been tested in Reporting Services but it should give you a direction to go in.

    To display text rotated 90 to the left in reportviewer:

     

    1.                  Go to the Report Menu and Select Report Properties.

    2.                  Select the References Tab.

    3.                  Add a reference under assembly name to System.Drawing

    4.                  Click on the code Tab.

    5.                  Add the following Code:

     

    Function LoadImage(ByVal sImageText as String)

             

            sImageText= sImageText.PadRight(50) & "  |"        ‘ Change this as needed

     

            Dim iFontSize As Integer = 10 ‘Change this as needed

     

            Dim bmpImage As New Drawing.Bitmap(1, 1)

     

            Dim iWidth As Integer = 0

            Dim iHeight As Integer = 0

     

            '// Create the Font object for the image text drawing.

            Dim MyFont As New Drawing.Font("Courier New", iFontSize, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point)

     

            '// Create a graphics object to measure the text's width and height.

            'Graphics(MyGraphics = Graphics.FromImage(bmpImage))

            Dim MyGraphics As Drawing.Graphics = Drawing.Graphics.FromImage(bmpImage)

     

            '// This is where the bitmap size is determined.

            iWidth = MyGraphics.MeasureString(sImageText, MyFont).Width

            iHeight = MyGraphics.MeasureString(sImageText, MyFont).Height

     

            '// Create the bmpImage again with the correct size for the text and font.

            'bmpImage = New Drawing.Bitmap(bmpImage, New Drawing.Size(iWidth, iHeight))

            bmpImage = New Drawing.Bitmap(bmpImage, New Drawing.Size(iHeight, iWidth))

     

            '// Add the colors to the new bitmap.

            MyGraphics = Drawing.Graphics.FromImage(bmpImage)

            MyGraphics.Clear(Drawing.Color.White)

            MyGraphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias

     

            MyGraphics.TranslateTransform(0, iWidth)

            MyGraphics.RotateTransform(270)

            MyGraphics.DrawString(sImageText, MyFont, New Drawing.SolidBrush(Drawing.Color.Black), 0, 0)

            MyGraphics.Flush()

     

            Dim stream As IO.MemoryStream = New IO.MemoryStream

            Dim bitmapBytes As Byte()

            'Create bitmap 

            bmpImage.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg)

            bitmapBytes = stream.ToArray

            stream.Close()

            bmpImage.Dispose()

     

            Return bitmapBytes

     

     

        End Function

     

    6.                  Click ok to save and close the Report Properties.

    7.                  You may use a textbox or image control on your form to display the rotated text.

    8.                  For a textbox you need to set the BackgroundImage properties, for both the image control and textbox set the following:

     

    Source = Database

    MIMEType = image/jpeg

     

    9.                  To assign the text to be rotated to the control just set:

     

    Value = Code.LoadImage("Your Text Here!")   or

    Value = Code.LoadImage(Fields!FirstName.Value)

     

    10.              If you are calling the Reportviewer Report from a form you need to add the following code to your form load event:

     

    Me.ReportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bla bla bla")  ‘You need to copy the assembly info from your Report Properties References tab for this to work.

     

     

     

    Let me know if you have any questions.

    Monday, July 17, 2006 2:08 PM

All replies

  • You can use the WritingMode property (sometimes just labeled Mode) of a textbox to determine whether it is written vertically (tb-rl) or horizontally (lr-tb). 

    See if the property documentation on http://msdn2.microsoft.com/en-us/ms189363.aspx helps.

    • Proposed as answer by AliceLaura Friday, June 08, 2012 9:33 PM
    Tuesday, June 20, 2006 10:20 PM
  • Thanks... thats almost it.  But the text I want the text to read the other direction.  tb-rl is the choice.. but i want it to be tb-lr.  Is that possible?

    Thanks

    Wednesday, June 21, 2006 1:44 PM
  • 1Dave,

    This is something that I have been working on in vs2005.  It hasn't been tested in Reporting Services but it should give you a direction to go in.

    To display text rotated 90 to the left in reportviewer:

     

    1.                  Go to the Report Menu and Select Report Properties.

    2.                  Select the References Tab.

    3.                  Add a reference under assembly name to System.Drawing

    4.                  Click on the code Tab.

    5.                  Add the following Code:

     

    Function LoadImage(ByVal sImageText as String)

             

            sImageText= sImageText.PadRight(50) & "  |"        ‘ Change this as needed

     

            Dim iFontSize As Integer = 10 ‘Change this as needed

     

            Dim bmpImage As New Drawing.Bitmap(1, 1)

     

            Dim iWidth As Integer = 0

            Dim iHeight As Integer = 0

     

            '// Create the Font object for the image text drawing.

            Dim MyFont As New Drawing.Font("Courier New", iFontSize, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point)

     

            '// Create a graphics object to measure the text's width and height.

            'Graphics(MyGraphics = Graphics.FromImage(bmpImage))

            Dim MyGraphics As Drawing.Graphics = Drawing.Graphics.FromImage(bmpImage)

     

            '// This is where the bitmap size is determined.

            iWidth = MyGraphics.MeasureString(sImageText, MyFont).Width

            iHeight = MyGraphics.MeasureString(sImageText, MyFont).Height

     

            '// Create the bmpImage again with the correct size for the text and font.

            'bmpImage = New Drawing.Bitmap(bmpImage, New Drawing.Size(iWidth, iHeight))

            bmpImage = New Drawing.Bitmap(bmpImage, New Drawing.Size(iHeight, iWidth))

     

            '// Add the colors to the new bitmap.

            MyGraphics = Drawing.Graphics.FromImage(bmpImage)

            MyGraphics.Clear(Drawing.Color.White)

            MyGraphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias

     

            MyGraphics.TranslateTransform(0, iWidth)

            MyGraphics.RotateTransform(270)

            MyGraphics.DrawString(sImageText, MyFont, New Drawing.SolidBrush(Drawing.Color.Black), 0, 0)

            MyGraphics.Flush()

     

            Dim stream As IO.MemoryStream = New IO.MemoryStream

            Dim bitmapBytes As Byte()

            'Create bitmap 

            bmpImage.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg)

            bitmapBytes = stream.ToArray

            stream.Close()

            bmpImage.Dispose()

     

            Return bitmapBytes

     

     

        End Function

     

    6.                  Click ok to save and close the Report Properties.

    7.                  You may use a textbox or image control on your form to display the rotated text.

    8.                  For a textbox you need to set the BackgroundImage properties, for both the image control and textbox set the following:

     

    Source = Database

    MIMEType = image/jpeg

     

    9.                  To assign the text to be rotated to the control just set:

     

    Value = Code.LoadImage("Your Text Here!")   or

    Value = Code.LoadImage(Fields!FirstName.Value)

     

    10.              If you are calling the Reportviewer Report from a form you need to add the following code to your form load event:

     

    Me.ReportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bla bla bla")  ‘You need to copy the assembly info from your Report Properties References tab for this to work.

     

     

     

    Let me know if you have any questions.

    Monday, July 17, 2006 2:08 PM
  • i am unsure of where "Report Properties" are located.  could you shed some light?

    Thursday, March 01, 2007 5:44 PM
  • Rightclick in the background of the report (in the reports layout) and select properties.

    Jens K. Suessmeyer.

    ---
    http://www.sqlserver2005.de
    ---

    Thursday, March 22, 2007 3:44 PM
  • I have a similar requirement and have tried the solution which uv suggested .. but it doesnt work for me yet   Is there anything else which needs to be taken care of ?

    Monday, June 25, 2007 6:27 AM
  • No, the solution should work like a charme, what is your problem. Do you get an error message ? BTW, the feature was posted by me on the connect.microsoft.com portal to vote for. If you find this one interesting and important, vote for it :-)

    Jens K. Suessmeyer.

    ---
    http://www.sqlserver2005.de
    ---
    Monday, June 25, 2007 7:11 AM
  • I need to incline the text in the textbox. I have tried the solution which has been posted in the thread (i.e creating the function ).. yet when i try to call the function, it gives me an Error and doesnt work .. do you have any inputs ?
    Tuesday, June 26, 2007 9:55 AM
  • More details, which error ?

    Jens K. Suessmeyer.

    ---
    http://www.sqlserver2005.de
    ---
    Tuesday, June 26, 2007 5:44 PM
  • I get the error at runtime :

    • The report references the code module ‘System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’, which is not a trusted assembly.
    So I added
    ReportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bla bla bla");
    to my pageload...but i still get the error
    Wednesday, July 18, 2007 4:10 PM
  • worked great. thank you

     

    Tuesday, July 31, 2007 9:35 PM
  • I followed teh steps outlined but I receive the following error:

     

    [rsCompilerErrorInCode] There is an error on line 12 of custom code: [BC30002] Type 'Drawing.Bitmap' is not defined.

     

    Could anyone help me with this?  I am not a developer per se, just a simple report writer.

     

    Thanks much!

    Thursday, October 25, 2007 3:09 PM
  • I work with Visual Studio 2003 and the solution works for me.

     

    Thank You

     

    I hope that will be fixed in the futur version of Reporting Services

    Wednesday, December 05, 2007 4:09 PM
  • I get the following warning when I try to use this to display static text:

    Warning    1    [rsInvalidExpressionDataType] The Value expression used in textbox ‘textbox5’ returned a data type that is not valid.

    It displays #Error on the rendered output.

    In the expression I have the following:

    =Code.LoadImage("text")

    Not sure what I am doing wrong.....


    Friday, May 02, 2008 1:49 PM
  • I tried this and recieve the error that Drawing.Bitmap is not defined

    how do I fix this

     

     

    Monday, May 05, 2008 11:20 PM
  • I added the reference and pasted the code in the right place.

     

    I typed = Code.LoadImage("Test") in Value. Source as Database. MIMEType as image/jpeg and BackgroundRepeat as NoRepeat.

     

    I didn't get any errors but I get a dash (-) and no image or text.

    Please someone help.

     

    Thanks.

    Monday, May 12, 2008 5:37 PM
  • I bet the dash is the | from the padding line in the code.  Try making you text box larger.
    Monday, May 12, 2008 5:55 PM
  •  

    I did, it didn't help.

    The dash is not |, it is -

     

    Monday, May 12, 2008 6:02 PM
  • Comment out this line like so:

    'sImageText= sImageText.PadRight(50) & "  |"        ‘ Change this as needed

    Let me know if you are getting the same thing after?


    Monday, May 12, 2008 6:10 PM
  • Thanks, it worked.

     

     

    Tuesday, May 13, 2008 2:14 PM
  • I'm having the same problem with #Error in the output.  Does anyone have a fix for this?

    Thanks!
    Matt
    Monday, August 11, 2008 6:12 PM
  • Dont put =Code.LoadImage("Text") in the textbox's value property. Place it in the Textbox's Background Image's Value (in coding terms it's TextBox.BackgroundImage.Value.

     

    That said, I'm still not THAT satisfied with the result due to the fact that the text is a little blurred. But still, thats not the designer's fault. It's the GDI's. Thanks for the hint.

    Friday, August 29, 2008 10:12 AM
  • Thank you for the solution.

     

    It's really working for me. But I am having a problem when exporting this report to excel. The excel is not showing the rotated text.But it is working fine when i export to pdf.Can anyone help me in this isuue?

    Wednesday, November 19, 2008 10:16 AM
  • When I rotate text, some portion of image was not visible, so used trigonometry to calculate imagte size:
    I used following function to rotate text:

      Function RotateImage(ByVal bm_in As System.Drawing.Bitmap, ByVal RotationAngle As Integer) As System.Drawing.Bitmap
            Dim wid As Single = bm_in.Width
            Dim hgt As Single = bm_in.Height
            Dim corners As  System.Drawing.Point() = { _
                New  System.Drawing.Point(0, 0), _
                New  System.Drawing.Point(wid, 0), _
                New  System.Drawing.Point(0, hgt), _
                New  System.Drawing.Point(wid, hgt)}

            ' Translate to center the bounding box at the origin.
            Dim cx As Single = wid / 2
            Dim cy As Single = hgt / 2
            Dim i As Long
            For i = 0 To 3
                corners(i).X -= cx
                corners(i).Y -= cy
            Next i

            ' Rotate.
            Dim theta As Single = Single.Parse(RotationAngle) * System.Math.PI _
                / 180.0
            Dim sin_theta As Single = System.Math.Sin(theta)
            Dim cos_theta As Single = System.Math.Cos(theta)
            Dim X As Single
            Dim Y As Single
            For i = 0 To 3
                X = corners(i).X
                Y = corners(i).Y
                corners(i).X = X * cos_theta + Y * sin_theta
                corners(i).Y = -X * sin_theta + Y * cos_theta
            Next i

            ' Translate so X >= 0 and Y >=0 for all corners.
            Dim xmin As Single = corners(0).X
            Dim ymin As Single = corners(0).Y
            For i = 1 To 3
                If xmin > corners(i).X Then xmin = corners(i).X
                If ymin > corners(i).Y Then ymin = corners(i).Y
            Next i
            For i = 0 To 3
                corners(i).X -= xmin
                corners(i).Y -= ymin
            Next i

            ' Create an output Bitmap and Graphics object.
            Dim bm_out As New  System.Drawing.Bitmap(CInt(-2 * xmin), CInt(-2 * _
                ymin))
            Dim gr_out As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bm_out)

            ' Drop the last corner lest we confuse DrawImage,
            ' which expects an array of three corners.
            ReDim Preserve corners(2)

            ' Draw the result onto the output Bitmap.
            gr_out.Clear(Drawing.Color.White)
            gr_out.DrawImage(bm_in, corners)
            gr_out.Flush()

            ' Display the result.
            Return bm_out
        End Function

    Whole article is available here:
    http://tejasp.blogspot.com/2009/01/ssrs-reports-rotate-text-or-split.html
    Monday, February 02, 2009 2:56 AM
  • Thanx it is working Fine.
    but when im exporting this report into excel that image disappears(Vertical Text Column).
    Plz Provide Help ..
    Abdul
    Wednesday, February 04, 2009 5:05 AM
  • HossHold_em said:

    I get the following warning when I try to use this to display static text:

    Warning    1    [rsInvalidExpressionDataType] The Value expression used in textbox ‘textbox5’ returned a data type that is not valid.

    It displays #Error on the rendered output.

    In the expression I have the following:

    =Code.LoadImage("text")

    Not sure what I am doing wrong.....




    plz.. make sure you don't forget the "End Function" line .. (at the end of the function)
    Thursday, February 12, 2009 6:12 PM
  • Worked great for me after I read all the amendments:
    1. followed your directions
    2. commented out
     "'sImageText= sImageText.PadRight(50) & "  |"        ‘ Change this as needed"
    3. used
                    <TableCell>
                      <ReportItems>
                        <Textbox Name="textbox43">
       ...
                          <Style>
       ...
       <BackgroundImage>
                              <Value>=Code.LoadImage("textValue")</Value>
                              <Source>Database</Source>
                              <BackgroundRepeat>NoRepeat</BackgroundRepeat>
                              <MIMEType>image/jpeg</MIMEType>
                            </BackgroundImage>
       ...
                </Style>
                        <Value />
                        </Textbox>
                      </ReportItems>
                    </TableCell>

    I love it when it works! Thanks for the help  

    Thursday, March 05, 2009 6:38 PM
  • Hi, I have followed the same process. but i got the following error.

    "Error while loading code module: ‘System.Drawing’. Details: Could not load file or assembly 'System.Drawing' or one of its dependencies. The system cannot find the file specified."

    what i need to do.

    I also tried the following:
    1 . by commenting the line --> sImageText= sImageText.PadRight(50) & "  |"
    2. entered the --> Code.LoadImage("Ordered") in BackgroundImage value and text value.

    But the error retains..
    Monday, March 23, 2009 1:57 PM
  •  did you add the reference to System.Drawing ?

    1. Go to the Report Menu and Select Report Properties.
    2. Select the References Tab.
    3. Add a reference under assembly name to System.Drawing
    Monday, March 23, 2009 2:48 PM
  • I do not understand how to add a text-box to a line-chart and have it display the values (dates) of the x-axis

    If Access charts can do this, Crimey!, why is it so difficult in SSRS?

    Frank K
    Monday, October 26, 2009 5:06 PM
  • Thanks.  It did work, but could not use it as the user wouldn't have the ability to copy the cell value, if needed.

    Its a shame that the problem is still open and we can't get it working just by setting a property!
    Wednesday, November 18, 2009 2:39 PM
  • its not working for me. compile time error:

    The BackgroundImageValue for the text box ‘textbox41’ has a constant value.  BackgroundImageValue requires a binary value, so it cannot be a constant.


    Thursday, January 27, 2011 7:55 AM
  • I am working on SQL Server 2008 R2 and there you can rotate the text as mentioned below:

    1. Press F4 to pop the property window.

    2. Select "WritingMode" property. Under Localization group.

    3. Change "Default" to "Vertical" or "Rotate270" as per your convenience.


    Warm Regards, Ajay

    • Proposed as answer by ajaymalloc Thursday, June 07, 2012 2:22 PM
    Thursday, June 07, 2012 2:22 PM
  • Hi Ajay,

    This property 'Rotate270' is not working with Report viewer 2010 control.  Did you check?  Please confirm if it works.


    Regards, Senthil

    Wednesday, August 01, 2012 9:01 AM
  • @Senthil,

    I only have Visual Studio 2008 version 9.0.xx and there this is how managed to do the work. Not sure about Report viewer 2010.


    Warm Regards, Ajay

    Thursday, August 16, 2012 12:48 PM
  • Hi Dave,

    Is there any way to display text direction as tb-lr in excel using SSRS?

    Friday, September 21, 2012 4:03 AM