Solved

Rotate Report Text

Posted on 2006-06-27
2
509 Views
Last Modified: 2008-02-01
Using vs2005, I would like to rotate the text in a textbox on my report to –90 or 270 degrees.  Any help would be greatly appreciated.  Thanks.
0
Comment
Question by:sr101880
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Author Comment

by:sr101880
ID: 17122173
I worked out a way to accomplish this with a bit of a workaround.

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.
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 17124826
Closed, 500 points refunded.
Netminder
Site Admin
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question