C#编程:完成图示程序:通过字体菜单选择字体,通过颜色菜单选择颜色,在窗体中画图并输出文字说明。

这篇博客介绍了一款使用C#编程实现的图形界面应用,用户可以通过字体菜单选择字体,颜色菜单选择颜色,然后在窗口中进行画线和画圆操作,并能添加文字说明。程序提供了丰富的交互功能,便于用户进行图形创作。

完成图示程序:通过字体菜单选择字体,通过颜色菜单选择颜色,在窗体中画图并输出文字说明。画图菜单包括两个菜单项:画线、画圆。

具体如图所示:
在这里插入图片描述
具体代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        Color pencolor ;
        Font fontSelect;
 
        private void 画圆ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (Graphics g = this.CreateGraphics())
            {
                g.Clear(this.BackColor);
                Pen p = new Pen(pencolor, 3);
                g.DrawEllipse(p, 90, 70, 100, 100);
                g.DrawString("圆", fontSelect, new SolidBrush(pencolor), 110, 200);
            }
        }
 
        private void 颜色ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ColorDialog ColorDialog1 = new ColorDialog();
            if (ColorDialog1.ShowDialog() == DialogResult.OK)
            {
                pencolor = ColorDialog1.Color;
            }
        }
 
        private void 字体ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FontDialog fontdialog1 = new FontDialog();
            if(fontdialog1.ShowDialog() == DialogResult.OK)
            {
                fontSelect = fontdialog1.Font;
            }
        }
 
        private void 画线ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (Graphics g = this.CreateGraphics())
            {
                g.Clear(this.BackColor);
                Pen p = new Pen(pencolor, 2);
                g.DrawLine(p, 20, 60, 250, 60);
                g.DrawString("线", fontSelect, new SolidBrush(pencolor), 110, 200);
            }
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值