C#文法功能結構

來源:互聯網
上載者:User

標籤:startup   index   move   讀取   rest   enter   toolstrip   top   message   

1、File
開啟指定檔案夾或者檔案,“\”為逸出字元
System.Diagnostics.Process.Start(Application.StartupPath + "\\Document\\資源管理員\\");

複製檔案到指定目錄下

 ToolStripItem Strip = sender as ToolStripItem;
 string stripValue = Strip.Text.ToString();
 switch (stripValue)
 {
  case "自訂":
   OpenFileDialog h_OpenFile = new OpenFileDialog();
   h_OpenFile.Filter = "png檔案|*.png";
   h_OpenFile.InitialDirectory = "E:\\";
   if (h_OpenFile.ShowDialog() == DialogResult.OK)
   {
      h_OpenFile.RestoreDirectory = true;
      var pathBefore = h_OpenFile.FileName.Substring(h_OpenFile.FileName.LastIndexOf("\\") + 1);
      var fileName = pathBefore.Substring(0, pathBefore.LastIndexOf("."));
      contextMenuStrip1.Items.Add(fileName).Click += ToolStripMenuItem_Click;

      FileInfo fileInfo = new FileInfo(h_OpenFile.FileName);
      string appPath = Application.StartupPath + "\\Images\\Theme\\";
      try
      {
         File.Copy(h_OpenFile.FileName, appPath + fileInfo.Name);
      }
      catch (Exception ex)
      {
         MessageBox.Show("檔案已經存在!");
      }
      finally
      {
         h_OpenFile.Dispose();
      }
   }
 break;
 default:
  try
  {
     this.BackgroundImage = Image.FromFile(Application.StartupPath + "\\Images\\Theme\\" + stripValue + ".png");
  }
  catch (Exception ex)
  {
     MessageBox.Show("背景不存在");
     this.contextMenuStrip1.Items.Remove(Strip);
  }
 break;
}

讀取指定路徑下的檔案夾並且遍曆目錄下的檔案
string strPath = string.Format(Application.StartupPath + "\\Document\\資源管理員\\5、報表範本\\");DirectoryInfo directoryName = new DirectoryInfo(strPath);foreach (FileInfo NextFile in directoryName.GetFiles()){ listViewEx1.Items.Add(NextFile.ToString(), 0);}

  

2、PictureBox
設定PictureBox背景圖片為DeBug目錄下的檔案圖片
pictureBox.BackgroundImage = Image.FromFile(Application.StartupPath + "\\Images\\彈窗類別\\" + "工作模版2.png");
3、ListView
擷取listview選中項的首項
listView.FocusedItem.SubItems[0].Text;
滑鼠拖拽實現

  //表單允許拖拽
  this.AllowDrop = true;
  //listview允許拖拽
  this.listViewEx1.AllowDrop = true;
  //訂閱項拖拽事件
  this.listViewEx1.ItemDrag += listViewEx1_ItemDrag;
  //訂閱拖入項事件
  this.listViewEx1.DragEnter += listViewEx1_DragEnter;

4、String
"Jackie"+"Aillo"和String.Format("{0}{1}","Jackie", "Aillo")
5、Point
擷取控制項相對父元素的座標
if (this.Width-20< e.X&&e.X<this.Width&&e.Y>panel2.Top&&e.Y<panel2.Top+panel2.Height) { panel2.Visible = true; } if (this.Height - 20 < e.Y && e.Y < this.Height&&e.X>this.Width-panel2.Width&&e.X<this.Width) { this.panel2.Visible = false; }
6、MessageBox
判斷使用者是否點擊確定按鈕
if(DialogResult.OK == MessageBox.Show("確定刪除嗎?", "提示", MessageBoxButtons.OKCancel))
{}

 

C#文法功能結構

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.