えムナウのプログラミングのページ

えムナウ の とどけもの

 Logo えムナウBlog@AILight
えムナウBlog@Wankuma

目次

利用状況

イメージ ギャラリー

カテゴリ

Links
 

inetaj

MSMVPロゴ
MSMVP Visual C# 2005/01-2007/12
HitTest.cs ヒットテスト種別・ヒットテスト情報クラスです。

using System;
using System.ComponentModel;

namespace SpreadControl
{
        #region ヒットテスト種別
        [Serializable]
        [TypeConverter(typeof(HitTestTypeConverter))]
        public enum HitTestType 
        {
                None = 0 ,
                Cell = 1
        }
        internal class HitTestTypeConverter : ExpandableObjectConverter 
        {
                public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) 
                {
                        if (destinationType == typeof(string)) return true;
                        return base.CanConvertTo(context, destinationType);
                }
                public override object ConvertTo(ITypeDescriptorContext context, 
                        System.Globalization.CultureInfo culture, object value, Type destType) 
                {
                        if (destType == typeof(string) && value is HitTestType) 
                        {
                                HitTestType ic = (HitTestType)value;
                                switch ( ic )
                                {
                                        case HitTestType.None: return "None" ;
                                        case HitTestType.Cell: return "Cell" ;
                                }
                                return "" ;
                        }
                        return base.ConvertTo(context, culture, value, destType);
                }   
        }
        #endregion

        #region ヒットテスト情報
        [Serializable]
        [TypeConverter(typeof(HitTestInfoConverter))]
        public class HitTestInfo
        {
                private int _column ;
                private int _row ;
                private HitTestType _type ;
                public static readonly HitTestInfo Nowhere = new HitTestInfo() ;

                public HitTestInfo()
                {
                        _column = -1 ;
                        _row = -1 ;
                        _type = HitTestType.None ;
                }

                public HitTestInfo(int column, int row, HitTestType type)
                {
                        _column = column ;
                        _row = row ;
                        _type = type ;
                }
                public int Column               { get { return _column ; } }
                public int Row                  { get { return _row ; } }
                public HitTestType Type { get { return _type ; } }
        }
        internal class HitTestInfoConverter : ExpandableObjectConverter 
        {
                public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) 
                {
                        if (destinationType == typeof(string)) return true;
                        return base.CanConvertTo(context, destinationType);
                }
                public override object ConvertTo(ITypeDescriptorContext context, 
                        System.Globalization.CultureInfo culture, object value, Type destType) 
                {
                        if (destType == typeof(string) && value is HitTestInfo) 
                        {
                                HitTestInfo ic = (HitTestInfo)value;
                                return ic.Column.ToString() + "," + ic.Row.ToString() + "," + ic.Type.ToString() ;
                        }
                        return base.ConvertTo(context, culture, value, destType);
                }   
        }
        #endregion
}