积木首页 | 500多种网页特效 | 函数手册 | 广播电台 | 高清晰图片素材 | 服务器合租 | 万年历 | 网友最新浏览记录
程序开发 网页设计 搜索引擎 特效代码 操作系统 防范病毒 黑客技术 图形图象 电脑硬件 网络技术 服 务 器 数 据 库 网文精粹
您的位置:积木首页 >> 程序开发频道 >> .NET >> 正文:
标题:.Net Framework3.0 实践纪实(4)
时间:2006-8-15 来源:本站原创 浏览数:
可视对象和棋子
任务1.6的实现和画棋纵横线没有很大的差别,设置好字体、要显示的坐标的文字,然后调用DrawingContext的DrawText方法在指定的位置画出对象即可。为了满足任务中的要求,我们设置一个开关字段和对应的属性,代码如下:
   public partial class BoardControl : Canvas
    {
        double scale = 0.03;
        readonly int[,] demarkCount ={ { 2, 3 }, { 3, 3 }, { 3, 4 }, { 3, 5 }, { 3, 6 } };
        bool showCoordinate = true;
        Brush coordinateColor = Brushes.White;
 
       ……
 
        public bool ShowCoordinate
        {
            get { return showCoordinate; }
            set
            {
                if (showCoordinate != value)
                {
                    showCoordinate = value;
                    InvalidateVisual();
                }
            }
        }
 
……..
        protected override void OnRender(DrawingContext dc)
        {
           ……
            if (showCoordinate)
            {
                double fontSize = 0.4;
 
                for (int i = 1; i <= BoardSize; i++)
                {
                    FormattedText fmtText = new FormattedText(i.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), fontSize, coordinateColor);
                    fmtText.TextAlignment = TextAlignment.Right;
                    dc.DrawText(fmtText, new Point(-0.5, (i - 1 - fmtText.Height * .5)));
                    fmtText =new FormattedText(((char)(i + 64)).ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), fontSize, coordinateColor);
                    fmtText.TextAlignment = TextAlignment.Center;
                    dc.DrawText(fmtText, new Point(i - 1, BoardSize - 0.5));
                }
            }
        }
……
编译运行。为了测试显示隐藏坐标的功能,切换到MainWindow的Xaml方式,插入如下代码:
      <StackPanelGrid.Row="1"Grid.Column="0"Orientation="Vertical"Margin="10">
        ……
                <CheckBoxName="coordinateCheckBox"Click="ShowCoordinateClick"IsChec

[1] [2] [3] [4] [5] [6] 下一页


(责任编辑:笑虎)
关于本站 | 广告服务 | 联系我们 | 版权申明 | 强强联盟 | 投稿热线 | 网站地图 | 申请链接
Copyright ©2005-2006 Gimoo.net All rights reserved. 积木网 版权所有
E-mail:gimoohr@gmail.com 京ICP备05050695号