-
Apr 15th, 2015, 03:03 AM
#1
Thread Starter
New Member
Italic and CAPITAL in one label
HI
i need to get text1.text in Italic and author.text in CAPITAL to Label1.text
please explain me how to do it.
Thanks
-
Apr 15th, 2015, 04:45 AM
#2
Junior Member
Re: Italic and CAPITAL in one label
Hi
you can try the following in a new project with one form, see if it is what you need...
Code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' combine Italic and Bold on label
Label1.Font = New Font("Arial", 9, FontStyle.Italic Or FontStyle.Bold)
Label1.Text = "AUTHOR :"
' set Capital letter text in textbox with italic font style
TextBox1.CharacterCasing = CharacterCasing.Upper
TextBox1.Font = New Font("Arial", 9, FontStyle.Italic)
TextBox1.Text = "Some Author" & Chr(13)
Label1.Select()
End Sub
End Class
-
Apr 15th, 2015, 12:15 PM
#3
Thread Starter
New Member
Re: Italic and CAPITAL in one label
Originally Posted by vangos
Hi
you can try the following in a new project with one form, see if it is what you need...
Code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' combine Italic and Bold on label
Label1.Font = New Font("Arial", 9, FontStyle.Italic Or FontStyle.Bold)
Label1.Text = "AUTHOR :"
' set Capital letter text in textbox with italic font style
TextBox1.CharacterCasing = CharacterCasing.Upper
TextBox1.Font = New Font("Arial", 9, FontStyle.Italic)
TextBox1.Text = "Some Author" & Chr(13)
Label1.Select()
End Sub
End Class
HI Thanks for the Reply
what exactly i need is.
Assume that text boxes have these values.
author.text= Stefan D
Titleof.text = Day Dreams
Getreferance_click ()
label1.text=Capital(Stefan D) +"," + Italic(Day Dreams)
-------------------------------------------------------------------------
OUT PUT SHOULD BE IN Label.text
STEFAN.D.,Day Dreams
=======================================
Thanks
-
Apr 15th, 2015, 12:32 PM
#4
Re: Italic and CAPITAL in one label
1) The standard label control can only have one font.
2) Never use + when joining text. Use the ampersand character &.
You could use a control that accepts HTML instead of a label control.
Or you could create a new label control that supports multiple fonts.
Burn the land and boil the sea
You can't take the sky from me
~T
-
Apr 15th, 2015, 12:33 PM
#5
Re: Italic and CAPITAL in one label
Not gonna happen... label has a font, and it applies to the whole label. The only control I know of out of the box that can handle multiple fonts in one go is the RichTextBox.
As for the capitalizing, since it's the entire Author.Text string you want capp'd... try author.text.ToUpper ... should get you what you want.
The Italics though... going to require something more than just a simple label.
-tg
-
Apr 15th, 2015, 12:55 PM
#6
Re: Italic and CAPITAL in one label
you can do it by handling the label's paint event and manually drawing the text.
Drop a label on the form and paste the following code...
Code:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Label1.AutoSize = False
Label1.Width = 400
Label1.Text = ""
End Sub
Private Sub Label1_Paint(sender As Object, e As PaintEventArgs) Handles Label1.Paint
Using br As New SolidBrush(Color.Black)
Dim s As String = "regular"
Dim fnt As Font = Me.Label1.Font
Dim sWidth As Single = e.Graphics.MeasureString(s, fnt).Width
e.Graphics.DrawString(s, fnt, br, 0, 0)
s = "italic"
fnt = New Font(fnt.FontFamily.Name, fnt.Size, FontStyle.Italic)
e.Graphics.DrawString(s, fnt, br, sWidth, 0)
fnt.Dispose()
End Using
End Sub
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Apr 15th, 2015, 06:46 PM
#7
Re: Italic and CAPITAL in one label
Here is a rough usercontrol that will paint in different colors and different fonts.
Code:
' Example code to set the flexlabel properties
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
With FlexLabel1
.Fonts.Add(New Font("Tahoma", 12, FontStyle.Bold))
.Fonts.Add(New Font("New Times Roman", 16, FontStyle.Italic))
.Fonts.Add(New Font("Microsoft Sans Serif", 12))
.Colors.Add(Color.Blue)
.Colors.Add(Color.Red)
.Colors.Add(Color.Green)
' Text containing @ tags that set color and font for each each segment defined by a forward slash character.
.EncodedText = "@C1/@F1/Good Morning/@C2/@F2/ Good Afternoon/@C3/@F3/ Good Evening"
End With
End Sub
End Class
Code:
Imports System.Drawing
Imports System.ComponentModel
Public Class FlexLabel
Public Property Colors As New List(Of Color)
Public Property Fonts As New List(Of Font)
Public Property RawText As String = ""
Private ColorIndex As Integer = 0
Private FontIndex As Integer = 0
Private _EncodedText As String = ""
Private _TextAlign As ContentAlignment = ContentAlignment.MiddleLeft
<Category("Alignment"), Description("Specifies the alignment of text.")> _
Public Property TextAlign() As ContentAlignment
Get
Return _TextAlign
End Get
Set(ByVal value As ContentAlignment)
_TextAlign = value
'Invalidate()
End Set
End Property
Public Property EncodedText() As String
Get
Return _EncodedText
End Get
Set(ByVal value As String)
_EncodedText = value
If _EncodedText <> "" Then
Dim Segs() As String = _EncodedText.Split("/"c)
RawText = ""
For Each Seg As String In Segs
If Seg.First <> "@" Then
RawText &= Seg
End If
Next
End If
End Set
End Property
Private Sub FlexLabel_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
If EncodedText = "" Then Exit Sub
Dim x As Integer = 0
Dim y As Integer = 0
Dim Segs() As String = EncodedText.Split("/"c)
With e.Graphics
For Each Seg As String In Segs
Dim Wt As Integer = CInt(.MeasureString(Seg, Fonts(FontIndex)).Width)
Dim Ht As Integer = CInt(.MeasureString(Seg, Fonts(FontIndex)).Height)
' Set Vert Justification
Select Case TextAlign
Case ContentAlignment.TopLeft, ContentAlignment.TopCenter, ContentAlignment.TopRight
y = 0
Case ContentAlignment.MiddleLeft, ContentAlignment.MiddleCenter, ContentAlignment.MiddleRight
y = CInt((Me.Height / 2) - (Ht / 2))
Case ContentAlignment.BottomLeft, ContentAlignment.BottomCenter, ContentAlignment.BottomRight
y = Me.Height - Ht
End Select
If Seg.StartsWith("@") Then
If Seg.Substring(1, 1) = "C" Then
ColorIndex = CInt(Seg.Substring(2))
ElseIf Seg.Substring(1, 1) = "F" Then
FontIndex = CInt(Seg.Substring(2))
End If
Else
.DrawString(Seg, Fonts(FontIndex), New SolidBrush(Colors(ColorIndex)), New Point(x, y))
x += CInt(.MeasureString(Seg, Fonts(FontIndex)).Width)
End If
Next
End With
End Sub
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Fonts.Add(Me.Font) ' Add base font at offset (0)
Colors.Add(Me.ForeColor) ' Add base Color as offset (0)
End Sub
End Class
Last edited by Gruff; Apr 15th, 2015 at 07:00 PM.
Burn the land and boil the sea
You can't take the sky from me
~T
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|