Results 1 to 7 of 7

Thread: Italic and CAPITAL in one label

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2015
    Posts
    2

    Smile Italic and CAPITAL in one label

    HI

    i need to get text1.text in Italic and author.text in CAPITAL to Label1.text

    Name:  Untitled.jpg
Views: 178
Size:  17.3 KB

    please explain me how to do it.

    Thanks

  2. #2
    Junior Member
    Join Date
    Jan 2014
    Location
    Athens, Greece
    Posts
    30

    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2015
    Posts
    2

    Re: Italic and CAPITAL in one label

    Quote Originally Posted by vangos View Post
    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

  4. #4
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    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

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,966

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,712

    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

  7. #7
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: Italic and CAPITAL in one label

    Here is a rough usercontrol that will paint in different colors and different fonts.

    Name:  MultiColorAndFontLabel.jpg
Views: 35
Size:  12.5 KB
    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
  •  



Click Here to Expand Forum to Full Width