Results 1 to 11 of 11

Thread: Highlight Text by command click or in list index

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    104

    Highlight Text by command click or in list index

    I want to make a list box and select an index to HighLight a specific part or whole Text or Label, But I don't know how to code for HighLight. Please help me!

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,734

    Re: Highlight Text by command click or in list index

    To highlight a piece of text in a TextBox use the .SelStart and .SelLenght properties
    You can't highlight pieces of a text in a Label control

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    104

    Re: Highlight Text by command click or in list index

    Many Thanks Dear #Arnoutdy !

  4. #4
    Lively Member
    Join Date
    Feb 2008
    Posts
    69

    Re: Highlight Text by command click or in list index

    You can highlight whole or part of any text in a label

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    104

    Re: Highlight Text by command click or in list index

    I found something easy

    ---------------
    If List1.ListIndex = 0 Then
    With Label1
    .Visible = True
    .Width = 3000
    .Height = 1500
    .Left = 2100
    .Top = 60
    End With
    Label2.Visible = False
    ElseIf List1.ListIndex = 1 Then
    With Label2
    .Visible = True
    .Width = 3000
    .Height = 1500
    .Left = 2100
    .Top = 60
    End With
    Label1.Visible = False
    End If
    End Sub
    ------------------

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: Highlight Text by command click or in list index

    Quote Originally Posted by On Error Try Again View Post
    You can highlight whole or part of any text in a label
    Example please......

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    104

    Re: Highlight Text by command click or in list index

    Private Sub List1_Click()
    On Error Resume Next
    If List1.ListIndex = 0 Then
    With Label1
    .Visible = True
    .Width = 3000
    .Height = 1500
    .Left = 2100
    .Top = 60
    End With
    Text1.Text = "Bleeding time is a laboratory test to assess platelet function and the body’s ability to form a clot. The test involves making a puncture wound in a superficial area of the skin and monitoring "
    Text1.SetFocus
    Text1.SelStart = 14
    Text1.SelLength = Len(Text1.Text) - 122
    Label2.Visible = False
    ElseIf List1.ListIndex = 1 Then
    With Label2
    .Visible = True
    .Width = 3000
    .Height = 1500
    .Left = 2100
    .Top = 60
    End With
    Text1.Text = "Bleeding time is a laboratory test to assess platelet function and the body’s ability to form a clot. The test involves making a puncture wound in a superficial area of the skin and monitoring "
    Text1.SetFocus
    Text1.SelStart = 85
    Text1.SelLength = Len(Text1.Text) - 118
    Label1.Visible = False
    End If


    End Sub

  8. #8
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: Highlight Text by command click or in list index

    So, MKP, how does your code highlight part of the caption (you called it text) of a label. Your code does nothing except sets basic stuff for your labels, but does nothing with their captions.

    Still waiting on "On Error Try Again"'s answer to my question in post #6.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    104

    Re: Highlight Text by command click or in list index

    when you click (listIndex=0) text1 will foucs a part of text not all of text and highlights that part, and when you click (listIndex=1) it will select and highlight another part.

  10. #10
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: Highlight Text by command click or in list index

    BUT NOT LABELS! At least YOUR code doesn't highlight a portion of the text (.caption) of your labels.
    So, never mind, guess I have no idea what you are trying to do with labels anyway...adios.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    104

    Re: Highlight Text by command click or in list index

    Yes, I tried to highlight a part of label, but i couldn't do it.

Tags for this Thread

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