c#测编-图形用户界面交互程序设计

本文档详细介绍了使用C#进行GUI编程的实验,包括矩阵运算类的实现,登录验证,主窗体及多个子窗体的设计。实验涵盖了坐标计算、角度转换、交会计算以及矩阵的加减乘逆等操作。通过实验,作者深化了对面向对象编程的理解,并掌握了Qt框架的应用。
摘要由CSDN通过智能技术生成

目录

1.实验需求分析

1.1实验目的

1.2实验要求

2.实验原理

3.实验代码

3.1.登录界面

3.2正在登录界面

3.3主界面

3.4坐标计算

3.5角度转换

3.6交会计算主界面

3.7前方交会

3.8距离交会

3.9侧方交会

3.10矩阵运算主界面

3.11矩阵加减乘运算

3.12矩阵求逆运算

3.13确认更换账户

4.实验总结


1.实验需求分析

1.1实验目的

  1. 熟悉GUI 编程方法
  2. 掌握常用控件的使用方法
  3. 掌握控件的属性、事件编程机制

1.2实验要求

1. 编写一个多文档界面交互程序。编写一个矩阵运算类,实现矩阵的加、减、乘、求逆运算。

2. 设计1个主窗体、4个子窗体、登录对话框、关于对话框。4个子窗体用于测绘计算。

3. 要求有登录对话框,输入用户名和密码进行验证,验证成功后显示主窗体。

4. 主窗体有系统(打开、退出功能菜单项)、窗体(子窗体的平铺等操作菜单项)和帮助(关于、帮助菜单项)菜单。

2.实验原理

通过两点距离及方位角计算原理,实验二转换和交会原理计算,以及矩阵的加减乘除等原理编写。

3.实验代码

3.1.登录界面

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 图形用户界面交互

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        public void Delay(double delayTime)

        {

            DateTime now = DateTime.Now;

            double s;

            do

            {

                TimeSpan spand = DateTime.Now - now;

                s = spand.Milliseconds;  //Milliseconds是指以毫秒计数

                Application.DoEvents();

            }

            while (s < delayTime);

        }

        public class admin

        {

            public static int count = 7;

            public static string[] zh = new string[8] { "1,2" };

            public static string[] mm = new string[8] { "1,2" };

        }

        private void button1_Click(object sender, EventArgs e)

        {

            string zhanghao, mima;

            zhanghao = 账号.Text;

            zhanghao = zhanghao.Trim();

            mima = 密码.Text;

            mima = mima.Trim();

            for (int i=0;i<admin.count+2;i++)

            {

                if (i < admin.count + 1)

                {

                    if (zhanghao == admin.zh[i] && mima == admin.mm[i])

                    {

                        正在登陆 b = new 正在登陆();

                        b.Show();

                        Delay(500);

                        b.Close();

                        主界面 f = new 主界面();

                        f.Show();

                        this.Hide();

                        break;

                    }

                }

                if(i==admin.count+1)

                    MessageBox.Show("账号或密码有误");

            }

               

           

        }



        private void button2_Click(object sender, EventArgs e)

        {

            账号.Text = "";

            密码.Text = "";

            账号.Focus();

            this.Close();

        }



        private void Form1_Load(object sender, EventArgs e)

        {

            this.ActiveControl = 账号;

        }

    }

}

3.2正在登录界面

namespace 图形用户界面交互

{

    public partial class 正在登陆 : Form

    {

        public 正在登陆()

        {

            InitializeComponent();

        }

    }

}

3.3主界面

namespace 图形用户界面交互

{

    public partial class 主界面 : Form

    {

        private void SetBtnStyle(Button btn)

        {

            btn.FlatStyle = FlatStyle.Flat;//样式

            btn.BackColor = Color.Transparent;//去背景

            btn.FlatAppearance.BorderSize = 0;//去边线

            btn.FlatAppearance.MouseOverBackColor = Color.Transparent;//鼠标经过

            btn.FlatAppearance.MouseDownBackColor = Color.Transparent;//鼠标按下

        }

        public 主界面()

        {

            InitializeComponent();

            SetBtnStyle(button1);

            SetBtnStyle(button2);

            SetBtnStyle(button3);

            SetBtnStyle(button4);

        }



        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            确认更换账户 f = new 确认更换账户();

            f.Show();

            this.Hide();

        }



