It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

How should I call the rgb value of a window's Me.BackColor?

Moderator: dafunkymunky

How should I call the rgb value of a window's Me.BackColor?

Postby photoelectricgeek on Mon Mar 21, 2011 10:04 pm

Untitled.png

I'm learning Visual Basic and this is a practice program per say.
It has three textboxes which are open to user-input and denote the R, G, and B values of Me.BackColor

I got most of the code from a tutorial but I had ideas that weren't there and was curious as to how I would implement one specifically. I want to have a label or read-only textbox(whichever's best) that dynamically displays the value of Me.BackColor

How would I set up a variable or array that contains the integer form of that rgb value?
(My intent is to also use that variable so that whenever someone click the "color" button without anything in the textboxes, my if statement can dynamically call what the background color was and return to it instead of a set rgb value like it is now...
If you have any better ideas for my first if statement they'd be greatly appreciated.)

Code: Select all
Public Class Form1

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then ' if the text boxes are empty at click
            MsgBox("Please enter a value between 0 and 255")
            TextBox1.Text = 255
            TextBox2.Text = 255
            TextBox3.Text = 255
        End If

        Dim rgb1, rgb2, rgb3 As Integer
        rgb1 = TextBox1.Text
        rgb2 = TextBox2.Text
        rgb3 = TextBox3.Text

        If rgb1 > 255 Or rgb2 > 255 Or rgb3 > 255 Or rgb1 < 0 Or rgb2 < 0 Or rgb3 < 0 Then
            MsgBox("Please enter a value between 0 and 255")
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
        Else
            Me.BackColor = Color.FromArgb(rgb1, rgb2, rgb3)
        End If

    End Sub

End Class
You do not have the required permissions to view the files attached to this post.
photoelectricgeek
 
Posts: 1
Joined: Mon Mar 21, 2011 9:42 pm

Who is online

Users browsing this forum: No registered users and 2 guests