using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
namespace youlaiyouqu
{
public partial class Form1 : Form
{ public Form1()
{
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
th = new Thread(new ThreadStart(run));
th.IsBackground = true;
}
Thread th;
public void run()
{
while (true)
{
for (int i = 0; i <= 32; i++)
{
this.pictureBox1.Left = this.pictureBox1.Left + i;
Thread.Sleep(122);
}
for (int i = 0; i < 26; i++)
{
this.pictureBox1.Top = this.pictureBox1.Top + i;
Thread.Sleep(100);
}
for (int i = 0; i <= 32; i++)
{
this.pictureBox1.Left = this.pictureBox1.Left - i;
Thread.Sleep(122);
}
for (int i = 0; i < 26; i++)
{
this.pictureBox1.Top = this.pictureBox1.Top - i;
Thread.Sleep(100);
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (th != null)
{
th.Abort();
}
}
private void button1_Click(object sender, EventArgs e)
{
if (this.button1.Text == "开始")
{ this.button1.Text = "暂停";
th.Start();
this.button2.Enabled = true; }
else if (this.button1.Text == "暂停")
{
this.button1.Text = "继续";
th.Suspend();
this.button2.Enabled = false;
}
else if (this.button1.Text == "继续")
{
this.button1.Text = "暂停";
th.Resume();
this.button2.Enabled = true;
}
} private void button2_Click(object sender, EventArgs e)
{
if(this.button2.Text=="停止")
{
th.Abort();
this.button1.Text = "开始";
th = new Thread(new ThreadStart(run));
th.IsBackground = true;
}
this.button1.Enabled = true;
}
private void Form1_Load(object sender, EventArgs e)
{
//OpenFileDialog ofDialog = new OpenFileDialog();
//ofDialog.AddExtension = true;
//ofDialog.CheckFileExists = true;
//ofDialog.CheckPathExists = true;
//ofDialog.Filter = "swf 文件 (*.swf)|*.swf|所有文件 (*.*)|*.*";
//ofDialog.DefaultExt = "mp3";
//if (ofDialog.ShowDialog() == DialogResult.OK)
//{
// // 设定播放的文件名
// this.axShockwaveFlash1.Movie = ofDialog.FileName;
// // 播放flash文件
// this.axShockwaveFlash1.Play();
//}
this.button1.Enabled = true;
this.button2.Enabled = false;
}
当我点开始 再点下就暂停 暂停后再点下停止 就报错 挂起的无法停止 怎么解决 还有在窗体背景中怎么插flash 和背景 音乐 网上找半天 都没看明白咋样插的 我注释了 可以帮小弟 写清楚么?
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
namespace youlaiyouqu
{
public partial class Form1 : Form
{ public Form1()
{
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
th = new Thread(new ThreadStart(run));
th.IsBackground = true;
}
Thread th;
public void run()
{
while (true)
{
for (int i = 0; i <= 32; i++)
{
this.pictureBox1.Left = this.pictureBox1.Left + i;
Thread.Sleep(122);
}
for (int i = 0; i < 26; i++)
{
this.pictureBox1.Top = this.pictureBox1.Top + i;
Thread.Sleep(100);
}
for (int i = 0; i <= 32; i++)
{
this.pictureBox1.Left = this.pictureBox1.Left - i;
Thread.Sleep(122);
}
for (int i = 0; i < 26; i++)
{
this.pictureBox1.Top = this.pictureBox1.Top - i;
Thread.Sleep(100);
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (th != null)
{
th.Abort();
}
}
private void button1_Click(object sender, EventArgs e)
{
if (this.button1.Text == "开始")
{ this.button1.Text = "暂停";
th.Start();
this.button2.Enabled = true; }
else if (this.button1.Text == "暂停")
{
this.button1.Text = "继续";
th.Suspend();
this.button2.Enabled = false;
}
else if (this.button1.Text == "继续")
{
this.button1.Text = "暂停";
th.Resume();
this.button2.Enabled = true;
}
} private void button2_Click(object sender, EventArgs e)
{
if(this.button2.Text=="停止")
{
th.Abort();
this.button1.Text = "开始";
th = new Thread(new ThreadStart(run));
th.IsBackground = true;
}
this.button1.Enabled = true;
}
private void Form1_Load(object sender, EventArgs e)
{
//OpenFileDialog ofDialog = new OpenFileDialog();
//ofDialog.AddExtension = true;
//ofDialog.CheckFileExists = true;
//ofDialog.CheckPathExists = true;
//ofDialog.Filter = "swf 文件 (*.swf)|*.swf|所有文件 (*.*)|*.*";
//ofDialog.DefaultExt = "mp3";
//if (ofDialog.ShowDialog() == DialogResult.OK)
//{
// // 设定播放的文件名
// this.axShockwaveFlash1.Movie = ofDialog.FileName;
// // 播放flash文件
// this.axShockwaveFlash1.Play();
//}
this.button1.Enabled = true;
this.button2.Enabled = false;
}
当我点开始 再点下就暂停 暂停后再点下停止 就报错 挂起的无法停止 怎么解决 还有在窗体背景中怎么插flash 和背景 音乐 网上找半天 都没看明白咋样插的 我注释了 可以帮小弟 写清楚么?
{ OpenFileDialog ofDialog = new OpenFileDialog();
ofDialog.AddExtension = true;
ofDialog.CheckFileExists = true;
ofDialog.CheckPathExists = true;
ofDialog.Filter = "swf 文件 (*.swf)|*.swf|所有文件 (*.*)|*.*";
ofDialog.DefaultExt = "mp3";
if(ofDialog.ShowDialog() == DialogResult.OK)
{
this.axShockwaveFlash1.Movie = ofDialog.FileName;
this.axShockwaveFlash1.Play();
}
}
点击“浏览”键,然后选择“c:\\WINNT(WINDOWS)\\system32\\MacromedFlashswflash.ocx" 控件
找到眼都花了 也没看见~~~~~~~~~~~~~~~
ShockwaveFlash 播放flash时背景透明疑难使用BackgroundColor這個屬性改为-1 來改變ShockwaveFlash元件的背景顏色在设计窗口中为白色 但是打开程序窗体后还是全黑的 下面的一些元件全覆盖啦 不知道咋办 怎么让ShockwaveFlash元件播放flash时背景透明 flash为最底层
暂停和恢复微软已经不建议用Abort和Resume方法,你编译的时候应该有警告
我给个暂停的例子吧using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;namespace AutoResetEventTest
{
public partial class Form1 : Form
{
private ManualResetEvent manualResetEvent;
private AutoResetEvent auto;
private bool suspend;
private AsyncOperation asyncOperation; public delegate void InvokeDelegate(string str); private InvokeDelegate invokeDelegate;
const string str = "Test";
private bool formClosed; public Form1()
{
InitializeComponent();
manualResetEvent = new ManualResetEvent(false);
auto = new AutoResetEvent(true);
asyncOperation = AsyncOperationManager.CreateOperation(null);
invokeDelegate = new InvokeDelegate(this.SafeInvoke);
this.FormClosed += delegate
{
this.formClosed = true;
this.auto.Close();
};
} private void btnStart_Click(object sender, EventArgs e)
{
this.btnStart.Enabled = false;
this.btnSuspend.Enabled = true;
ThreadPool.QueueUserWorkItem(delegate
{
SafeInvoke(); //this.BeginInvoke(invokeDelegate, new object[] { str });
});
} private void btnSuspend_Click(object sender, EventArgs e)
{
this.btnSuspend.Enabled = false;
this.btnResume.Enabled = true;
this.suspend = true;
manualResetEvent.Reset();
} private void SafeInvoke(string s)
{
while (true)
{
if (formClosed)
return; Thread.Sleep(200); if (suspend)
this.auto.WaitOne();
this.txtMessageBox.AppendText(s);
}
} private void SafeInvoke()
{
while (true)
{
if (formClosed)
return; Thread.Sleep(200); if (suspend)
//this.auto.WaitOne();
manualResetEvent.WaitOne(); asyncOperation.Post(delegate
{
this.txtMessageBox.AppendText(str);
}, str);
} } private void btnResume_Click(object sender, EventArgs e)
{
this.btnResume.Enabled = false;
this.btnSuspend.Enabled = true;
this.suspend = false;
//this.auto.Set();
manualResetEvent.Set();
}
}
}
//static AutoResetEvent ChangeEvent = new AutoResetEvent(false);
static ManualResetEvent myResetEvent = new ManualResetEvent(false);
static ManualResetEvent ChangeEvent = new ManualResetEvent(false);
myResetEvent.set(); myResetEvent.Reset();