Solved

Rotate Report Text

Posted on 2006-06-27
2
506 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

919 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now