|
-
Jan 28th, 2007, 06:38 AM
#1
Thread Starter
Junior Member
[2005] testing colors in VB
Hi - newbie to VB - am using Textboxes to dispolay text and have the textboxes colored yellow, white and red depending upon their designation. I want to use the double-click event processing of the textboxes (using event handler) and take different actions depending upon the color of the textbox. I set the color as shown (this works OK):
TextBox1.BackColor = Color.Yellow
I attemp to test the color with the following (this does not work)
if TextBox1.BackColor = Color.Yellow then
' do something'
end if
if TextBox1.BackColor = Color.Red then
' do something else'
end if
This creates an error and does not work and I have not been able to find the way to test this and take appropriate action. Help would be appreciated in the way to test the BackColor existing and take action depending on what this color is.
Thanks and cheers
Ross
-
Jan 28th, 2007, 08:23 AM
#2
Re: [2005] testing colors in VB
use the .Equals method like this ...
VB Code:
[COLOR=Blue]Private Sub[/COLOR] Form1_Load([COLOR=Blue]ByVal[/COLOR] sender [COLOR=Blue]As[/COLOR] System.Object, [COLOR=Blue]ByVal[/COLOR] e [COLOR=Blue]As[/COLOR] System.EventArgs) [COLOR=Blue]Handles[/COLOR] MyBase.Load
TextBox1.BackColor = Color.Yellow
[COLOR=Blue]End Sub[/COLOR]
[COLOR=Blue]Private Sub[/COLOR] TextBox1_DoubleClick([COLOR=Blue]ByVal[/COLOR] sender [COLOR=Blue]As[/COLOR] [COLOR=Blue]Object[/COLOR], [COLOR=Blue]ByVal[/COLOR] e [COLOR=Blue]As[/COLOR] System.EventArgs) [COLOR=Blue]Handles[/COLOR] TextBox1.DoubleClick
[COLOR=Blue]If[/COLOR] TextBox1.BackColor.[B]Equals[/B](Color.Yellow) [COLOR=Blue]Then[/COLOR]
MessageBox.Show([COLOR=Purple]"yellow!"[/COLOR])
[COLOR=Blue]ElseIf[/COLOR] TextBox1.BackColor.[B]Equals[/B](Color.Red) [COLOR=Blue]Then[/COLOR]
MessageBox.Show([COLOR=Purple]"red!"[/COLOR])
[COLOR=Blue]End If[/COLOR]
End Sub
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Jan 28th, 2007, 09:22 AM
#3
Re: [2005] testing colors in VB
 Originally Posted by Ross007
Hi - newbie to VB - am using Textboxes to dispolay text and have the textboxes colored yellow, white and red depending upon their designation. I want to use the double-click event processing of the textboxes (using event handler) and take different actions depending upon the color of the textbox. I set the color as shown (this works OK):
TextBox1.BackColor = Color.Yellow
I attemp to test the color with the following (this does not work)
if TextBox1.BackColor = Color.Yellow then
' do something'
end if
if TextBox1.BackColor = Color.Red then
' do something else'
end if
This creates an error and does not work and I have not been able to find the way to test this and take appropriate action. Help would be appreciated in the way to test the BackColor existing and take action depending on what this color is.
Thanks and cheers
Ross
Hi,
You could do something like this also;
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.BackColor = Color.Yellow Then
' do something'
MsgBox("Yellow")
End If
If TextBox1.BackColor = Color.Red Then
' do something else'
MsgBox("Red")
End If
End Sub
Change the color of yout textbox with another button and see the result.
Wkr,
sparrow1
-
Jan 28th, 2007, 10:59 AM
#4
Member
Re: [2005] testing colors in VB
-
Jan 28th, 2007, 02:00 PM
#5
Thread Starter
Junior Member
Re: [2005] testing colors in VB
-
Jan 28th, 2007, 04:11 PM
#6
Re: [2005] testing colors in VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.BackColor = Color.Yellow Then
' do something'
MsgBox("Yellow")
End If
If TextBox1.BackColor = Color.Red Then
' do something else'
MsgBox("Red")
End If
End Sub
could be:
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Select Case TextBox1.BackColor
Case Colors.Yellow
'Yellow color code
Case Colors.Red
'Red Color code
End Select
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|