- 博客(0)
- 资源 (8)
- 收藏
- 关注
C#29种设计模式实战演练
01简单工厂模式02策略模式07代理模式08工厂方法模式14观察者模式20迭代器模式21单例模式22桥接模式27解释器模式28访问者模式附录1动物练习
2009-12-03
显示当前系统时间锁频获得键盘直
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
this.toolStripStatusLabel1.Text = "当前系统时间是:" + System.DateTime.Now.ToLongTimeString();
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
this.timer1.Stop();
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
//建立进程
Process p = new Process();
p.StartInfo.WorkingDirectory = "c:\\windows\\system32";
p.StartInfo.FileName = "rundll32.exe";
//锁屏命令
p.StartInfo.Arguments = "user32.dll,LockWorkStation";
p.Start();
}
else if (e.Button == MouseButtons.Right)
{
ProcessStartInfo psInfo = new ProcessStartInfo("cmd.exe");
psInfo.RedirectStandardInput = true;
psInfo.UseShellExecute = false;
psInfo.CreateNoWindow = true;
psInfo.RedirectStandardOutput = true;
Process proc = new Process();
proc.StartInfo = psInfo;
proc.Start();
proc.StandardInput.WriteLine("shutdown -r");
}
else
{
this.Close();
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
MessageBox.Show(Convert.ToInt32(e.KeyChar).ToString());
}
private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
}
}
2009-03-14
C#实现的声音录制回放的小程序
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
// PURPOSE.
//
// This material may not be duplicated in whole or in part, except for
// personal use, without the express written consent of the author.
//
// Email: ianier@hotmail.com
//
// Copyright (C) 1999-2003 Ianier Munoz. All Rights Reserved.
using System;
using System.Threading;
using System.Runtime.InteropServices;
namespace WaveLib
{
internal class WaveOutHelper
{
public static void Try(int err)
{
if (err != WaveNative.MMSYSERR_NOERROR)
throw new Exception(err.ToString());
}
}
public delegate void BufferFillEventHandler(IntPtr data, int size);
internal class WaveOutBuffer : IDisposable
{
public WaveOutBuffer NextBuffer;
private AutoResetEvent m_PlayEvent = new AutoResetEvent(false);
private IntPtr m_WaveOut;
private WaveNative.WaveHdr m_Header;
private byte[] m_HeaderData;
private GCHandle m_HeaderHandle;
private GCHandle m_HeaderDataHandle;
private bool m_Playing;
internal static void WaveOutProc(IntPtr hdrvr, int uMsg, int dwUser, ref WaveNative.WaveHdr wavhdr, int dwParam2)
{
if (uMsg == WaveNative.MM_WOM_DONE)
{
try
{
GCHandle h = (GCHandle)wavhdr.dwUser;
WaveOutBuffer buf = (WaveOutBuffer)h.Target;
buf.OnCompleted();
}
catch
{
}
}
}
public WaveOutBuffer(IntPtr waveOutHandle, int size)
{
m_WaveOut = waveOutHandle;
m_HeaderHandle = GCHandle.Alloc(m_Header, GCHandleType.Pinned);
m_Header.dwUser = (IntPtr)GCHandle.Alloc(this);
2009-03-14
《用C#制作飘动的窗体效果》源代码
《用C#制作飘动的窗体效果》源代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace FallingGold
{
public partial class AboutForm : Form
{
public AboutForm()
{
InitializeComponent();
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string url = linkLabel1.Text;
try
{
System.Diagnostics.Process.Start(url);
}
catch (System.ComponentModel.Win32Exception noBrowser)
{
if (noBrowser.ErrorCode == -2147467259) MessageBox.Show(noBrowser.Message);
}
catch (System.Exception exc)
{
MessageBox.Show(exc.Message);
}
}
private void btnOK_Click(object sender, EventArgs e)
{
Dispose();
}
}
}
2009-03-14
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人