473,890 Members | 1,197 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inherited label text alignment and rotation problem

I'm having a problem with an inherited label, applying text rotation to
aligned text.
If text rotation is applied to the aligned text, the alignment goes 'nuts'.
I can find no logic to what is happening.

I've built the following code from several examples on the web, if you
remove the rotation then alignment works fine:

Imports System.Componen tModel

Public Class TransparentLabe l
Inherits Label

Private _RotationAngle As Integer

#Region " Windows Form Designer generated code "

Public Sub New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'UserControl1 overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnos tics.DebuggerSt epThrough()Priv ate Sub
InitializeCompo nent()
'TransparentLab el
Me.BackColor = System.Drawing. Color.DeepPink
Me.Name = "TransparentLab el"
Me.Size = New System.Drawing. Size(256, 46)

End Sub

#End Region
Public Property RotationAngle() As Integer
RotationAngle = _RotationAngle
End Get
Set(ByVal value As Integer)
_RotationAngle = value
End Set
End Property

Private Sub TransparentLabe l_Paint(ByVal sender As Object, ByVal e As
System.Windows. Forms.PaintEven tArgs) Handles MyBase.Paint
Dim sFormat As StringFormat = Nothing

sFormat = New StringFormat

If Me.TextAlign <= ContentAlignmen t.TopRight Then
sFormat.LineAli gnment = StringAlignment .Near
ElseIf Me.TextAlign >= ContentAlignmen t.BottomRight Then
sFormat.LineAli gnment = StringAlignment .Far
sFormat.LineAli gnment = StringAlignment .Center
End If

If Me.TextAlign = ContentAlignmen t.BottomLeft Or Me.TextAlign =
ContentAlignmen t.MiddleLeft Or Me.TextAlign = ContentAlignmen t.TopLeft Then
sFormat.Alignme nt = StringAlignment .Near
ElseIf Me.TextAlign = ContentAlignmen t.BottomRight Or
Me.TextAlign = ContentAlignmen t.MiddleRight Or Me.TextAlign =
ContentAlignmen t.TopRight Then
sFormat.Alignme nt = StringAlignment .Far
sFormat.Alignme nt = StringAlignment .Center
End If

