標籤: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#文法功能結構