Results 1 to 3 of 3

Thread: Changing the colour of Text

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2010
    Posts
    33

    Changing the colour of Text

    hey i am using vb 2008, and i am trying 2 code a button that will change the colour of the font that is being entered. I want it to open a dialog box so i can choose the colour.. any help would be appreciated.

  2. #2
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    Re: Changing the colour of Text

    Using a form, ColorDialog, 2 buttons and a text box. How I do it.

    Code:
    Public Class frmColorDialog
        ' declare variables to hold color values
        Dim intRed As Integer
        Dim intGreen As Integer
        Dim intBlue As Integer
        Dim intAlpha As Integer
    
        Private Sub btnChangeColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChangeColor.Click
            With ColorDialog1
                .ShowDialog()
                intRed = .Color.R
                intGreen = .Color.G
                intBlue = .Color.B
                intAlpha = .Color.A
                txtCurrentColor.ForeColor = Color.FromArgb(intAlpha, intRed, intGreen, intBlue)
            End With
        End Sub
    
        Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
            Me.Close()
        End Sub
    End Class
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  3. #3
    Junior Member
    Join Date
    Jul 2010
    Posts
    19

    Re: Changing the colour of Text

    vb Code:
    1. Public ColorChosen As Color
    2.  Public ColorChose As String = ColorChosen.ToArgb
    3.  
    4. Private Sub ColorButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorButton.Click
    5.  
    6.         ColorChosen = Me.ColorDialog1.Color
    7.         ColorChose = ColorChosen.ToArgb
    8.         TextBox1.ForeColor = ColorChosen
    9.         ColorDialog1.Dispose()
    10.     End Sub

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