using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace Test02
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void button1_Click(object sender, EventArgs e)
        {
            Graphics ghs = this.CreateGraphics(); //创建Graphics对象
            for (int i = 1; i < 6; i++) //使用for循环
            {
                HatchStyle hs = (HatchStyle)(5 + i); //设置HatchStyle值
                HatchBrush hb = new HatchBrush(hs, Color.White); //实例化HatchBrush类
                Rectangle rtl = new Rectangle(10, 50 * i, 50 * i, 50); //根据i值绘制矩形
                ghs.FillRectangle(hb, rtl); //填充矩形
            }        }
    }
}麻烦问一下,这句“HatchStyle hs = (HatchStyle)(5 + i);”是什么意思啊?

解决方案 »

  1.   

    将5+i的值强制转换为 HashStyle
      

  2.   

    HatchStyle是个枚举,HatchStyle hs = (HatchStyle)(5 + i);就是将hs赋值为HashStyle中的第5+i个元素的值,假设i=1,那么hs就变成HatchStyle.DashedDownwardDiagonal了。
      

  3.   

    HatchStyle是个枚举,HatchStyle hs = (HatchStyle)(5 + i);就是将hs赋值为HashStyle中的第5+i个元素的值,假设i=1,那么hs就变成HatchStyle.DashedDownwardDiagonal了。
      

  4.   

    那么HashStyle中的第6、7、8、9、10个元素的值分别是什么啊?它是按什么排的啊?我看MSDN中,HatchStyle的枚举成员有很多啊,Horizontal、Vertical、ForwardDiagonal、BackwardDiagonal、Cross、DiagonalCross、Percent05、Percent10等等
      

  5.   

    拆箱为HatchStyle类型,也就是强制转换
    还可以用as:HatchStyle hs=(5+i) as HatchStyle; 
      

  6.   

    有谁知道HashStyle枚举中的第6、7、8、9、10个元素的值分别是什么啊?它的枚举值是个什么排法呀?