一、语音程序
添加应用 Interop.SpeechLib.dll
下载地址:http://download.csdn.net/detail/jsjyyjs07/4398579
using SpeechLib;
/// <summary>
/// 发音
/// </summary>
/// <param name="content"></param>
void read(object content)
{
try
{
backgroundWorker1.RunWorkerAsync(content);
}
catch (Exception er)
{
MessageBox.Show(er.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
SpeechVoiceSpeakFlags spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpVoice voice = new SpVoice();
voice.Rate = 0;//调整发音语速,可以为负数,如-3,0,5
voice.Speak(e.Argument.ToString(), spFlags);
}
二、在窗体的任意位置拖动窗体
实例一:
private int LEFT = 5, RIGHT = 5, BOTTOM = 5, TOP = 5, TITLE_WIDTH = 45;//边框和标题栏的大小
private MouseAction mouse;//鼠标的事件响应对象
private int x = 0, y = 0;//保存鼠标的临时坐标
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
private void Form2_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
x = e.X;
y = e.Y;
//this.Parent.Cursor = CheckCursorType(e.X, e.Y);//改变鼠标的指针形状
if (mouse != null)
{
mouse.Action(Control.MousePosition.X, Control.MousePosition.Y, this);//执行时间响应
//注意坐标是Control.MousePosition这个静态变量给出的,它的值为鼠标在桌面上的全局坐标
}
//鼠标点击左上边框
if ((e.X <= LEFT + 10 && e.Y <= TOP) || (e.Y <= TOP + 10 && e.X <= LEFT))
{
//mouse = new MouseSizeTopLeft(Location.X, Location.Y, Width, Height);
return;
}
}
private void DrawMiddle_Left(Graphics g)
{
//Brush brush = new TextureBrush(Middle_Left, new Rectangle(0, 0,Middle_Left.Width, Middle_Left.Height));
//g.FillRectangle(brush, 0, TITLE_WIDTH, Middle_Left.Width,Height - Bottom_Middle.Height - TITLE_WIDTH);
}
//定义了一个抽象的基类MouseAction,用来表示所有的鼠标事件,它有一个抽象方法Action
public abstract class MouseAction
{
public abstract void Action(int ScreenX, int ScreenY, System.Windows.Forms.Form form);
}
//向右拉伸窗口事件
public class MouseSizeRight : MouseAction
{
private int lx;
public MouseSizeRight(int LocationX)
{
lx = LocationX;
}
public override void Action(int ScreenX, int ScreenY, System.Windows.Forms.Form form)
{
form.Width = ScreenX - lx;
form.Invalidate();
}
}
//鼠标拖动
public class MouseDrag : MouseAction
{
private int x, y;
public MouseDrag(int hitX, int hitY)
{
x = hitX;
y = hitY;
}
public override void Action(int ScreenX, int ScreenY, System.Windows.Forms.Form form)
{
form.Location = new Point(ScreenX - x, ScreenY - y);
}
}
示例二:
public static Point CPoint;
bool down = false;
private void Form3_MouseDown(object sender, MouseEventArgs e)
{
CPoint = new Point(e.X, e.Y);
down = true;
}
private void Form3_MouseMove(object sender, MouseEventArgs e)
{
if (down == true)
{
if (e.Button == MouseButtons.Left)
{
Point mousePosition = Control.MousePosition;
mousePosition.Offset(-CPoint.X, -CPoint.Y);
this.DesktopLocation = mousePosition;
}
}
}