| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1800 人关注过本帖
标题:求助编制绘图软件题
只看楼主 加入收藏
姓张名世离
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2019-10-17
结帖率:66.67%
收藏
已结贴  问题点数:20 回复次数:2 
求助编制绘图软件题
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: 绘图 软件 
2020-11-24 09:56
haitao0000
Rank: 2
等 级:论坛游民
帖 子:9
专家分:60
注 册:2020-11-4
收藏
得分:20 
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GDI绘图
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            g = splitContainer1.Panel1.CreateGraphics();
            bHaveFirstPoint = false;
            this.Text = "简单绘图软件";
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            cboSize.Items.Add("5");
            cboSize.Items.Add("7");
            cboSize.Items.Add("9");
            cboSize.Items.Add("11");
            cboSize.Items.Add("14");
            cboColor.Items.Add("Black");
            cboColor.Items.Add("Blue");
            cboColor.Items.Add("Coral");
            cboColor.Items.Add("Gray");
            cboColor.Items.Add("Cyan");
            cboColor.Items.Add("DeepPink");
            cboSize.Text = "14";
            cboColor.Text = "DeepPink";           
        }


        public Point startP;
        public Graphics g;
        bool bHaveFirstPoint;
        private void splitContainer1_Panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.splitContainer1.Panel1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.splitContainer1_Panel1_MouseMove);
                startP = e.Location;
                bHaveFirstPoint = true;
            }
               
        }

        private void splitContainer1_Panel1_MouseUp(object sender, MouseEventArgs e)
        {
            
            if(e.Button==MouseButtons.Left)
            {
                Pen myPen = new Pen(Color.FromName(cboColor.Text), Convert.ToInt32(cboSize.Text));
                g.DrawLine(myPen, startP, e.Location);
                this.splitContainer1.Panel1.MouseMove -= new System.Windows.Forms.MouseEventHandler(this.splitContainer1_Panel1_MouseMove);
                bHaveFirstPoint = false;
            }            
        }

        private void splitContainer1_Panel1_MouseClick(object sender, MouseEventArgs e)
        {
            
            if (e.Button == MouseButtons.Right)
            {

                //定义字体
                Font drawFont = new Font("Arial", float.Parse(cboSize.Text));
                //定义画刷
                SolidBrush drawBrush = new SolidBrush(Color.FromName(cboColor.Text));
                //定义字符串格式
                StringFormat drawFormat = new StringFormat();
                drawFormat.FormatFlags = StringFormatFlags.DisplayFormatControl;
                //输出文本的左上角座标
                float x = e.X;
                float y = e.Y;
                g.DrawString(txtInfo.Text, drawFont, drawBrush, x, y, drawFormat);
            }
            
        }

        private void splitContainer1_Panel1_MouseMove(object sender, MouseEventArgs e)
        {
            
            if (cboColor.Text.Length == 0 || cboSize.Text.Length == 0)
            {
                return;
            }
            if(bHaveFirstPoint)
            {
                g.Clear(SystemColors.AppWorkspace);
                Pen myPen = new Pen(Color.FromName(cboColor.Text), Convert.ToInt32(cboSize.Text));
                g.DrawLine(myPen, startP, e.Location);
            }                                   
        }
    }
}
2020-11-28 00:46
sssooosss
Rank: 9Rank: 9Rank: 9
等 级:禁止访问
威 望:3
帖 子:664
专家分:1115
注 册:2019-8-27
收藏
得分:0 
共同学习
2020-12-21 08:27
快速回复:求助编制绘图软件题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034999 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved