求救:C#中窗体怎么关闭?
发布网友
发布时间:2022-12-09 22:27
我来回答
共4个回答
热心网友
时间:2024-12-02 23:03
你把你要关的那个窗体传过来 应该可以把!
string json = "{ \"header\": { \"messagename\": \"UpdateReticleFromMes\", \"eventuser\": \"ok\", \"facilityid\": \"ok\", \"transactionid\": \"2021030318280000001\", \"originalsourcesubjectname\": \"ok\" }, \"body\": \"{ \\\"RETICLE_ID\\\" : \\\"061600-177AA-1WB\\\", \\\"CURRENT_LOCATION\\\" : \\\"RACK02-01-03\\\" }\" }";
string url = "http://47.116.119.6:18080/infactory/rest/api/Invoke";
string type = "POST";
string result = "";
string transacionid = DateTime.Now.ToString("yyyyMMddHHmmssfff");
Encoding encoding = Encoding.UTF8;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);//webrequest请求api地址
//request.Accept = "text/html,application/xhtml+xml,*/*";
request.ContentType = "application/json;charset=UTF-8";
request.Method = type.ToUpper().ToString();//get或者post
request.Headers.Add("Authorization", "Basic QURNSU5AUlRNUzptYW5hZ2Vy");
//Basic QURNSU5AUIRNUzptYW5hZ2Vy
//Basic QURNSU5AUlRNUzptYW5hZ2Vy
byte[] buffer = encoding.GetBytes(json);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
result = reader.ReadToEnd();
}
Console.Write(result);
JObject jt = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(result);
Console.WriteLine("body:" + jt["body"]);
Console.WriteLine();
Console.WriteLine("return:" + jt["return"]);
Console.WriteLine();
Console.WriteLine("return-returnmessage:" + jt["return"]["returnmessage"]);
Console.WriteLine();
Console.WriteLine("return-returncode:" + jt["return"]["returncode"]);
Console.ReadLine();
热心网友
时间:2024-12-02 23:04
你需要在这个窗体中能够获取到要关闭的那个窗体的实例才行
比如你可以在创建后者的时候,把后者的实例传到前者中(当然如果后者是前者创建的就简单多了),然后你就可以通过操作这个实例来关闭它(实例就是这个窗体本身)追问那如果用form1里面的按钮关闭form2,要怎么写代码?
不好意思,我是初学者,您说的不是很懂,能不能说简单点。
热心网友
时间:2024-12-02 23:04
两种方法可以实现,委托或者自定义消息。请看参考资料“C# 委托实例(跨窗体操作控件)”。不明白再问
参考资料:http://blog.csdn.net/bdstjk?viewmode=contents
热心网友
时间:2024-12-02 23:05
Form1 f1=new Form1();
Form2 f2=new Form2(f1);
f2.buttonclose_click{this.f1.close()}