Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 18th, 2003, 07:22 PM
Sas Sas is offline
Registered User
 
Join Date: Oct 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Form Color In VB.NET

Just started coding in VB.NET and created a small app; click a button and the form changes color. If the form is red it changes to blue; if the form is blue it changes to red.

In the click event I placed this code:

If Me.Backcolor = Color.Red Then
   Me.Backcolor = Color.Blue
Else
   Me.Backcolor = Color.Red
End If

In the IF statement I'm getting the error:

"Operator '=' not defined for types System.Drawing.Color"

Any help would be appreciated. Many thanks in advance...

Sas :)

 
Old October 19th, 2003, 03:47 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You can use the Equals method off the Color class to find out whether the BackColor is of a specific color:

If Me.BackColor.Equals(Color.Red) Then
  Me.BackColor = Color.Blue
Else
  Me.BackColor = Color.Red
End If

This will compare the Color of the Background of the Form with Color.Red and return true if the two are of the same color.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old October 20th, 2003, 01:08 PM
Sas Sas is offline
Registered User
 
Join Date: Oct 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much for the solution Imar!

 
Old October 27th, 2004, 12:35 PM
Registered User
 
Join Date: Oct 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to jhax Send a message via MSN to jhax
Default

Thanks alot that code is great.

~#1586;#294;#1076;#65272;~





Similar Threads
Thread Thread Starter Forum Replies Last Post
how data grid of vb.net add cell color Nuwang Forum and Wrox.com Feedback 0 September 10th, 2008 08:36 PM
how to set a form as startup form in vb.net 2.0 mallikalapati .NET Framework 2.0 1 February 21st, 2008 09:19 AM
change row color of DataGrid in VB.Net (Windows ap remya1000 .NET Framework 1.x 2 December 31st, 2007 03:56 AM
Datagrid row color changing - windows vb.net app badgolfer VS.NET 2002/2003 7 April 18th, 2007 02:32 PM
Urgent VB form Migration to VB.net form kvenkat_2k1 Pro VB.NET 2002/2003 1 December 7th, 2005 04:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.