Solved

Rotate Report Text

Posted on 2006-06-27
2
505 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
Comment Utility
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
Comment Utility
Closed, 500 points refunded.
Netminder
Site Admin
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

14 Experts available now in Live!

Get 1:1 Help Now