C#简单功能(三)

3设计一基于window窗体的登录界面,窗体居中显示。要求用户输入用户名和密码,若登录失败则显示用户名或密码错误,若登录成功则显示第二个窗体。第二个窗体要求能在屏幕上以三种颜色、三种字体输出文字: “GIS开发设计基础—你的姓名”。这里你的姓名要替换成你的名字。

  1. 第一步:登录界面设计:
  2. 第二步:绘制字符串界面设计:
    一个menustrip,一个textbox,一个picturebox,三个button,一个colorDialog,一个fontDialog 在这里插入图片描述

3.第三步:绘制界面代码设计:

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;
using System.IO;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

namespace C_shape考核第三题
{
    public partial class Form2 : Form
    {
       
        public Form2()
        {
            InitializeComponent(); 
        }

        Graphics g;//创建画板
        Bitmap bmp;//绘制形成的图片
        string str;//接收文本框内容
        SaveFileDialog SaveFileDialog1 = new SaveFileDialog();//文件保存
        List<Color> clist = new List<Color>();//颜色列表
        List<Font> flist = new List<Font>();//字体列表
        public int spacing = 0;//初始Y坐标

        private void btn_Draw_Click(object sender, EventArgs e)
        {
            bmp = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);//初始化图片
            g = Graphics.FromImage(bmp);//初始化画板
            g.Clear(Color.White);//情况颜色

            str = textBox1.Text;
            if(str=="")//如果没有输入指定内容,默认内容输出
            {
                for (int i = 0; i < clist.Count; i++)//以颜色个数嵌套循环
                {
                    Brush brush = new SolidBrush(clist[i]);//更新画笔颜色
                    g.DrawString("GIS开发设计基础—唐文健", flist[i], brush, new Point(0, spacing));//(内容,字体,颜色,初始位置)
                    spacing += 30;//调整Y坐标大小,以达到换行的效果
                }
            }
            else
            {
                for (int i=0;i<clist.Count;i++)
                { 
                    Brush brush = new SolidBrush(clist[i]);
                    g.DrawString(str, flist[i], brush, new Point(0, spacing));
                    spacing += 30;
                }
            }
            spacing = 0;
            this.pictureBox1.Image = bmp;
            g.Dispose();
        }

        private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //保存图片,可以设置格式
            this.SaveFileDialog1.Filter = "(png)|*.png|(jpg)|*.jpg";
            if (this.SaveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string targetFn = this.SaveFileDialog1.FileName;
                bmp.Save(targetFn, ImageFormat.Png);
            }
        }

        private void 新建ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //初始化画板
            bmp = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);
            g = Graphics.FromImage(bmp);
            g.Clear(Color.White);
            this.pictureBox1.Image = bmp;
            g.Dispose();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.colorDialog1.ShowDialog() == DialogResult.OK)
            {
                clist.Add(this.colorDialog1.Color);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if(this.fontDialog1.ShowDialog()==DialogResult.OK)
            {
                flist.Add(this.fontDialog1.Font);
            }
        }
    }
}

4.总结:
亮点为自主颜色和字体选择,自主内容输出。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值