rotate control

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

Hi,

Is it possible to rotate a control on a form ? (e.g. Button, customcontrol)

thnx
Christian
 
Chris,

The most simple format is to set the width larger than the height, however I
assume that you want to rotate it completly.

Normally you should find information about this on the pages from Bob Powell
which are
www.bobpowell.net

The newsgroup where he is very active it not in your crossposting

microsoft.public.dotnet.framework.drawing

What I have seen in this newsgroups is, that after they had implemented GDI+
for this, people where disapointed because there programs became slow. So
keep that in mind.

I hope this helps something?

Cor
 
Christian,
In addition to the other comments.

If you handle all the painting of the control yourself (as Cor suggested).
You can use Graphics.RotateTransform to rotate the painting surface before
you do any drawing. You may also need to use Graphics.TranslateTransform to
move the origin...

You would need to override the Paint event if they allow it.

Something like:

Imports System.ComponentModel
Imports System.Windows.Forms

Public Class RotatedLabel
Inherits Label

Private m_angle As Integer

Public Sub New()
' Stop the flicker
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.DoubleBuffer, True)
'Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.UpdateStyles()
End Sub

<Description("Amount to rotate the text"), _
Category("Appearance"), _
DefaultValue(0)> _
Public Property Angle() As Integer
Get
Return m_angle
End Get
Set(ByVal value As Integer)
m_angle = value
Invalidate()
End Set
End Property

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
With e.Graphics
.TranslateTransform(MyBase.ClientSize.Width / 2.0F,
MyBase.ClientSize.Height / 2.0F)
.RotateTransform(m_angle)
.Clear(MyBase.BackColor)
Dim brush As New SolidBrush(MyBase.ForeColor)
.DrawString(MyBase.Text, MyBase.Font, brush, 0, 0)
brush.Dispose()
End With
End Sub

End Class

Some controls, such as the TabControl have limited built-in support for
"rotation" for example see TablControl.Alignment.

In addition to Bob Powell's web site the Cor reference, Charles Petzold's
book "Programming Microsoft Windows with Microsoft Visual Basic .NET"
provides a wealth of information on using GDI+.

Hope this helps
Jay
 
Hi Chris.

If you want to rotate everything you draw on the control's client area the
other posters gave you the solutions.
If you want to rotate the controls in a fashion where the caption, menus,
caret, buttons are rotated and all the mouse clicks take's into acount
this. I'd say it is impossible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top