在窗体上有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.   


    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;//获得需要播放的文件名 播放的时候加上路径
        //播放的代码自己搞定吧,上网搜搜
    }
      

  2.   

    那都是没有实现的功能`  指定按钮播放录像`这个我会的`  就是写成方法~~  第一个方法用来从目录下获取录像的名字传给label的text属性`  别一个方法是根据label的属性进行播放~~ 比如说第一个label的名字为eee.exe那点当我点击的时候就会播放eee.exe这个目录像`  这些录像都看过以后`我再把目录下的录像换成新的`程序会自动读取~也可以播放~  明白了吧  急啊  接着等
      

  3.   

    哎~ 搞了半天是把目录的exe 遍历了一遍`  就出现一个录像在窗体上`  现在的问题是1` 我在加载的时候怎么把~所有的EXE可执行文件都放到窗体上~  2、如何确定位置~  就是读到文件以后放到窗体上的位置` 3、路径问题
    这是代码  请看下: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++;
    }

    }
    }
    }
      

  4.   

    你跟踪调试下
    看看string[] files = Directory.GetFiles( @"E:\执行外部EXE\WindowsApplication1\bin","*.exe"); 
    这句一共得到几个文件
    lab.Location = new Point(x, y + 10 * i); 
    这句是设置Label的坐标的
    如果没有这句那所有的Label 就会重叠在一个地方
      

  5.   

    如果你的文件可能有中文的
    那你最好设置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()); 
      

  6.   

    另外我这个代码就是动态生成Label了,你可以把你的那6个Label都去掉至于坐标就是Location属性
    按照你想排列的位置自己去设置吧
      

  7.   

    string file = Path.Combine(@"E:\执行外部EXE\WindowsApplication1\bin",control.Tag.ToString()); 
    ---》
    string file = Path.Combine(@"E:\执行外部EXE\WindowsApplication1\bin",control.Tag.ToString() + ".exe");