Ejemplo n.º 1
0
        public void AddListBoxItem(string p)
        {
            //if(File.Exists(p))
            //{
            //    FileInfo fi = new FileInfo(p);
            //    p = fi.Name;

            //    //FileInfo.Exists:获取指定文件是否存在;
            //    //FileInfo.Name,FileInfo.Extensioin:获取文件的名称和扩展名;
            //    //FileInfo.FullName:获取文件的全限定名称(完整路径);
            //    //FileInfo.Directory:获取文件所在目录,返回类型为DirectoryInfo;
            //    //FileInfo.DirectoryName:获取文件所在目录的路径(完整路径);
            //    //FileInfo.Length:获取文件的大小(字节数);
            //    //FileInfo.IsReadOnly:获取文件是否只读;
            //    //FileInfo.Attributes:获取或设置指定文件的属性,返回类型为FileAttributes枚举,可以是多个值的组合
            //    //FileInfo.CreationTime、FileInfo.LastAccessTime、FileInfo.LastWriteTime:分别用于获取文件的创建时间、访问时间、修改时间;
            //}
            if (listBox1.InvokeRequired)
            {
                AddListBoxItemDelegate d = AddListBoxItem;
                listBox1.Invoke(d, p);
            }
            else
            {
                listBox1.Items.Add(p);
            }
        }
Ejemplo n.º 2
0
        public void Log(string format, params object[] variableArguments)
        {
            try
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendFormat(format, variableArguments);
                builder.Append("\r\n");

                if (lbLog.InvokeRequired)
                {
                    // This is a worker thread so delegate the task.
                    AddListBoxItemDelegate addItemDelegate = new AddListBoxItemDelegate(this.Log);
                    lbLog.Invoke(addItemDelegate, format, variableArguments);
                }
                else
                {
                    // This is the UI thread so perform the task.
                    int idx = lbLog.Items.Add(builder.ToString());
                    lbLog.SetSelected(idx, true);
                }
            }
            catch (Exception ex)
            {
                lbLog.Items.Add(String.Format("Caught exception: {0}", ex.Message));
            }
        }
Ejemplo n.º 3
0
 public void AddListBoxItem(string p)
 {
     if (listBox1.InvokeRequired)
     {
         AddListBoxItemDelegate d = AddListBoxItem;
         listBox1.Invoke(d, p);
     }
     else
     {
         listBox1.Items.Add(p);
     }
 }
Ejemplo n.º 4
0
 private void AddItem(ListBox listbox, string text)
 {
     if (listbox.InvokeRequired)
     {
         AddListBoxItemDelegate d = AddItem;
         listbox.Invoke(d, new object[] { listbox, text });
     }
     else
     {
         listbox.Items.Add(text);
         listbox.SelectedIndex = listbox.Items.Count - 1;
         listbox.ClearSelected();
     }
 }
Ejemplo n.º 5
0
 private void AddListBoxItem(ListBox listbox, string str)
 {
     if (listbox.InvokeRequired)
     {
         AddListBoxItemDelegate d = new AddListBoxItemDelegate(AddListBoxItem);
         listbox.Invoke(d, new object[] { listbox, str });
     }
     else
     {
         listbox.Items.Add(str);
         listbox.SelectedIndex = listbox.Items.Count - 1;
         listbox.ClearSelected();
     }
 }