Solved

Button Text

Posted on 2004-09-15
16
223 Views
Last Modified: 2010-04-23
Hello,

Here is the scenario.  I am trying to make a buttton that functions like an aircraft switch/light.  The actuall switch has two lines of text that light up independently.  Is there any way I can simulate this on a regular button?  I tried adding a label but of course I lose the animation of the button click.  I tried adding another button to the button but that didnt look right either.  I need to be able to have two lines of text that can be highlighted different colors.  Any ideas?!?  Thanks in advance for your help!!
0
Comment
Question by:anitahelp
  • 5
  • 4
  • 4
  • +2
16 Comments
 
LVL 5

Expert Comment

by:tzxie2000
ID: 12064233
firstly
you can use two label

and write the click action in mouseup event
0
 
LVL 19

Expert Comment

by:Desp
ID: 12064234
can you post/upload the picture somewhere of what you want to acheive?
0
 
LVL 5

Expert Comment

by:tzxie2000
ID: 12064316
you can also double click the label in IDE
then you will find label also has click event
0
 

Author Comment

by:anitahelp
ID: 12064363
tzxie2000:
Mouse up for the label?  Does this somehow need to call the mouse up event of the button?

Desp:
Unfortunately I can't post a picture but it is basically as I stated, example:  Button, line one text = "LAND" line two text = "SEA".  Push the button once and the line one text becomes highlighted, push the button again and both become highlighted, once more and line one turns off and line two is highlighted.
0
 
LVL 5

Expert Comment

by:tzxie2000
ID: 12064384
I just found that label also have click event

you can also double click the label in IDE
then you will find label also has click event


0
 

Author Comment

by:anitahelp
ID: 12064387
I understand that a label has a click event, problem is that you don't have the animation of the button being pressed.
0
 
LVL 19

Expert Comment

by:Desp
ID: 12064530
How about having three icons in the same button and use the Image Property of the button to the set appropriate icons stored in an imagelist
0
 
LVL 5

Expert Comment

by:tzxie2000
ID: 12064574
how about write this in your button paint event

 Private Sub Button1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Button1.Paint
        Dim g As Graphics = e.Graphics
        Dim f As Font = New Font("Arial", 8)

        g.DrawString("run", f, System.Drawing.Brushes.Blue, 0, 0)
        g.DrawString("stop", f, System.Drawing.Brushes.Red, 0, 8)

    End Sub
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:anitahelp
ID: 12064591
The problem i see with that is the fact that I have a number of these switch lights and they all have different text.  I would need hundreds of images contained within lists.  It is a possibility but since it is text I would prefer to build some sort of control so that I can just set the text properties based on the received values.
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12064682
Try this

call like this

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim f As New mybutton
        f.Text = "hallo"
        f.text2 = "hallo2"
        f.Height = 40
        f.Width = 100
        f.Top = 100
        f.Left = 100
        f.TextBackcolor1 = Color.Red
        f.TextBackcolor2 = Color.Blue
        AddHandler f.Click, AddressOf Myclick
        Me.Controls.Add(f)
end sub

Private Sub MyClick(ByVal sender As Object, ByVal e As System.EventArgs)
        CType(sender, mybutton).OnOff = Not CType(sender, mybutton).OnOff
        CType(sender, mybutton).Invalidate()
    End Sub


Public Class mybutton
    Inherits Button
    Dim _text2 As String
    Dim _textbackcolor1 As Color
    Dim _textbackcolor2 As Color
    Dim _ONOFF As Boolean = True

    Public Property OnOff() As Boolean
        Get
            Return _ONOFF
        End Get
        Set(ByVal Value As Boolean)
            _ONOFF = Value
        End Set
    End Property

    Public Property text2() As String
        Get
            Return _text2
        End Get
        Set(ByVal Value As String)
            _text2 = Value
        End Set
    End Property

    Public Property TextBackcolor1() As Color
        Get
            Return _textbackcolor1
        End Get
        Set(ByVal Value As Color)
            _textbackcolor1 = Value
        End Set
    End Property

    Public Property TextBackcolor2() As Color
        Get
            Return _textbackcolor2
        End Get
        Set(ByVal Value As Color)
            _textbackcolor2 = Value
        End Set
    End Property

    Protected Overrides Sub OnPaint(ByVal pevent As System.Windows.Forms.PaintEventArgs)

        MyBase.OnPaint(pevent)
        Dim textheight As SizeF = pevent.Graphics.MeasureString(Me.Text, Me.Font)
        If ONOFF Then
            pevent.Graphics.FillRectangle(New SolidBrush(TextBackcolor1), 4, 4, Me.Width - 8, textheight.Height)
            pevent.Graphics.FillRectangle(New SolidBrush(Me.BackColor), 4, textheight.Height + 4, Me.Width - 8, Me.Height - textheight.Height - 10)
        Else
            pevent.Graphics.FillRectangle(New SolidBrush(Me.BackColor), 4, 4, Me.Width - 8, textheight.Height)
            pevent.Graphics.FillRectangle(New SolidBrush(TextBackcolor2), 4, textheight.Height + 4, Me.Width - 8, Me.Height - textheight.Height - 10)
        End If
        pevent.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Color.Black), 4, 4)
        pevent.Graphics.DrawString(Me.text2, Me.Font, New SolidBrush(Color.Black), 4, Me.Height - textheight.Height - 8)

    End Sub


