在窗体上有10个label 在程序的bin目录下有四个录像,
1、当程序加载的时候 10个label中会有4个label显示录像的名字 其它的label不会显示东西(就是说哪个label有值就为可见没有就为不可见,在窗体加载的时候从目录下读取这些录像的名字例如:1.exe有几个就读几天按一定的顺序把读到的名字传给label的text属性)
2、当点击相应的label的时候 就会播放相应的录像(假如第一个label的名字是haha,那么点击它的时候就会播放名字为haha.exe的录像`也就是说实现绑定~)3,弄完以后要求是`当我变换目录下的录像时`还能达到这种效果~ 比如我现在又加进去了三个录像`也就是变为了7个录像`那么则会有7个label显示出来4\要用循环来解决,(给label付值为一个循环方法,实现点击哪个label播放哪个录像为一个循环方法)
一定给会~ 解决问题马上给分~我就50分了全部给~要是不够我再去申请号去~ 先谢过了` 最好有一个例子`416700390@qq.com .NET03
1、当程序加载的时候 10个label中会有4个label显示录像的名字 其它的label不会显示东西(就是说哪个label有值就为可见没有就为不可见,在窗体加载的时候从目录下读取这些录像的名字例如:1.exe有几个就读几天按一定的顺序把读到的名字传给label的text属性)
2、当点击相应的label的时候 就会播放相应的录像(假如第一个label的名字是haha,那么点击它的时候就会播放名字为haha.exe的录像`也就是说实现绑定~)3,弄完以后要求是`当我变换目录下的录像时`还能达到这种效果~ 比如我现在又加进去了三个录像`也就是变为了7个录像`那么则会有7个label显示出来4\要用循环来解决,(给label付值为一个循环方法,实现点击哪个label播放哪个录像为一个循环方法)
一定给会~ 解决问题马上给分~我就50分了全部给~要是不够我再去申请号去~ 先谢过了` 最好有一个例子`416700390@qq.com .NET03
解决方案 »
- 添加引用出现叹号,怎么解决
- 请问怎样捕获webbrowser新窗口的URL?
- 主窗体弹出一个新窗体后,主窗体的线程还能起作用吗?
- TreeView的checkbox问题,还有个小问题解决不了,请求各位高手解决下(急!)
- 怎样调用oleDB的“数据链接属性”对话框?
- .net中文件隐式上传和下载(急急急)
- 哈希解密问题??????????????
- 求C#+SQL2000做的试题库管理系统
- [向net提问] winform中怎么让界面从有到无-------从无到有求代码,环境C# vs.net2005
- 救命啊!!!C#今天的第2个问题!! 很急,求各位高手解答!! 我都摸了一天了 ,求各位发发慈悲 ,救救我!!!
- 请问水晶报表中sumif表达式如何写?在线等
- 部署安装程序的问题
string filePath = "你的路径";
string[] files = Directory.GetFiles(filePath,"你的扩展名");
int x = 10;
int y = 10;
int i = 0;
foreach (string file in files)
{
Label lab = new Label();
lab.Name = Path.GetFileNameWithoutExtension(file);
lab.Text = lab.Name;
lab.Location = new Point(x, y + 10 * i);
lab.Tag = Path.GetExtension(file);
lab.Click += new EventHandler(lab_Click);
this.Controls.Add(lab);
i++;
}private void lab_Click(object sender, EventArgs e)
{
Control control = sender as Control;
string name = control.Name;
string extension = control.Tag.ToString();
string file = name + extension;//获得需要播放的文件名 播放的时候加上路径
//播放的代码自己搞定吧,上网搜搜
}
这是代码 请看下:using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace WindowsApplication1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(64, 176);
this.label1.Name = "label1";
this.label1.TabIndex = 1;
//
// label2
//
this.label2.Location = new System.Drawing.Point(64, 232);
this.label2.Name = "label2";
this.label2.TabIndex = 2;
//
// label3
//
this.label3.Location = new System.Drawing.Point(192, 184);
this.label3.Name = "label3";
this.label3.TabIndex = 3;
//
// label4
//
this.label4.Location = new System.Drawing.Point(192, 232);
this.label4.Name = "label4";
this.label4.TabIndex = 4;
//
// label5
//
this.label5.Location = new System.Drawing.Point(328, 232);
this.label5.Name = "label5";
this.label5.TabIndex = 5;
//
// label6
//
this.label6.Location = new System.Drawing.Point(320, 176);
this.label6.Name = "label6";
this.label6.TabIndex = 6;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(456, 318);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void lab_Click(object sender, EventArgs e)
{
Control control = sender as Control;
string name = control.Name;
string extension = control.Tag.ToString();
string file = name + extension;//获得需要播放的文件名
System.Diagnostics.Process.Start(@"E:\执行外部EXE\WindowsApplication1\bin\会员充值.exe");
}
private void Form1_Load(object sender, System.EventArgs e)
{
string[] files = Directory.GetFiles( @"E:\执行外部EXE\WindowsApplication1\bin","*.exe");
int x = 10;
int y = 10;
int i = 1;
foreach (string file in files)
{ Label lab = new Label();
lab.Name = Path.GetFileNameWithoutExtension(file);
lab.Text = lab.Name;
lab.Location = new Point(x, y + 10 * i);
lab.Tag = Path.GetExtension(file);
lab.Click += new EventHandler(lab_Click);
this.Controls.Add(lab);
i++;
}
}
}
}
看看string[] files = Directory.GetFiles( @"E:\执行外部EXE\WindowsApplication1\bin","*.exe");
这句一共得到几个文件
lab.Location = new Point(x, y + 10 * i);
这句是设置Label的坐标的
如果没有这句那所有的Label 就会重叠在一个地方
那你最好设置Label的Name的属性的时候设置成
lab.Name = "lbl" + i;
lab.Tag = Path.GetFileNameWithoutExtension(file);
然后再Click事件里面Control control = sender as Control;
string file = Path.Combine(@"E:\执行外部EXE\WindowsApplication1\bin",control.Tag.ToString());
System.Diagnostics.Process.Start(file); 当然路径不应该这么写死
文件夹名称应该是Application.StartupPath即
string[] files = Directory.GetFiles( Application.StartupPath,"*.exe"); string file = Path.Combine(Application.StartupPath,control.Tag.ToString());
按照你想排列的位置自己去设置吧
---》
string file = Path.Combine(@"E:\执行外部EXE\WindowsApplication1\bin",control.Tag.ToString() + ".exe");