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

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

5181

被折叠的 条评论
为什么被折叠?



