【发布时间】:2014-12-18 00:41:50
【问题描述】:
我有一个可以动态创建用户控件的表单,每个用户控件都有一个开始按钮和一个停止按钮。有没有办法在表单上设置全部开始和全部停止按钮?
我尝试在单击主窗体按钮时设置一个布尔值,但一旦创建了用户控件,它就不会检查布尔值。
这里是主窗体的代码(vdoPlayer 是用户控件):
namespace AutoPopulateVideoSaving
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DisplayImage();
}
private void DisplayImage()
{
int h = 20;
for (int i = 0; i < 6; i++)
{
int w = i % 2;
vdoPlayer np = new vdoPlayer();
np.Location = new System.Drawing.Point((33 + 408 * w), h);
np.Name = "test" + i.ToString();
np.Size = new System.Drawing.Size(408, 266);
this.Controls.Add(np);
h = h + (266 * w);
}
}
private void StartAllBut_Click(object sender, EventArgs e)
{
}
private void StopAllBut_Click(object sender, EventArgs e)
{
}
}
}
这是用户控件的代码:
namespace AutoPopulateVideoSaving
{
public partial class vdoPlayer : UserControl
{
public vdoPlayer()
{
InitializeComponent();
VariableClass2.InitiateVariables();
JPEGStream jpegSource1 = new JPEGStream("http:// IP address /jpg/image.jpg?resolution=320x240");
jpegSource1.Login = username;
jpegSource1.Password = password;
jpegSource1.NewFrame += new NewFrameEventHandler(jpegSource1_NewFrame);
jpegSource1.VideoSourceError += new VideoSourceErrorEventHandler(jpegSource1_VideoSourceError);
Player1.VideoSource = jpegSource1;
}
void jpegSource1_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap image = new Bitmap(eventArgs.Frame, 320, 240);
image.Save(someFile, System.Drawing.Imaging.ImageFormat.Bmp);
}
void jpegSource1_VideoSourceError(object sender, VideoSourceErrorEventArgs eventArgs)
{
//Error handler
Debug.WriteLine(eventArgs.Description);
}
private void StartBut_Click(object sender, EventArgs e)
{
Player1.VideoSource.Start();
}
private void StopBut_Click(object sender, EventArgs e)
{
Player1.VideoSource.Stop();
}
}
}
我不知道在 Form1 的按钮单击事件中放置什么来控制其余部分。就像我之前说的,我尝试使用布尔值,但它不起作用。这甚至可能吗?
【问题讨论】:
标签: c# forms user-controls