End Class
0
 
LVL 42

Expert Comment

by:frodoman
ID: 12064743
Why not just use a normal button and change the text based on it's current value?

        If Me.Text = "air" Then
            Me.Text = "sea"
            Me.ForeColor = Color.Blue
        Else
             If Me.Text = "sea" Then
                   ....
             End If
        End If
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12064797
if you just want the front color of the text change color then change to

Protected Overrides Sub OnPaint(ByVal pevent As System.Windows.Forms.PaintEventArgs)

        MyBase.OnPaint(pevent)
        Dim textheight As SizeF = pevent.Graphics.MeasureString(Me.Text, Me.Font)
        pevent.Graphics.FillRectangle(New SolidBrush(Me.BackColor), 4, 4, Me.Width - 8, Me.Height - 8)
        If OnOff Then
            pevent.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(TextBackcolor1), 4, 4)
            pevent.Graphics.DrawString(Me.text2, Me.Font, New SolidBrush(Color.Black), 4, Me.Height - textheight.Height - 8)
        Else
            pevent.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Color.Black), 4, 4)
            pevent.Graphics.DrawString(Me.text2, Me.Font, New SolidBrush(TextBackcolor2), 4, Me.Height - textheight.Height - 8)
        End If


    End Sub
0
 

Author Comment

by:anitahelp
ID: 12064911
RonaldBiemans,

That works great, I wish that it would appear as if the text is being depressed with the switch though.  (while the buttton gives the effect that it is being pressed down the text doesn't move).
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12064993
I'll see what I can do, just a moment
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 500 total points
ID: 12065121
this should do it

Public Class mybutton
    Inherits Button
    Dim _text2 As String
    Dim _textbackcolor1 As Color
    Dim _textbackcolor2 As Color
    Dim _ONOFF As Boolean = True
    Dim tclick As Boolean = False

    Public Property OnOff() As Boolean
        Get
            Return _ONOFF
        End Get
        Set(ByVal Value As Boolean)
            _ONOFF = Value
        End Set
    End Property

    Public Property text2() As String
        Get
            Return _text2
        End Get
        Set(ByVal Value As String)
            _text2 = Value
        End Set
    End Property

    Public Property TextBackcolor1() As Color
        Get
            Return _textbackcolor1
        End Get
        Set(ByVal Value As Color)
            _textbackcolor1 = Value
        End Set
    End Property

    Public Property TextBackcolor2() As Color
        Get
            Return _textbackcolor2
        End Get
        Set(ByVal Value As Color)
            _textbackcolor2 = Value
        End Set
    End Property

    Protected Overrides Sub OnPaint(ByVal pevent As System.Windows.Forms.PaintEventArgs)

        MyBase.OnPaint(pevent)
        Dim textheight As SizeF = pevent.Graphics.MeasureString(Me.Text, Me.Font)

        pevent.Graphics.FillRectangle(New SolidBrush(Me.BackColor), 4, 4, Me.Width - 8, Me.Height - 8)
        If tclick Then
            If OnOff Then
                pevent.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(TextBackcolor1), 5, 5)
                pevent.Graphics.DrawString(Me.text2, Me.Font, New SolidBrush(Color.Black), 5, Me.Height - textheight.Height - 7)
            Else
                pevent.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Color.Black), 5, 5)
                pevent.Graphics.DrawString(Me.text2, Me.Font, New SolidBrush(TextBackcolor2), 5, Me.Height - textheight.Height - 7)
            End If
        Else
            If OnOff Then
                pevent.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(TextBackcolor1), 4, 4)
                pevent.Graphics.DrawString(Me.text2, Me.Font, New SolidBrush(Color.Black), 4, Me.Height - textheight.Height - 8)
            Else
                pevent.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Color.Black), 4, 4)
                pevent.Graphics.DrawString(Me.text2, Me.Font, New SolidBrush(TextBackcolor2), 4, Me.Height - textheight.Height - 8)
            End If
        End If
        tclick = True

    End Sub

    Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
        tclick = False
        MyBase.OnClick(e)
    End Sub
End Class
0
 

Author Comment

by:anitahelp
ID: 12065264
Works like a charm!  Thanks for your time and effort, I truely appreciate it!!!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now