- 博客(0)
- 资源 (22)
- 收藏
- 关注
C#播放指定的声音,内有详细的步骤说明,非常适合新手学习,亲自测试能用
C#播放指定的声音,内有详细的步骤说明,非常适合新手学习,亲自测试能用,
//第一步在界面中添加axWindowsMediaPlayer1控件;第二步添加引用AxInterop.WMPLib.dll和Interop.WMPLib.dll
//第三步写一个声音函数,调用声音文件
2023-01-03
CSharp与西门子PLC通信模板 本人亲自测试过,保证能用 包括上位机和PLC的全套程序
CSharp与西门子PLC通信模板 本人亲自测试过,保证能用。包括上位机和PLC的全套程序。非常适合新手学习。
2022-12-28
通过TXT文本修改登录密码.rar
string oldpassword = tb_oldPwd.Text;
string newpassword = tb_newPwd.Text;
string repeatpassword = tb_conPwd.Text;
if (oldpassword != common.password)
{
MessageBox.Show("旧密码错误");
return;
}
if (newp
2020-10-30
俄罗斯方块C#源代码.rar
using System.Drawing;
//add
namespace 俄罗斯方块
{
internal class Game
{
public const int BlockImageWidth = 21; //方砖中每个小方格的大小
public const int BlockImageHeight = 21;
public const int PlayingFieldWidth = 10; //游戏面板大小
public const int PlayingFieldHeight = 20;
2020-08-28
华容道C#源代码.rar
using System;
using System.Drawing;
using System.Windows.Forms;
namespace 华容道
{
public partial class Form1 : Form
{
private readonly int[,] A = new int[7,6];
private readonly Button[] Bing = new Button[4];
private readonly Button[] Jiang = new Button[4];
priv
2020-08-28
扫雷有限C#源代码.rar
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Mine
{
public partial class Form1 : Form
{
private int CostTime; //所用时间
private int MineNum = 10; //雷的总数
private int MineWidth = 30; //雷方块的大小(宽度为30像素)
private Button[,] Mines;
p
2020-08-28
贪吃蛇csharp源代码.rar
using System;
using System.Collections;
using System.Drawing;
namespace 贪吃蛇
{
///<summary>
/// snake 的摘要说明。
///</summary>
public class Snake
{
private ArrayList blockList; //字段
private int direction = 1; //0,1,2,3分别代表上、右、下、左
private int headNumber; //蛇头序
2020-08-28
C#文件夹监控并生成日志.rar
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using opc_Library;
namespace Files
{
///
/// Form1 的摘要说明。
///
public class Form1 : System.Windows.Forms.Form
{
write_log write_log = new write_log();
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.IO.FileSystemWatcher fileSystemWatcher1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label2;
///
/// 必需的设计器变量。
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
///
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
///
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.button1 = new System.Windows.Forms.Button();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.fileSystemWatcher1 = new System.IO.FileSystemWatcher();
this.button2 = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.fileSystemWatcher1)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(120, 16);
this.label1.TabIndex = 0;
this.label1.Text = "文件夹全路径名: ";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(8, 40);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(320, 21);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "C:\\";
//
// button1
//
this.button1.Location = new System.Drawing.Point(232, 8);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(96, 23);
this.button1.TabIndex = 2;
this.button1.Text = "浏览文件夹";
this.button1.Click += new System.EventHandler(this.button1_Click_1);
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(8, 88);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(320, 136);
this.richTextBox1.TabIndex = 3;
this.richTextBox1.Text = "";
//
// fileSystemWatcher1
//
this.fileSystemWatcher1.EnableRaisingEvents = true;
this.fileSystemWatcher1.SynchronizingObject = this;
this.fileSystemWatcher1.Changed += new System.IO.FileSystemEventHandler(this.fileSystemWatcher1_Changed);
this.fileSystemWatcher1.Created += new System.IO.FileSystemEventHandler(this.fileSystemWatcher1_Created);
this.fileSystemWatcher1.Deleted += new System.IO.FileSystemEventHandler(this.fileSystemWatcher1_Deleted);
this.fileSystemWatcher1.Renamed += new System.IO.RenamedEventHandler(this.fileSystemWatcher1_Renamed);
//
// button2
//
this.button2.Location = new System.Drawing.Point(232, 64);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(96, 23);
this.button2.TabIndex = 5;
this.button2.Text = "开始监视";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 72);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(120, 16);
this.label2.TabIndex = 4;
this.label2.Text = "文件系统变化情况: ";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(336, 230);
2020-04-01
添加动态控件.rar
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Label lab = new Label();//定义在到事件外面,这样多个按钮能公用该变量
private void button1_Click(object sender, EventArgs e)
{
#region //动态添加多个按钮
for (int i=0;i<4;i++)
{
Button btn = new Button();
btn.Name = "MyButton"+i;
btn.Text = string.Format("按钮"+i);
btn.Size = new Size(72, 48);
btn.Location = new Point(200, 180+70*i);
this.Controls.Add(btn);
}
#endregion
#region//动态添加标签
lab.Name = "MyLabel";
lab.Text = string.Format("标签");
lab.Size = new Size(72, 48);
lab.Location = new Point(100, 180);
this.Controls.Add(lab);
#endregion
#region//动态添加文本框
TextBox tb = new TextBox();
tb.Name = "MyTextBox";
tb.Text = string.Format("文本框");
tb.Size = new Size(72, 48);
tb.Location = new Point(300, 180);
this.Controls.Add(tb);
#endregion
#region//往容器内添加标签
Label lab1 = new Label();
lab1.Name = "MyLabel1";
lab1.Text = string.Format("标签");
lab1.Size = new Size(72, 48);
lab1.Location = new Point(710, 180);
panel1.AutoScroll = true; //为panel添加滚动条
panel1.Controls.Add(lab1);//为panel添加控件
panel1.BorderStyle = BorderStyle.FixedSingle;//为panel添加边框
// panel1.BorderStyle = BorderStyle.None;//为panel取消边框
#endregion
}
private void button2_Click(object sender, EventArgs e)
{
this.Controls.Remove(lab);
}
}
}
2020-03-20
自动出题 自动生成EXCEL表格
private void Save2Excel()
{
//string file = "F:\\11\\ck.xlsx";
//string path = "F:\\11\\excel\\";
string time = DateTime.Now.ToString("yyyyMMdd");
string file = System.Windows.Forms.Application.StartupPath + "\\ck.xlsx";
string path = System.Windows.Forms.Application.StartupPath + "\\excel\\";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
string saveName1 = path + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
excel = new CCExcel(file,saveName1);
excel.Exceldata();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
Form1.name = textBox1.Text.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Text = 11.ToString();
comboBox2.Text = 100.ToString();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Form1.comB1 = comboBox1.Text.ToString();
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
Form1.comB2 = comboBox2.Text.ToString();
}
}
public class CCExcel
{
public Excel.Application appExcel;
public Excel.Workbooks wbs;
public Excel.Workbook wb;
public Excel.Worksheets wss;
public Excel.Worksheet ws;
private string fileName;
private string saveName;
public CCExcel(string fileName,string saveName)
{
//
//TODO: 在此处添加构造函数逻辑
//
this.fileName = fileName;
this.saveName = saveName;
}
public void Exceldata()
{
Create();
//Open(fileName);
Data2Excel();
Save(saveName);
//Save(wb,saveName);
//appExcel.ActiveWorkbook.SaveCopyAs(fileName); //判断当前激活的表,并保存这个表。否则,保存时会弹出“是否保存Sheet1.xlsx”的对话框
wb.Close(Type.Missing, Type.Missing, Type.Missing);
wbs.Close();
appExcel.Quit();
wb = null;
wbs = null;
appExcel = null;
GC.Collect();
}
private void Create()//创建一个Excel对象
{
appExcel = new Excel.Application();
wbs = appExcel.Workbooks;
wb = wbs.Add(true);
//ws = (Excel.Worksheet)wb.ActiveSheet;//这是一个只读sheets集合
//Excel.Worksheet worksheet = wb.ActiveSheet as Excel.Worksheet;//这也是一个只读sheets集合
//Excel.Worksheet ws = (Worksheet)wb.Worksheets[1];//创建工作页sheet单页
ws = wb.Worksheets[1] as Worksheet; //第一个sheet页
ws.Name = "ck"; //这里修改sheet名称
}
public void Open(string fileName)
{
appExcel = new Excel.Application();
wbs = appExcel.Workbooks;
wb = wbs.Add(fileName);
wb = wbs.Open(fileName,Type.Missing,Type.Missing,Type.Missing,Type.Missing,
Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,
Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);
}
2020-03-16
西门子1200与Labview通过以太网通信(内含labview与1200的plc程序)
西门子1200与Labview通过以太网通信(内含labview与1200的plc程序),包括全套程序和资料,亲测可用,M0.0是开关,M0.0为true则开始发送数据给Labview。用之前要将OB1 中的TSEND_C组态中的IP地址192.168.0.11改为你自己电脑的IP。非常适合初学者使用,欢迎下载!
2019-03-29
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人