日期:2014-05-18  浏览次数:20817 次

C#中的 Style的一个小问题
public partial class Form1 : Form
  {
  //自定义的变量,用来记录当前选择的图形
  Style style = Style.Line;//Style这里提示错误,
   
 ……
  }

编译背景:
我是在以前的书上看到的一个例子
是C#2.0的
vs2010

错误提示:
错误1 未能找到类型或命名空间名称“Style”(是否缺少 using 指令或程序集引用?)

已有命名空间:

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;
using System.Windows ;



------解决方案--------------------
using System.Web.UI.WebControls;得引入这个命名空间
------解决方案--------------------
用对象浏览器查了下,没有单独的Style类;
从LZ的注释来看,Style 我估计是自定义的一个枚举,像这样的
enum Style {
Line,Circle,Rectangle };

------解决方案--------------------
web中可以这样用

 Style style = new Style();
 style.BackColor = Color.Blue;
 this.Header.StyleSheet.CreateStyleRule(style, null, "body");

设置样式的。


------解决方案--------------------
不管是winform,webform都可以这样
C# code

 Style s = new Style();
 s.BackColor = Color.Red;