'variables to capture the size of the text area
Dim width As Double = e.Graphics.Meas ureString(Text,
Dim height As Double = e.Graphics.Meas ureString(Text,
'convert the rotation angle into radians for trig functions
Dim angleRadian As Double = ((_rotationAngl e Mod 360) / 180) *
'capture the forground color as a brush
Dim myBrush As Brush = New SolidBrush(Me.F oreColor)

'If Me.BackColor = Color.Transpare nt Then
If Me.AutoSize Then
Dim Siz As Drawing.SizeF = e.Graphics.Meas ureString(Me.Te xt,
Me.Width = Siz.Width + 1
Me.Height = Siz.Height + 1
End If
Dim B As New Bitmap(Me.Width , Me.Height)
Dim G As Graphics = Graphics.FromIm age(B)
Dim TextArea As New Rectangle(0, 0, Me.Width, Me.Height)

If Me.BackColor = Color.Transpare nt Then
G.FillRectangle (New SolidBrush(Colo r.DeepPink), TextArea)
G.FillRectangle (New SolidBrush(Me.B ackColor), TextArea)
End If

G.TranslateTran sform(CInt((Cli entRectangle.Wi dth + (height *
Math.Sin(angleR adian)) - (width * Math.Cos(angleR adian))) / 2),
CInt((ClientRec tangle.Height - (height * Math.Cos(angleR adian)) - (width *
Math.Sin(angleR adian))) / 2))
G.RotateTransfo rm(CInt(_Rotati onAngle))
G.DrawString(Me .Text, Font, myBrush, TextArea, sFormat)
G.SmoothingMode = Drawing2D.Smoot hingMode.AntiAl ias
G.ResetTransfor m()

Dim Pth As New Drawing2D.Graph icsPath()
Dim X, Y As Short
For X = 0 To Me.Width - 1
For Y = 0 To Me.Height - 1
If B.GetPixel(X, Y).ToArgb.ToStr ing =
Color.DeepPink. ToArgb.ToString Then
Pth.AddRectangl e(New Rectangle(X, Y, 1, 1))
End If

Dim Rgn As Region

If Me.BackColor = Color.Transpare nt Then
G.FillRectangle (New SolidBrush(Me.F oreColor), New
Rectangle(0, 0, Me.Width, Me.Height))
End If

e.Graphics.Draw Image(B, 0, 0)
Rgn = New Region(New Rectangle(0, 0, Me.Width, Me.Height))
If Me.BackColor = Color.Transpare nt Then
Rgn.Exclude(Pth )
End If
Me.Region = Rgn

Catch ex As Exception
End Try
End Sub

Private Sub TransparentLabe l_Load(ByVal sender As Object, ByVal e As
System.Windows. Forms.PaintEven tArgs) Handles MyBase.Paint
SetStyle(Contro lStyles.AllPain tingInWmPaint, True)
SetStyle(Contro lStyles.DoubleB uffer, True)
SetStyle(Contro lStyles.UserPai nt, True)
End Sub
End Class

Can anyone advise me what I'm doing wrong to throw the alignment out?

Oct 19 '06 #1
0 1808

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Rui Patinha | last post by:
Hello, I have a label in a report that is filled up with text from a query. The problem is that I need to justify the alignment, but not as it does by default... let me try to clear this... if I get a 5 line text from the query, all the lines have the label width, even if the last line just have 1 word! I tryed to put spaces after the text, but it doesn't do the trick. If I put underscores and spaces
by: Stuart Norris | last post by:
Dear Readers, I am attempting to draw box around some text using unicode on multiline label. The label is forty characters wide and 12 lines deep. I have been trying to draw a box around text (centered in the label) on this label. My font on this label is Courier new - hence fixed width character cells.
by: David | last post by:
Hello. I have a Label control on my web form and I have long text in it. What I want is to disable text wrapping of this Label. Is it possible? Also I want to know how can I set text alignment to right in Label? Thank you.
by: Mike Bulava | last post by:
I have created a base form that I plan to use throughout my application let call the form form1. I have Built the project then add another form that inherits from form1, I add a few panel controls each with a couple of controls in them I then rebuilt my project and my new panels and all controls they contained are gone... I've looked through the Auto generated code but don't see anything that looks wrong Any body have any idea why this...
by: jcrouse | last post by:
I am rotating some text is some label controls. In the one place I use it it works fine. In the other place I use it I can't figure out the syntax. I don't really understand the event. Where it works fine, it seems to fire when the form changes visibility. Here is the code. Private Sub lblP1JoyUp_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles lblP1JoyUp.Paint If lblP1JoyUp.Visible = True Then Dim...
by: Nak | last post by:
Hi there, I have some inherited forms that I wish to make "localizable", unfortunately none of the items I wish to be "localizable" are actually being "localized". For example, I have a few of properties which set the text of some labels on the form which are inherited from the base form, these text values aren't "localized" Has anyone any ideas where I'm going wrong? Nick.
by: Jeff User | last post by:
Hello I am using C#, .net1.1 Vis Studio 2003 I am using homeBase.aspx.cs page as a base for several other aspx/aspx.cs web pages. The base page handles some operations that are common to all pages. like this: somepage... public class homeBase : System.Web.UI.Page .... then other pages.....
by: André Hänsel | last post by:
Hi again, I have a radio button: <p> <input id="v_yes" type="radio" name="v" value="yes" /> <label for="v_yes">Ja</label> <input id="v_no" type="radio" name="v" value="no" /> <label for="v_no">Nein</label> </p>
by: swapna_munukoti | last post by:
Hi all, I am new to asp.net. So, may be my question may be simple. But I am feeling hard to achieve this. I need to create a web custom label control, for which I have to assign new property called "Align". It should have center,left and right alignments. I have created a label with this property and set that to textalign. But it doesnt have center alignment. How can I get center alignment?
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.