foreach (object item in listBox1.SelectedItems)
{
string curItem = item.ToString();
var parts = curItem.Split("{}XY=, ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
var xCoord = float.Parse(parts[0]);
var yCoord = float.Parse(parts[1]);
var point = new PointF(xCoord, yCoord);
CloudEnteringAlert.pointtocolor.Add(point);
pictureBox1.Invalidate();
}
Run Code Online (Sandbox Code Playgroud)
curItem 变量包含如下值:Cloud detected at: 0.9174312 Kilometers from the coast.
我只想从值中获取0.9174312并将其设置在变量 xCoord 中。问题是它现在进行解析的方式出现错误:
Input string was not in a correct format
我猜索引不应该为零。如何从字符串中只获取浮点数?
现在这个字符串格式每次都是相同的:
第一部分: Cloud detected at: Second part: 0.9174312 and Last part: Kilometers from the coast.
但也许将来我会更改字符串格式,所以我需要在任何地方浮点数将位于字符串的中间最后或开头以仅获取浮点数。
在 form1 中我有一个方法 DoRequest:
void DoRequest(ScreenshotRequest.DannysCommands cmd)
{
progressBar1.Invoke(new MethodInvoker(delegate()
{
if (progressBar1.Value < progressBar1.Maximum)
{
progressBar1.PerformStep();
_captureProcess.BringProcessWindowToFront();
// Initiate the screenshot of the CaptureInterface, the appropriate event handler within the target process will take care of the rest
_captureProcess.CaptureInterface.BeginGetScreenshot(new Rectangle(int.Parse(txtCaptureX.Text), int.Parse(txtCaptureY.Text), int.Parse(txtCaptureWidth.Text), int.Parse(txtCaptureHeight.Text)), new TimeSpan(0, 0, 2), Callback,cmd);
}
else
{
end = DateTime.Now;
txtDebugLog.Text = String.Format("Debug: {0}\r\n{1}", "Total Time: " + (end-start).ToString(), txtDebugLog.Text);
}
})
);
}
Run Code Online (Sandbox Code Playgroud)
然后我在 form1 的两个地方在按钮单击事件中调用此方法:
DoRequest(ScreenshotRequest.DannysCommands.Displayoverlays);
Run Code Online (Sandbox Code Playgroud)
我得到的错误是在 form1 的这个方法中:
void Callback(IAsyncResult result)
{ …Run Code Online (Sandbox Code Playgroud) 我将计时器刻度事件设置为250毫秒:
private void timer4_Tick(object sender, EventArgs e)
{
if (pictureboximagestosavecount == 72)
{
timer4.Enabled = false;
}
else
{
Bitmap bmp = new Bitmap(this.Width, this.Height);
Rectangle rect = new Rectangle(this.Location.X, this.Location.Y, this.Width, this.Height);
pictureboximagestosavecount++;
savePictureBox(pictureBox1, @"c:\temp\pboximages\" + pictureboximagestosavecount.ToString("D6") + "pbimg.gif");
this.DrawToBitmap(bmp, rect);
bmp.Save(@"c:\temp\pboximages\" + pictureboximagestosavecount.ToString("D6") + "form.gif");
}
}
Run Code Online (Sandbox Code Playgroud)
首先,我使用savePictureBox方法将pictureBox保存为gif.其次我保存form1:
bmp.Save(@"c:\temp\pboximages\" + pictureboximagestosavecount.ToString("D6") + "form.gif");
Run Code Online (Sandbox Code Playgroud)
在timer4停止后,我有一个基本点击事件,我从保存的文件中创建动画gif:
private void animatedgifbutton_Click(object sender, EventArgs e)
{
DirectoryInfo di1;
FileInfo[] fi1;
di1 = new DirectoryInfo(@"c:\temp\pboximages\");
fi1 = di1.GetFiles("*form.gif");
List<string> newImages = new List<string>();
for …Run Code Online (Sandbox Code Playgroud)