• 大小: 50KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-17
  • 语言: C#
  • 标签: C#  示波器  

资源简介

用C#编写的简单示波器,有振幅的变换,周期的变换,其中有正弦波,方波,三角波。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 简单示波器
{
    public partial class Form1 : Form
    {
        int type = 0;   //决定显示的波型
        double range = 10; //显示的波的振幅,初始值为10
        double periods = 5;  //显示的波的周期,初始值为10
        public Form1()
        {
            InitializeComponent();

        }

        private void pictureBox1_Paint(object sender PaintEventArgs e)
        {
           
            Graphics g = e.Graphics;
            Pen mypen=new Pen(Color.Black2);

            g.TranslateTransform(this.pictureBox1.Width / 2.0f this.pictureBox1.Height / 2.0f);
            g.ScaleTransform(1 -1);//改变坐标

            g.DrawLine(mypen -this.pictureBox1.Width / 2.0f 0 this.pictureBox1.Width / 2.0f 0);
            g.DrawLine(mypen 0 -this.pictureBox1.Height / 2.0f 0 this.pictureBox1.Height / 2.0f);
            //画坐标
            g.DrawLine(mypen -5.0f this.pictureBox1.Height / 2.0f - 5.0f 0 this.pictureBox1.Height / 2.0f);
            g.DrawLine(mypen 5.0f this.pictureBox1.Height / 2.0f - 5.0f 0 this.pictureBox1.Height / 2.0f);
            //画Y方向上的箭头
            g.DrawLine(mypen this.pictureBox1.Width / 2.0f - 7.0f 5.0f this.pictureBox1.Width / 2.0f - 3.0f 0);
            g.DrawLine(mypen this.pictureBox1.Width / 2.0f - 7.0f -5.0f this.pictureBox1.Width / 2.0f - 3.0f 0);
            //画X方向上的箭头


            //下面代码中的  251 是由this.pictureBox1.Width / 2.0f取整数得来的。

            switch (type)//根据type画不同的波型
            {
                case 0:   //画正弦波
                    double x1 x2 y1 y2;
                    for (x1 = -251; x1 <= 251; x1++)
                    {
                        y1 = Math.Sin(x1 / periods) * range;
                        x2 = x1 + 1;
                        y2 = Math.Sin(x2 / periods) * range;
                        g.DrawLine(mypen (float)x1 (float)y1 (float)x2 (float)y2);
                    }
                    break;
                case 1:   //画方波
                    double x3 x4 y;
                    for (x3 = -251; x3 <= 251; x3++)
                    {
                        if (Math.IEEERemainder(x3 periods) > 0 && Math.IEEERemainder(x3 periods) < periods / 2)
                            y = range;
                        else
                            y = -range;
                        x4 = x3 + 1;
                        g.DrawLine(mypen (float)x3 (float)y (float)x4 (float)y);
                    }
                    break;
                case 2: //画三角波
                    double x;
                    for (x = -251; x <= 251; x = x + 1)
                    {
                        if (Math.IEEERemainder(x periods) == 0)
                        {
                            g.DrawLine(mypen (float)x 0 (float)(x + periods / 4) (float)range)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      13312  2012-06-22 10:47  简单示波器\简单示波器\bin\Debug\简单示波器.exe

     文件      32256  2012-06-22 10:47  简单示波器\简单示波器\bin\Debug\简单示波器.pdb

     文件      11600  2012-06-22 10:47  简单示波器\简单示波器\bin\Debug\简单示波器.vshost.exe

     文件        490  2009-08-31 00:40  简单示波器\简单示波器\bin\Debug\简单示波器.vshost.exe.manifest

     文件       4530  2012-06-22 10:51  简单示波器\简单示波器\Form1.cs

     文件      11138  2012-06-22 09:42  简单示波器\简单示波器\Form1.Designer.cs

     文件       5817  2012-06-22 09:42  简单示波器\简单示波器\Form1.resx

     文件       4440  2012-06-22 09:38  简单示波器\简单示波器\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6359  2012-06-22 10:47  简单示波器\简单示波器\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        792  2012-06-22 10:45  简单示波器\简单示波器\obj\x86\Debug\GenerateResource.read.1.tlog

     文件       1858  2012-06-22 10:45  简单示波器\简单示波器\obj\x86\Debug\GenerateResource.write.1.tlog

     文件       7897  2012-06-22 09:42  简单示波器\简单示波器\obj\x86\Debug\ResolveAssemblyReference.cache

     文件       3180  2012-06-22 10:47  简单示波器\简单示波器\obj\x86\Debug\简单示波器.csproj.FileListAbsolute.txt

     文件      13312  2012-06-22 10:47  简单示波器\简单示波器\obj\x86\Debug\简单示波器.exe

     文件        180  2012-06-22 10:45  简单示波器\简单示波器\obj\x86\Debug\简单示波器.Form1.resources

     文件      32256  2012-06-22 10:47  简单示波器\简单示波器\obj\x86\Debug\简单示波器.pdb

     文件        180  2012-06-22 10:45  简单示波器\简单示波器\obj\x86\Debug\简单示波器.Properties.Resources.resources

     文件        496  2012-06-21 10:35  简单示波器\简单示波器\Program.cs

     文件       1362  2012-06-21 10:35  简单示波器\简单示波器\Properties\AssemblyInfo.cs

     文件       2880  2012-06-21 10:35  简单示波器\简单示波器\Properties\Resources.Designer.cs

     文件       5612  2012-06-21 10:35  简单示波器\简单示波器\Properties\Resources.resx

     文件       1100  2012-06-21 10:35  简单示波器\简单示波器\Properties\Settings.Designer.cs

     文件        249  2012-06-21 10:35  简单示波器\简单示波器\Properties\Settings.settings

     文件       3689  2012-06-21 11:19  简单示波器\简单示波器\简单示波器.csproj

     文件        887  2012-06-21 10:35  简单示波器\简单示波器.sln

    ..A..H.     23552  2012-06-22 10:51  简单示波器\简单示波器.suo

     目录          0  2012-06-21 10:35  简单示波器\简单示波器\obj\x86\Debug\TempPE

     目录          0  2012-06-22 10:47  简单示波器\简单示波器\obj\x86\Debug

     目录          0  2012-06-21 12:33  简单示波器\简单示波器\bin\Debug

     目录          0  2012-06-21 12:33  简单示波器\简单示波器\obj\x86

............此处省略8个文件信息

评论

共有 条评论