DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2004
    Posts
    20

    .NET newbie ques.

    I am starting to switch from VB6 to .NET and I can't change a form'2 backcolor using code. For example using a button's click event, what would you do. VB6 was Form1.backcolor = vbgreen

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    If you view the code for your form, you'll see a collapsed region labeled, "Windows Form Designer generated code." Expand that region, and you can see the code .NET uses to initialize your form. If you use the Properties window to set the form's BackColor to green, then examine the generated code, you'll find this line:

    Me.BackColor = System.Drawing.Color.Green

    That's exactly what you would put in your button's Click event to change the BackColor at runtime.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Oct 2004
    Posts
    20
    When I do that everything turns green, even the button, why?

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Interesting! I'd never noticed that before. Look up BackColor in VB.NET's online help. Notice:
    The BackColor property is an ambient property. An ambient property is a control property that, if not set, is retrieved from the parent control. For example, a Button will have the same BackColor as its parent Form by default.
    So, can you figure out what you need to do in order to prevent the button's BackColor changing when you change the form's BackColor?
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  5. #5
    Join Date
    Oct 2004
    Posts
    20
    I found out in a book that unless you specifically assign a collor to a control, it will take the color of the form it is attached to.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links