Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 制造一个五米发射器_C# - Fatal编程技术网

C# 制造一个五米发射器

C# 制造一个五米发射器,c#,C#,我正在尝试为我的FiveM服务器开发一个Laucher,现在我可以从appdata本地文件夹打开FiveM,但是我需要插入服务器ip,以便在游戏开始时执行。我访问了anser,但我无法使其工作 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using Syste

我正在尝试为我的FiveM服务器开发一个Laucher,现在我可以从appdata本地文件夹打开FiveM,但是我需要插入服务器ip,以便在游戏开始时执行。我访问了anser,但我无法使其工作

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.IO;
    using System.Net;
    using System.Net.Sockets;

    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {

            }

        private void label1_Click(object sender, EventArgs e)
        {
            Process p = new Path(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            //string appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            System.Net.IPAddress ipaddress = System.Net.IPAddress.Parse("http:127.0.0.1");
            //test, comment the next line out
            MessageBox.Show(System.IO.Path.Combine(appData, @"FiveM\test.exe" + ipaddress));
            p.StartInfo (@"FiveM\test.exe")                


        }

这里您试图将路径(“C:\ProgramData\YourProgram”)转换为进程。这行不通

Process p = new Path(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
//string appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
这里您正在创建一个IP对象

System.Net.IPAddress ipaddress = System.Net.IPAddress.Parse("http:127.0.0.1");
//test, comment the next line out
这里显示的是一个带有一些文本的消息框
appData
是一个未注释的变量

MessageBox.Show(System.IO.Path.Combine(appData, @"FiveM\test.exe" + ipaddress));
这里您试图启动一个方法
StartInfo()
,它是一个属性

p.StartInfo (@"FiveM\test.exe")
这真的不是工作代码

如何运行Exe?试试这个:

// Create some textfile in C:\Temp ..
string testFile = @"C:\Temp\test.txt";
using (File.Create(testFile))
{

}

// Choose the program to start. Path.Combine combines Paths, Directories and Filenames to one Path.
string path = Path.Combine(@"C:\Windows\System32", "notepad.exe");

// Your exe should have some arguments. In your case an IP-address i guess. If we start notepad we can tell him which file it should open.
string arguments = testFile;

// Start an exe with an argument
Process p = Process.Start(path, arguments);
// You would do the same if you push "Ctrl+R" and enter "C:\Windows\System32\Notepad.exe C:\Temp\test.txt"

// An now we tell our program to wait until the Process is closed..
p.WaitForExit();

如果你想继续编程。你应该做一些教程;-)

如果您想要一个直接连接到您输入的服务器IP的按钮,您可以这样做

private void Button_Click_3(object sender, RoutedEventArgs e) {
    System.Diagnostics.Process.Start("fivem://connect/185.113.141.24:30120");
}

欢迎来到堆栈溢出!看来你的主要问题是如何用参数启动一个外部过程。但是,由于各种原因,例如使用属性作为方法和分配不匹配的类型,您的代码无法编译。查看有关如何启动外部流程的详细信息。如果您仍在挣扎,请使用编译的代码更新您的问题。当您单击按钮时,它将直接连接到服务器ip,在本例中为“185.113.141.24:30120”