• (深入.Net平台和C#编程)第六章.简答题5.20170410


    -------------------------------------------父类形状类-------------------------------------------

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Drawing;
     4 using System.Linq;
     5 using System.Text;
     6 using System.Threading.Tasks;
     7 
     8 namespace J4.entity
     9 {
    10     public class Shape
    11     {
    12         public virtual void Draw(Graphics g, Pen p)
    13         {
    14         }
    15     }
    16 }
    Shape

    -------------------------------------------子类圆形类-------------------------------------------

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Drawing;
     4 using System.Linq;
     5 using System.Text;
     6 using System.Threading.Tasks;
     7 
     8 namespace J4.entity
     9 {
    10     public class Circle:Shape
    11     {
    12         public override void Draw(Graphics g, Pen p)
    13         {
    14             g.DrawEllipse(p, 75,150,100,100);
    15         }
    16 
    17       
    18     }
    19 }
    Circle

    -------------------------------------------子类矩形类-------------------------------------------

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Drawing;
     4 using System.Linq;
     5 using System.Text;
     6 using System.Threading.Tasks;
     7 
     8 namespace J4.entity
     9 {
    10    public class Rect:Shape
    11     {
    12        public override void Draw(Graphics g, Pen p)
    13        {
    14            Rectangle rec = new Rectangle(20, 100, 200, 200);
    15            g.DrawRectangle(p, rec);
    16        }
    17     }
    18 }
    Rect

    -------------------------------------------主窗体类-------------------------------------------

     1 using J4.entity;
     2 using System;
     3 using System.Collections.Generic;
     4 using System.ComponentModel;
     5 using System.Data;
     6 using System.Drawing;
     7 using System.Linq;
     8 using System.Text;
     9 using System.Threading.Tasks;
    10 using System.Windows.Forms;
    11 
    12 namespace J4
    13 {
    14     public partial class frmMain : Form
    15     {
    16         public frmMain()
    17         {
    18             InitializeComponent();
    19         }
    20 
    21         private void btnDraw_Click(object sender, EventArgs e)
    22         {
    23             //Graphics g = CreateGraphics();
    24             ////(颜色,厚度)
    25             //Pen p = new Pen(Color.Red,3);
    26             ////(X轴坐标,Y轴坐标,宽,高)
    27             //Rectangle rec = new Rectangle(50,100,200,200);
    28             ////矩形
    29             //g.DrawRectangle(p,rec);
    30             ////圆形
    31             //g.DrawEllipse(p,50,100,100,100);
    32 
    33 
    34 
    35             Shape shape = new Shape();
    36             Graphics g = this.panel1.CreateGraphics();
    37             //默认红色
    38             Pen p = new Pen(Color.Red, 3);
    39 
    40             //判断选中的是什么形状
    41             if (rbtnCircle.Checked == true)
    42             {
    43                 shape = new Circle();
    44             }
    45             else
    46             {
    47                 shape = new Rect();
    48             }
    49             //判断选中的是什么颜色
    50             if (rbtnBlue.Checked == true)
    51             {
    52                 p = new Pen(Color.Blue, 3);
    53             }
    54             else if (rbtnYellow.Checked == true)
    55             {
    56                 p = new Pen(Color.Yellow, 3);
    57             }
    58             //调用方法
    59             shape.Draw(g,p);
    60             
    61         }
    62 
    63         private void panel1_Paint(object sender, PaintEventArgs e)
    64         {
    65         }
    66     }
    67 }
    frmMain
  • 相关阅读:
    【ASP.NET 插件】zyUpload的HTML5上传插件
    【软件】图文解释XCode常用快捷键的使用
    【软件使用】Windows下的Objective-C集成开发环境搭建(IDE)
    【Javascript Demo】移动端访问PC端网页时跳转到对应的移动端网页
    【网络文摘】30多年程序员生涯经验总结
    【算法】网上看到的5个问题
    【ASP.NET 进阶】定时执行任务
    【ASP.NET 基础】Page类和回调技术
    【ASP.NET 基础】表单和控件
    【ASP.NET 基础】ASP.NET内置对象
  • 原文地址:https://www.cnblogs.com/1-2-3-4/p/6691473.html
Copyright © 2020-2023  润新知