gpt4 book ai didi

c# - 非静态字段、方法或属性“WindowsApplication1.Form1.TextboxText()..与标签相同”需要对象引用

转载 作者:太空狗 更新时间:2023-10-30 01:23:24 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
An object reference is required for the nonstatic field, method, or property 'WindowsApplication1.Form1.setTextboxText(int)

我正在创建一个 IP 跟踪器,它将连接到网络并从文本框中输入值 (IP) 并将接收结果。这是代码。

 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.Xml;

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

private void button1_Click(object sender, EventArgs e)
{
iptrace();
}

public static string iptrace()
{
XmlDocument xmldoc = new XmlDocument();
XmlNodeList xmlnode;
int i;

xmldoc.Load("http://freegeoip.net/xml/" + textBox1.Text);
xmlnode = xmldoc.GetElementsByTagName("response");
for (i = 0; i < xmlnode.Count; i++)
{
xmlnode[i].ChildNodes.Item(0).InnerText.Trim();
label1.Text = "Ip Address: " + xmlnode[i].ChildNodes.Item(0).InnerText.Trim();
label2.Text = "Country Code: " + xmlnode[i].ChildNodes.Item(1).InnerText.Trim();
label3.Text = "Country Name: " + xmlnode[i].ChildNodes.Item(2).InnerText.Trim();
label4.Text = "Region Code: " + xmlnode[i].ChildNodes.Item(3).InnerText.Trim();
label5.Text = "Region Name: " + xmlnode[i].ChildNodes.Item(4).InnerText.Trim();
label6.Text = "City: " + xmlnode[i].ChildNodes.Item(5).InnerText.Trim();
label7.Text = "Zip Code: " + xmlnode[i].ChildNodes.Item(6).InnerText.Trim();
label8.Text = "Latitude: " + xmlnode[i].ChildNodes.Item(7).InnerText.Trim();
label9.Text = "Longitude: " + xmlnode[i].ChildNodes.Item(8).InnerText.Trim();
label10.Text = "Metro Code: " + xmlnode[i].ChildNodes.Item(9).InnerText.Trim();
}

}


}
}`

它给我错误

非静态字段、方法或属性“geoIP.Form1.textBox1”需要对象引用

24 4 0