?
Solved

Button Text

Posted on 2004-09-15
16
Medium Priority
?
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:Fahad Mukhtar
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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:Fahad Mukhtar
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
 

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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month12 days, 9 hours left to enroll

777 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