Solved

Rotate Report Text

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
LINQ - C# to VB convertion 12 56
VB.net Move a class from Solution Items to a project 2 22
Help with exporting to excel 4 25
vb.net class 3 11
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

786 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