米尔嘉
米尔嘉
发布于 2022-11-28 / 329 阅读
3
0

C#学习记录

学习记录

this.Size = new Size(600, 400);
this.BackColor = Color.Red;
this.ForeColor = Color.Red;
label1.Location = new Point(10, 100);
label1.BackColor = Color.Red;
label1.Text = "";
this.Cursor = Cursors.Default;
this.BackgroundImage = new Bitmap("
using System;
using System.Linq;
namespace Test1_7
{
    class Program
    {
        static void Main(string[] args)
        {
            int i;
            string s_ident;
            char ch = Convert.ToChar("\0");
            Console.WriteLine("请输入15位身份证号码:");
            s_ident = Console.ReadLine();
            if (s_ident.Length != 15)
            {
                Console.WriteLine("号码格式不正确");
            }
            else
            {
                for (i = 0; i < 15; i++)
                {
                    ch = s_ident.ElementAtOrDefault(i);
                    if (!char.IsNumber(ch))
                    {
                        Console.WriteLine("号码格式不正确");
                        break;
                    }
                    if (i == 14)
                    {
                        if (ch % 2 == 0)
                        {
                            Console.WriteLine("性别为女");
                            break;
                        }
                        else
                        {
                            Console.WriteLine("性别为男");
                            break;
                        }
                    }
                }
            }
            Console.WriteLine("按回车键结束");
            Console.ReadLine();
        }
    }
}
using System;
using System.Linq;

namespace Test1_8
{
    class Program
    {
        static void Main(string[] args)
        {
            int i;
            string s_ident;
            char ch = Convert.ToChar("\0");
            Console.WriteLine("请输入十八位身份证号码:");
            s_ident = Console.ReadLine();
            if (s_ident.Length != 18)
            {
                Console.WriteLine("号码格式不正确");
            }
            else
            {
                for (i = 0; i < s_ident.Length; i++)
                {
                    ch = s_ident.ElementAtOrDefault(i);
                    if (i <= 16)
                    {
                        if (!char.IsNumber(ch)){
                            Console.WriteLine("号码格式1不正确");
                            break;
                        }
                        /*if (ch <= '0' && ch >= '9')
                        {
                            Console.WriteLine("号码格式不正确");
                        }*/
                    }
                    else if(i==17)
                    {

                        if (!char.IsNumber(ch)&&ch != 'X' )
                        {
                            Console.WriteLine("号码格式2不正确");
                            break;
                        }
                        if (ch % 2 == 0 && char.IsNumber(ch))  //ch >= '0' && ch <= '9'
                        {
                            Console.WriteLine("性别为女");
                            break;
                        }
                        else
                        {
                            Console.WriteLine("性别为男");
                            break;
                        }
                    }
                }
            }
            Console.WriteLine("按回车键结束");
            Console.ReadLine();
        }
    }
}
using System;
using System.Linq;

namespace Test1_9
{
    class Program
    {
        static void Main(string[] args)
        {
            int i;
            string s_text;
            char ch = Convert.ToChar('\0');
            Console.WriteLine("请输入一个字符串");
            s_text = Console.ReadLine();
            ch=s_text.ElementAtOrDefault(0);
            for (i = 0; i < s_text.Length; i++)
            {
                if(ch< s_text.ElementAtOrDefault(i))
                {
                    ch = s_text.ElementAtOrDefault(i);
                }
            }
            Console.WriteLine("ASCII码最大的字符是:");
            Console.WriteLine(ch);
            Console.WriteLine("按回车键结束");
            Console.ReadLine();
        }
    }
}
using System;
using System.Linq;

namespace Test1_10
{
    class Program
    {
        static void Main(string[] args)
        {
            int i;
            string s_text;
            char ch = Convert.ToChar('\0');
            Console.WriteLine("请输入一个字符串");
            s_text = Console.ReadLine();
            ch=s_text.ElementAtOrDefault(0);
            for (i = 0; i < s_text.Length; i++)
            {
                if(ch> s_text.ElementAtOrDefault(i))
                {
                    ch = s_text.ElementAtOrDefault(i);
                }
            }
            Console.WriteLine("ASCII码最小的字符是:");
            Console.WriteLine(ch);
            Console.WriteLine("按回车键结束");
            Console.ReadLine();
        }
    }
}
public void SaveInfo(String path)
{
     StreamWriter sw = new StreamWriter(path);
     sw.WriteLine(textBox1.Text);
     sw.WriteLine(textBox2.Text);
     sw.WriteLine(dateTimePicker1.Value.ToLongDateString());
     sw.WriteLine(textBox3.Text);
     sw.WriteLine(comboBox1.SelectedIndex);
     sw.WriteLine(textBox4.Text);
      sw.Close();
}
public void LoadInfo(String path) 
{
     StreamReader sr = new StreamReader(path);
     textBox1.Text = sr.ReadLine();
     textBox2.Text = sr.ReadLine();
     dateTimePicker1.Value = DateTime.Parse(sr.ReadLine());
     textBox3.Text = sr.ReadLine();
     comboBox1.SelectedIndex = Int32.Parse(sr.ReadLine());
     textBox4.Text = sr.ReadLine();
    sr.Close();
}
private void button1_Click(object sender, EventArgs e)
{
     OpenFileDialog dlg = new OpenFileDialog();
     dlg.InitialDirectory = Application.StartupPath;
     dlg.Filter = "商品信息文件(*.s72))|*.s72";
      if (dlg.ShowDialog() == DialogResult.OK)
      {
           LoadInfo(dlg.FileName);
       }
       statusBar1.Panels[0].Text =File.GetLastWriteTime(dlg.FileName).ToString();
        }
private void button2_Click(object sender, EventArgs e)
{
     SaveFileDialog dlg = new SaveFileDialog();
      dlg.InitialDirectory = Application.StartupPath;
      dlg.Filter = "商品信息文件(*.s72))|*.s72";
      if (dlg.ShowDialog() == DialogResult.OK) 
      {
           SaveInfo(dlg.FileName);
      }
}
private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.InitialDirectory = Application.StartupPath;
            dlg.Filter = "商品信息文件(*.s72))|*.s72";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                LoadInfo(dlg.FileName);
            }
            statusBar1.Panels[0].Text = File.GetLastWriteTime(dlg.FileName).ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.InitialDirectory = Application.StartupPath;
            dlg.Filter = "商品信息文件(*.s72))|*.s72";
            if (dlg.ShowDialog() == DialogResult.OK) 
            {
                SaveInfo(dlg.FileName);
            }

        }

        public void LoadInfo(String path) 
        {
            FileStream fs = new FileStream(path,FileMode.Open);
            BinaryReader br = new BinaryReader(fs);
            textBox1.Text = br.ReadString();
            textBox2.Text = br.ReadString();
            dateTimePicker1.Value = DateTime.Parse(br.ReadString());
            textBox3.Text = br.ReadString();
            comboBox1.SelectedIndex = br.ReadInt32();
            textBox4.Text = br.ReadString();
            br.Close();
            fs.Close();
        }
        public void SaveInfo(String path)
        {
            FileStream fs = new FileStream(path, FileMode.Create);
            BinaryWriter bw = new BinaryWriter(fs);
            bw.Write(textBox1.Text);
            bw.Write(textBox2.Text);
            bw.Write(dateTimePicker1.Value.ToLongDateString());
            bw.Write(textBox3.Text);
            bw.Write(comboBox1.SelectedIndex);
            bw.Write(textBox4.Text);
            bw.Close();
            fs.Close();
        }
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Test7_11
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btn_Add_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length > 0 && !listBox1.Items.Contains(textBox1.Text))
            {
                listBox1.Items.Add(textBox1.Text);
                textBox1.Text = "";
            }
        }

        private void btn_Del_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex >= 0)
                listBox1.Items.RemoveAt(listBox1.SelectedIndex);
        }

        public void SaveInfo(String path)
        {
            StreamWriter sw = new StreamWriter(path);
            sw.WriteLine(listBox1.Items.Count);
            for(int i = 0; i < listBox1.Items.Count; i++)
            {
                sw.WriteLine(listBox1.Items[i].ToString());
            }
            sw.Close();
        }

        public void LoadInfo(String path)
        {
            listBox1.Items.Clear();
            StreamReader sr = new StreamReader(path);
            int num = int .Parse( sr.ReadLine());
            for(int i = 0; i < num; i++)
            {
                listBox1.Items.Add(sr.ReadLine());
            }
            sr.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = Application.StartupPath;
            ofd.Filter = "好友列表文件(*.s711)|*.s711";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                LoadInfo(ofd.FileName);
                statusBarPanel1.Text = File.GetLastAccessTime(ofd.FileName).ToString();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.InitialDirectory = Application.StartupPath;
            sfd.Filter = "好友列表文件(*.s711)|*.s711";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                SaveInfo(sfd.FileName);
            }
        }
    }
}

            /*同心圆*/
            /*e.Graphics.DrawEllipse(Pens.Black,40,40,160,160);
            e.Graphics.DrawEllipse(Pens.Black, 60, 60, 120, 120);*/

            /*第一题网格线*/
            /*e.Graphics.DrawString("这是一组网格线", this.Font, Brushes.Black, 90, 20);
            e.Graphics.DrawLine(Pens.Black, 0, 80, 300, 80);
            e.Graphics.DrawLine(Pens.Black, 0, 160,300, 160);
            e.Graphics.DrawLine(Pens.Black, 80, 0, 80, 240);
            e.Graphics.DrawLine(Pens.Black, 200, 0, 200, 240);



            /*第二题平行线*/
            /*e.Graphics.DrawString("平行线", this.Font, Brushes.Black, 10, 20);
            e.Graphics.DrawLine(Pens.Red, 120, 180, 160, 40);
            e.Graphics.DrawLine(Pens.Blue, 160, 180, 200, 40);
            e.Graphics.DrawLine(Pens.Black, 200, 180, 240, 40);*/


            /*第三题同心圆*/
            /*e.Graphics.DrawString("这是一组同心圆", this.Font, Brushes.Black, 10, 20);
            e.Graphics.DrawEllipse(Pens.Black, 40, 40, 160,160);
            e.Graphics.DrawEllipse(Pens.Black, 60, 60, 120, 120);
            e.Graphics.DrawEllipse(Pens.Black, 80, 80, 80, 80);
            e.Graphics.DrawEllipse(Pens.Black, 100, 100, 40, 40);*/



            /*第四题实心圆*/
            /*e.Graphics.FillEllipse(Brushes.Red, 240, 40, 160, 160);
            e.Graphics.FillEllipse(Brushes.Blue, 260, 60, 120, 120);
            e.Graphics.FillEllipse(Brushes.Pink, 280, 80, 80, 80);
            e.Graphics.FillEllipse(Brushes.Black, 300, 100, 40, 40);*/


            /*第五题多边形*/
            //三角形
            /*e.Graphics.DrawLine(Pens.Red, 50, 100, 20, 150);
            e.Graphics.DrawLine(Pens.Red, 20, 150, 80, 150);
            e.Graphics.DrawLine(Pens.Red, 80, 150, 50, 100);*/
            //四边形
            /*e.Graphics.DrawLine(Pens.Red, 100, 100, 100, 150);
            e.Graphics.DrawLine(Pens.Red, 100, 150, 150, 150);
            e.Graphics.DrawLine(Pens.Red, 150, 150, 150, 100);
            e.Graphics.DrawLine(Pens.Red, 150, 100, 100, 100);*/
            //五边形
            /*e.Graphics.DrawLine(Pens.Red, 220, 100, 190, 120);
            e.Graphics.DrawLine(Pens.Red, 190, 120, 200, 150);
            e.Graphics.DrawLine(Pens.Red, 200, 150, 240, 150);
            e.Graphics.DrawLine(Pens.Red, 240, 150, 250, 120);
            e.Graphics.DrawLine(Pens.Red, 250, 120, 220, 100);*/



            /*第六题实心*/
            // 三角形
            /* Point point1 = new Point(50, 100);
             Point point2 = new Point(20, 150);
             Point point3 = new Point(80, 150);
             Point[] pntArr = { point1, point2, point3 };
             e.Graphics.DrawPolygon(Pens.Red, pntArr);*///new Pen(Color.Red
                                                        // 填充三角形
            /*Point point1 = new Point(50, 100);
            Point point2 = new Point(20, 150);
            Point point3 = new Point(80, 150);
            Point[] pntArr1 = { point1, point2, point3 };
            e.Graphics.FillPolygon(Brushes.Pink, pntArr1);*/


            //四边形
            /* Point point4 = new Point(100, 100);
             Point point5 = new Point(100, 150);
             Point point6 = new Point(150, 150);
             Point point7 = new Point(150, 100);
             Point[] pntArr = { point4, point5, point6, point7 };
             e.Graphics.DrawPolygon(Pens.Red, pntArr);*/
            //填充四边形
            /*Point point4 = new Point(100, 100);
            Point point5 = new Point(100, 150);
            Point point6 = new Point(150, 150);
            Point point7 = new Point(150, 100);
            Point[] pntArr2 = { point4, point5, point6, point7 };
            e.Graphics.FillPolygon(Brushes.Pink, pntArr2);*/


            //五边形
            /* Point point8 = new Point(220, 100);
             Point point9 = new Point(190, 120);
             Point point10 = new Point(200, 150);
             Point point11 = new Point(240, 150);
             Point point12 = new Point(250, 120);
             Point[] pntArr3 = { point8, point9, point10, point11, point12 };
             e.Graphics.DrawPolygon(Pens.SkyBlue, pntArr3); */
            // 填充五边形
            /*Point point8 = new Point(220, 100);
            Point point9 = new Point(190, 120);
            Point point10 = new Point(200, 150);
            Point point11= new Point(240, 150);
            Point point12= new Point(250, 120);
            Point[] pntArr3 = { point8, point9, point10,point11,point12};
            e.Graphics.FillPolygon(Brushes.SkyBlue, pntArr3);*/




            //第七题矩形
            /*e.Graphics.DrawRectangle(Pens.Red, 20, 80, 40, 100);
            e.Graphics.DrawRectangle(Pens.Red, 80, 100, 100, 40);
            e.Graphics.DrawRectangle(Pens.Red, 200, 100, 60, 60);*/


            // 第八题填充矩形
            /*e.Graphics.FillRectangle(Brushes.Red, 20, 80, 40, 100);
            e.Graphics.FillRectangle(Brushes.Red, 80, 100, 100, 40);
            e.Graphics.FillRectangle(Brushes.Red, 200, 100, 60, 60);*/


            //第九题折线
            /* e.Graphics.DrawLine(Pens.Red, 80, 100, 120, 60);
             e.Graphics.DrawLine(Pens.Blue, 120, 60, 160, 100);
             e.Graphics.DrawLine(Pens.Black, 160, 100, 200, 60);
             e.Graphics.DrawLine(Pens.Black, 200, 60, 240, 100);
             e.Graphics.DrawLine(Pens.Black, 240, 100, 280, 60);*/

            //e.Graphics.DrawLines(Pens.Black, new Point[] { new Point(20, 100), new Point(60, 60), new Point(100, 100), new Point(140, 60), new Point(180, 100), new Point(220, 60), new Point(260, 100)});


            //e.Graphics.DrawLines(Pens.Black, new Point[] { new Point(20, 100), new Point(60, 60), new Point(100, 100), new Point(140, 60), new Point(180, 100), new Point(220, 60), new Point(260, 100), new Point(20, 100) });

            /*Point point8 = new Point(80, 100);
            Point point9 = new Point(120, 60);
            Point point10 = new Point(160, 100);
            Point point11 = new Point(200, 60);
            Point point12 = new Point(240, 100);
            Point point13 = new Point(280, 60);
            Point[] pntArr3 = { point8, point9, point10, point11, point12 , point13 };
            e.Graphics.DrawLines(Pens.Black, pntArr3);*/



            //第十题

            /*Point point8 = new Point(80, 100);
            Point point9 = new Point(120, 60);
            Point point10 = new Point(160, 100);
            Point point11 = new Point(200, 60);
            Point point12 = new Point(240, 100);
            Point point13 = new Point(280, 60);
            Point point14 = new Point(320, 60);
            Point point15 = new Point(80, 100);
            Point[] pntArr3 = { point8, point9, point10, point11, point12, point13, point14, point15};
            e.Graphics.DrawLines(Pens.Black, pntArr3); */



            //第十一题 圆弧
            /*e.Graphics.DrawArc(Pens.Pink, 160, 160, 160, 160, 20, 100);
            e.Graphics.DrawArc(Pens.Blue, 160, 160, 160, 160, 140, 100);
            e.Graphics.DrawArc(Pens.Pink, 160, 160, 160, 160, 260, 100);*/


            //第十一题 空心扇形
            /*e.Graphics.DrawPie(Pens.Pink, 160, 160, 160, 160, 20, 100);
            e.Graphics.DrawPie(Pens.Blue, 160, 160, 160, 160, 140, 100);
            e.Graphics.DrawPie(Pens.Pink, 160, 160, 160, 160, 260, 100);*/

            //第十二题 实心扇形
            /*e.Graphics.FillPie(Brushes.Pink, 160, 160, 160, 160, 20, 100);
            e.Graphics.FillPie(Brushes.Blue, 160, 160, 160, 160, 140, 100);
            e.Graphics.FillPie(Brushes.Pink, 160, 160, 160, 160, 260, 100);*/


            //e.Graphics.DrawCurve(Pens.Black, new Point[] { new Point(20, 100), new Point(80, 60), new Point(140, 100), new Point(200, 140), new Point(260, 100) });


            //e.Graphics.DrawClosedCurve(Pens.Black, new Point[] { new Point(20, 100), new Point(80, 60), new Point(140, 100), new Point(200, 140), new Point(260, 100) });

            //e.Graphics.FillClosedCurve(Brushes.Red, new Point[] { new Point(20, 100), new Point(80, 60), new Point(140, 100), new Point(200, 140), new Point(260, 100) });


            //e.Graphics.DrawString("这是一组实心椭圆", this.Font, Brushes.Black, 10, 20);
            //e.Graphics.FillEllipse(Brushes.Purple, 40, 60, 40, 120);
            //e.Graphics.FillEllipse(Brushes.Blue, 80, 100, 120, 40);
            //e.Graphics.FillEllipse(Brushes.Green, 200, 60, 40, 120);

            //e.Graphics.DrawString("这是一组实心椭圆", this.Font, Brushes.Black, 10, 20);
            //e.Graphics.DrawEllipse(Pens.Purple, 40, 60, 40, 120);
            //e.Graphics.DrawEllipse(Pens.Blue, 80, 100, 120, 40);
            //e.Graphics.DrawEllipse(Pens.Green, 200, 60, 40, 120);


            //e.Graphics.DrawRectangle(Pens.Blue, 40, 80, 160, 80);
            //e.Graphics.DrawEllipse(Pens.Red, 40, 80, 160, 80);

           e.Graphics.FillRectangle(Brushes.Blue, 40, 80, 160, 80);
            e.Graphics.FillEllipse(Brushes.White, 40, 80, 160, 80);

http://www.doc88.com/p-0711910463155.html


评论