        private void 退出系统ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            this.Close();

        }



        private void 帮助ToolStripMenuItem1_Click(object sender, EventArgs e)

        {

            MessageBox.Show("有问题找QQ3");

        }



        private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            MessageBox.Show("1");

        }



        private void 更换账户ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            确认更换账户 f = new 确认更换账户();

            f.Show();

            this.Hide();

        }



        private void 退出应用ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            System.Environment.Exit(0);

        }



        private void 帮助ToolStripMenuItem3_Click(object sender, EventArgs e)

        {

            MessageBox.Show("有问题找1");

        }



        private void 关于ToolStripMenuItem1_Click(object sender, EventArgs e)

        {

            MessageBox.Show("1");

        }



        private void button1_Click(object sender, EventArgs e)

        {

            坐标基本计算 f = new 坐标基本计算();

            f.Show();

            this.Hide();

        }



        private void 坐标基本计算ToolStripMenuItem2_Click(object sender, EventArgs e)

        {

            坐标基本计算 f = new 坐标基本计算();

            f.Show();

            this.Hide();

        }



        private void 坐标基本计算ToolStripMenuItem3_Click(object sender, EventArgs e)

        {

            坐标基本计算 f = new 坐标基本计算();

            f.Show();

            this.Hide();

        }



        private void button1_MouseHover(object sender, EventArgs e)

        {

            Button button_1 = sender as Button;

            button1.FlatAppearance.BorderSize = 1;

        }



        private void button1_MouseLeave(object sender, EventArgs e)

        {

            Button button_1 = sender as Button;

            button1.FlatAppearance.BorderSize = 0;

        }



        private void button2_MouseHover(object sender, EventArgs e)

        {

            Button button_2 = sender as Button;

            button2.FlatAppearance.BorderSize = 1;

        }



        private void button2_MouseLeave(object sender, EventArgs e)

        {

            Button button_2 = sender as Button;

            button2.FlatAppearance.BorderSize = 0;

        }



        private void button3_MouseHover(object sender, EventArgs e)

        {

            Button button_3 = sender as Button;

            button3.FlatAppearance.BorderSize = 1;

        }



        private void button3_MouseLeave(object sender, EventArgs e)

        {

            Button button_3 = sender as Button;

            button3.FlatAppearance.BorderSize = 0;

        }



        private void button4_MouseHover(object sender, EventArgs e)

        {

            Button button_4 = sender as Button;

            button4.FlatAppearance.BorderSize = 1;

        }



        private void button4_MouseLeave(object sender, EventArgs e)

        {

            Button button_4 = sender as Button;

            button4.FlatAppearance.BorderSize = 0;

        }



        private void button2_Click(object sender, EventArgs e)

        {

            交会运算主界面 f = new 交会运算主界面();

            f.Show();

            this.Hide();

        }



        private void button3_Click(object sender, EventArgs e)

        {

            角度转换 f = new 角度转换();

            f.Show();

            this.Hide();

        }



        private void button4_Click(object sender, EventArgs e)

        {

            矩阵运算主界面 f = new 矩阵运算主界面();

            f.Show();

            this.Close();

        }



        private void 交会计算ToolStripMenuItem3_Click(object sender, EventArgs e)

        {

            交会运算主界面 f = new 交会运算主界面();

            f.Show();

            this.Hide();

        }



        private void 角度转换ToolStripMenuItem3_Click(object sender, EventArgs e)

        {

            角度转换 f = new 角度转换();

            f.Show();

            this.Hide();

        }



        private void 矩阵运算ToolStripMenuItem3_Click(object sender, EventArgs e)

        {

            矩阵运算主界面 f = new 矩阵运算主界面();

            f.Show();

            this.Close();

        }



        private void 交会计算ToolStripMenuItem2_Click(object sender, EventArgs e)

        {

            交会运算主界面 f = new 交会运算主界面();

            f.Show();

            this.Hide();

        }



        private void 角度转换ToolStripMenuItem2_Click(object sender, EventArgs e)

        {



            角度转换 f = new 角度转换();

            f.Show();

            this.Hide();

        }



        private void 矩阵运算ToolStripMenuItem2_Click(object sender, EventArgs e)

        {

            矩阵运算主界面 f = new 矩阵运算主界面();

            f.Show();

            this.Close();

        }

    }

3.4坐标计算

namespace 图形用户界面交互

{

    public partial class 坐标基本计算 : Form

    {

        public 坐标基本计算()

        {

            InitializeComponent();

        }



        private void button2_Click(object sender, EventArgs e)

        {

            主界面 f = new 主界面();

            f.Show();

            this.Close();

        }



        public static double DuD(double x)//度转度分秒

        {

            int a;

            double b, c, d;

            a = (int)x;

            b = (int)((x - a) * 60);

            d = ((x - a) * 60);

            c = (d - b) * 60;

            x = a + b / 100.0 + c / 10000;

            return x;

        }

        public static double FWJ(double x1, double y1, double x2, double y2)//方位角计算

        {

            double A, R;

            double azimuth = 0;

            double deltax = x2 - x1;

            double deltay = y2 - y1;

            if (deltax == 0 && deltay == 0)

            {

                A = -1;

                return A;

            }

            else if (deltax == 0)

            {

                if (deltay > 0)

                {

                    azimuth = Math.PI / 2.0;

                }

                else

                    azimuth = 1.5 * Math.PI;

            }

            else

            {

                R = Math.Atan(deltay / deltax);

                if (deltax <= 0)

                    azimuth = R + Math.PI;

                else if (deltay <= 0)

                    azimuth = R + 2 * Math.PI;

                else

                    azimuth = R;



            }

            A = azimuth * (180 / Math.PI);//弧度转度

            A = DuD(A);//度转度分秒

            return A;

        }

            private void button1_Click(object sender, EventArgs e)

        {

            double x1, y1, x2, y2,S,A;

            if (Y1.Text == "" || Y2.Text == "" || X1.Text == "" || X2.Text == "")

                MessageBox.Show("请检查是否将数据输入完整");

            else

            {

                x1 = Convert.ToDouble(X1.Text);

                y1 = Convert.ToDouble(Y1.Text);

                x2 = Convert.ToDouble(X2.Text);

                y2 = Convert.ToDouble(Y2.Text);

                S = Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));

                A = FWJ(x1, y1, x2, y2);

                string S1 = S.ToString("f3");

                string A1 = A.ToString("f5");

                MessageBox.Show("距离=" + S1 + "\n方位角=" + A1 + "(DD.MMSSS)");

            }

        }

    }

}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值