Solved

Rotate Report Text

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

734 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