c#编纂的窗体程序,动态生成的checkbox的tag值传递给其他窗体
c#编写的窗体程序,动态生成的checkbox的tag值传递给其他窗体
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://192.168.0.111/AssPrj/netLoginAction_selectAppInfo.action");//创建一个请求示例
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader sr = new StreamReader(stream);
string html = sr.ReadToEnd();//获取到的json字符串
JArray ja = (JArray)JsonConvert.DeserializeObject(html);
--------------上面的得到的json
for (int i = 0; i < ja.Count; i++)
{
chkBox.Tag = ja[i]["apkName"].ToString() + "," + ja[i]["apkPath"] + "," + ja[i]["appName"].ToString() + "," + ja[i]["appVer"].ToString()+","+ja[i]["appId"].ToString();
}
--------------------------给动态生成checkbox赋值tag
foreach (Control check in this.panel1.Controls)
{
if (check is CheckBox)
{
CheckBox cb = (CheckBox)check;
if (cb.Checked)
{
string str = cb.Tag.ToString();
string[] strs = str.Split(',');
--------------------取到选中的checkbox的tag里面的值
但是现在我想把选中checkbox的tag里面的值传到别的form里面。请问怎么办,求具体代码。。。分不多了。,但是真心求帮助
------解决方案--------------------
使用委托,在这个窗体中定义委托,然后在需要传过来的窗体中注册委托事件。网上搜下“C# 委托”一大堆,学习下很简单。
------解决方案--------------------
需要保证你的CheckBox的父窗口有另一个窗口的引用
class Form1
{
Form2 m_Form2=null;
}
假如你要传strs
在需要接收的窗口(比如Form2)添加一个方法
class Form2
{
public void SetCheckBoxTagValues(string[] strs)
{
//接收窗口处理Form2的代码
}
}
在Form1中得到strs后执行(需要保证m_Form2正好是你要传入的窗口)
m_Form2.SetCheckBoxTagValues(strs);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://192.168.0.111/AssPrj/netLoginAction_selectAppInfo.action");//创建一个请求示例
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader sr = new StreamReader(stream);
string html = sr.ReadToEnd();//获取到的json字符串
JArray ja = (JArray)JsonConvert.DeserializeObject(html);
--------------上面的得到的json
for (int i = 0; i < ja.Count; i++)
{
chkBox.Tag = ja[i]["apkName"].ToString() + "," + ja[i]["apkPath"] + "," + ja[i]["appName"].ToString() + "," + ja[i]["appVer"].ToString()+","+ja[i]["appId"].ToString();
}
--------------------------给动态生成checkbox赋值tag
foreach (Control check in this.panel1.Controls)
{
if (check is CheckBox)
{
CheckBox cb = (CheckBox)check;
if (cb.Checked)
{
string str = cb.Tag.ToString();
string[] strs = str.Split(',');
--------------------取到选中的checkbox的tag里面的值
但是现在我想把选中checkbox的tag里面的值传到别的form里面。请问怎么办,求具体代码。。。分不多了。,但是真心求帮助
------解决方案--------------------
使用委托,在这个窗体中定义委托,然后在需要传过来的窗体中注册委托事件。网上搜下“C# 委托”一大堆,学习下很简单。
------解决方案--------------------
需要保证你的CheckBox的父窗口有另一个窗口的引用
class Form1
{
Form2 m_Form2=null;
}
假如你要传strs
在需要接收的窗口(比如Form2)添加一个方法
class Form2
{
public void SetCheckBoxTagValues(string[] strs)
{
//接收窗口处理Form2的代码
}
}
在Form1中得到strs后执行(需要保证m_Form2正好是你要传入的窗口)
m_Form2.SetCheckBoxTagValues(strs);