Jump to content
  • Advertisement
Sign in to follow this  
atoi

[MDX] 'Color' property and out of context

This topic is 4676 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For some reason, it claims that the property color is out of the current context.
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace DirectX_Application
{
    public class Game : System.Windows.Forms.Form
    {
        private Device device;

        protected void Render()
        {
            device.Clear(ClearFlags.Target, Color.Blue, 1, 0);
        }

        
        protected bool InitializeGraphics()
        {
            PresentParameters pres = new PresentParameters();
            pres.Windowed = true;
            pres.SwapEffect = SwapEffect.Discard;

            device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, pres);
            return true;
        }

        static void Main()
        {
            Game app = new Game();
            app.InitializeGraphics();
            app.Show();
            while (app.Created)
            {
                //app.Render();
                Application.DoEvents();
            }
            //app.DisposeGraphics();
        }
    }
}

Error	1	The name 'Color' does not exist in the current context	C:\Documents and Settings\HP_Administrator\Local Settings\Application Data\Temporary Projects\DirectX Application\Program.cs	15	45	DirectX_Application

Regards, Mike

Share this post


Link to post
Share on other sites
Advertisement
That's because the Color class resides in the System.Drawing namespace, which you haven't imported in this file. You should either use the full class name System.Drawing.Color, or you should add a using System.Drawing; clause at the top of your file. Since some classes in System.Drawing have the same name as DirectX ones (not sure, thought so), the first option, specifying the full class name, is probably the wisest to avoid conflicts.

If you need the System.Drawing namespace a lot, you can save yourself some typing by redefining its name with an extended using clause, by adding using Draw = System.Drawing; instead of the normal using clause. For Draw you can substitute any shorthand name you like. With this using clause at the beginning of your file, you can reference System.Drawing.Color with the shorthand version Draw.Color instead of its full name.

Share this post


Link to post
Share on other sites
Fantastic reply Remigius.
Cannot state it better myself. Atoi, I am sure you will find value in remigius' reply.

Share this post


Link to post
Share on other sites
Thank you very much for that reply, It actually showed me something i wasn't aware in c# as well as how to fix my problem. Thank you very much for that.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!