此代码适用于单个选定项目:在顶部:
ContextMenuStrip menuStrip;
Run Code Online (Sandbox Code Playgroud)
然后在构造函数中:
menuStrip = new ContextMenuStrip();
menuStrip.ItemClicked += menuStrip_ItemClicked;
menuStrip.Items.Add("Cut");
menuStrip.Items.Add("Copy");
menuStrip.Items.Add("Paste");
Run Code Online (Sandbox Code Playgroud)
该menuStripitemclicked事件:
ListViewItem item;
private void menuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
if (e.ClickedItem.Text == "Copy")
{
Clipboard.SetText(item.SubItems[1].Text);
}
}
Run Code Online (Sandbox Code Playgroud)
然后ListView鼠标单击事件:
private void lstDisplayHardware_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
item = lstDisplayHardware.GetItemAt(e.X, e.Y);
menuStrip.Show(lstDisplayHardware, e.Location);
}
}
Run Code Online (Sandbox Code Playgroud)
此代码适用于单个选定项目.例如,我单击项目中的项目ListView,右键单击该项目并选择Copy:将所选项目的子项目复制到剪贴板.
但现在我想为多项选择做同样的事情.
因此,如果我使用Ctrl +鼠标左键单击并选择4个项目并Copy从上下文菜单中调用命令,我希望将4个所选项目文本的所有子项目复制到剪贴板中.
例如,我有这些项目:
丹尼你好世界
丹尼尔喜所有
dan rain今天
daniels阳光灿烂的日子
我选择了这些项目:
丹尼·
丹尼尔·
丹·
丹尼尔斯
然后右键单击并单击"复制".当我paste …
我试过这个:
ProcessStartInfo psi = new ProcessStartInfo("https://stackoverflow.com/");
psi.RedirectStandardOutput = false;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
Process.Start(psi);
Run Code Online (Sandbox Code Playgroud)
但我在 Process.Start(psi); 线上遇到异常
Win32Exception 系统找不到指定的文件
如果我更改行 psi.UseShellExecute = true; 然后它就可以工作,但它不会隐藏窗口。
我希望当它打开浏览器时,例如https://stackoverflow.com/,用户将不会随时看到该窗口,但该窗口仍会打开。不是关闭而是隐藏。
尝试谷歌但没有找到有效的解决方案。
Win32Exception 消息:
System.ComponentModel.Win32Exception was unhandled
HResult=-2147467259
Message=The system cannot find the file specified
Source=System
ErrorCode=-2147467259
NativeErrorCode=2
StackTrace:
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at CuteDadyImages.Form1.OpenBroswerTab() in d:\C-Sharp\test\Form1.cs:line 155
at CuteDadyImages.Form1..ctor() in d:\C-Sharp\test\Form1.cs:line 55
at CuteDadyImages.Program.Main() in d:\C-Sharp\test\Program.cs:line 35
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, …Run Code Online (Sandbox Code Playgroud) 这是我的代码只是截取整个屏幕的截图.在它工作几次之后它就抛出了异常.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
namespace Capture_ScreenShots
{
public partial class Form1 : Form
{
string bfbc;
string save_location;
int save_image;
int screenWidth;
int screenHeight;
public Form1()
{
InitializeComponent();
save_location = @"c:\screenshots\sc1\";
timer1.Enabled = true;
timer1.Interval = 200;
save_image = 0;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
save_image = save_image + 1;
bfbc = save_location + …Run Code Online (Sandbox Code Playgroud) 在一次油漆活动中我做了:
List<Point> drawPoints = GetDrawPoints();
if (drawPoints.Count > 1)
{
foreach (Point p in drawPoints)
{
e.Graphics.DrawLine(pen, p.X - 2, p.Y - 2, 4, 4);
}
}
Run Code Online (Sandbox Code Playgroud)
但是不是在后续点之间绘制线条,而是从同一个地方到每个点绘制两条线.
我想用一条线连接所有点.
private void ProcessInfo()
{
string ffMPEG = System.IO.Path.Combine(Application.StartupPath, "ffMPEG.exe");
System.Diagnostics.Process mProcess = null;
System.IO.StreamReader SROutput = null;
string outPut = "";
string filepath = "D:\\source.mp4";
string param = string.Format("-i \"{0}\"", filepath);
System.Diagnostics.ProcessStartInfo oInfo = null;
System.Text.RegularExpressions.Regex re = null;
System.Text.RegularExpressions.Match m = null;
TimeSpan Duration = 0;
//Get ready with ProcessStartInfo
oInfo = new System.Diagnostics.ProcessStartInfo(ffMPEG, param);
oInfo.CreateNoWindow = true;
//ffMPEG uses StandardError for its output.
oInfo.RedirectStandardError = true;
oInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
oInfo.UseShellExecute = false;
// Lets start the process
mProcess …Run Code Online (Sandbox Code Playgroud)