当前位置:编程学习 > C#/ASP.NET >>

“Graphics”是“命名空间”,但此处被当做“类型”来使用

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;



namespace Graphics
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
                
            Pen pen1 = new Pen(Color.Red);
            SolidBrush brush1 = new SolidBrush(Color.Blue);
            g.DrawEllipse(pen1, 10, 10, 100, 100);
            g.FillEllipse(brush1, 10, 10, 100, 100);
        }
    }
}

结果出现错误:
“Graphics”是“命名空间”,但此处被当做“类型”来使用 E:\Visual Studio\Graphics\Graphics\Form1.cs13 Graphics
--------------------编程问答-------------------- 你不应该用Graphics当你的namespace。 --------------------编程问答--------------------
引用 1 楼 healer_kx 的回复:
你不应该用Graphics当你的namespace。


+1

或者明确指定。
System.Drawing.Graphics g = this.CreateGraphics(); --------------------编程问答--------------------  我这里是VS2010 ,button1_Click 中的代码没问题啊。 --------------------编程问答-------------------- Graphics 是类
如果当作命名控件很容易出错
--------------------编程问答--------------------
引用 2 楼 wuyazhe 的回复:
引用 1 楼 healer_kx 的回复:
你不应该用Graphics当你的namespace。


+1

或者明确指定。
System.Drawing.Graphics g = this.CreateGraphics();

支持 --------------------编程问答-------------------- 学习          


回复内容太短了! 


--------------------编程问答-------------------- System.Drawing.Graphics g = this.CreateGraphics(); --------------------编程问答-------------------- 你的namespace Graphics和系统的System.Drawing.Graphics类型同名了,当然出错
1.改掉你的namespace名称
2.明确指定你所用的Graphics类型
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,