fff
This commit is contained in:
@@ -20,6 +20,7 @@ namespace Reader
|
||||
{
|
||||
".doc", ".docx", ".pdf", ".ppt", ".pptx"
|
||||
};
|
||||
private MouseButtons lastGridMouseButton = MouseButtons.Left;
|
||||
|
||||
static MainForm()
|
||||
{
|
||||
@@ -33,6 +34,8 @@ namespace Reader
|
||||
public MainForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
dgv.CellMouseDown += dgv_CellMouseDown;
|
||||
dgv.CellMouseClick += dgv_CellMouseClick;
|
||||
}
|
||||
|
||||
private void btnBrowse_Click(object sender, EventArgs e)
|
||||
@@ -99,6 +102,7 @@ namespace Reader
|
||||
}
|
||||
var rowIndex = dgv.Rows.Add(fileName, up, down);
|
||||
dgv.Rows[rowIndex].Tag = entry.FilePath;
|
||||
dgv.Rows[rowIndex].Cells["Filename"].ToolTipText = entry.FilePath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +124,7 @@ namespace Reader
|
||||
private void MainForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
|
||||
dgv.ShowCellToolTips = true;
|
||||
dgv.Columns["Filename"].Width = 500;
|
||||
dgv.Columns["eryi_ID"].Width = 100;
|
||||
dgv.Columns["下载者用户名"].Width = 100;
|
||||
@@ -127,9 +132,39 @@ namespace Reader
|
||||
|
||||
private void dgv_CellClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (lastGridMouseButton == MouseButtons.Right)
|
||||
{
|
||||
return;
|
||||
}
|
||||
HandleGridClick(e);
|
||||
}
|
||||
|
||||
private void dgv_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
|
||||
{
|
||||
lastGridMouseButton = e.Button;
|
||||
}
|
||||
|
||||
private void dgv_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
|
||||
{
|
||||
if (e.RowIndex < 0 || e.ColumnIndex < 0 || e.Button != MouseButtons.Right)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var columnName = dgv.Columns[e.ColumnIndex].Name;
|
||||
if (columnName != "Filename")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var row = dgv.Rows[e.RowIndex];
|
||||
var filePath = row.Tag as string;
|
||||
if (!string.IsNullOrWhiteSpace(filePath) && File.Exists(filePath))
|
||||
{
|
||||
OpenFolderAndSelectFile(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleGridClick(DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (e.RowIndex < 0 || e.ColumnIndex < 0)
|
||||
@@ -158,6 +193,24 @@ namespace Reader
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void OpenFolderAndSelectFile(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "explorer.exe",
|
||||
Arguments = $"/select,\"{filePath}\"",
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("打开文件所在位置失败: " + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private static void OpenWithShell(string target)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user