当前上下文中不存在名称“InitializeComponent”
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.Data.OleDb;
using System.IO;
namespace homework1
{
public partial class Form1 : Form
{
ListView lv = new ListView();
private static string strConnect = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=jzd.mdb";
private OleDbConnection conConnection = new OleDbConnection(strConnect);
public Form1()
{
InitializeComponent();
}
public int ReadPointShp()
{
double x, y;
int ObjCount = 0;
try
{
//打开.shp文件,读取x,y坐标的信息
FileStream fs = new FileStream("jzd.shp", FileMode.Open, FileAccess.Read); //文件流形式
BinaryReader BinaryFile = new BinaryReader(fs); //打开二进制文件
BinaryFile.ReadBytes(32); //先读出36个字节,紧接着是Box边界合
int shapetype = BinaryFile.ReadInt32();
if (shapetype != 1)
{ //MessageBox.Show("不是点shp文件!");
return 0;
}
//读出整个shp图层的边界盒
double Left = BinaryFile.ReadDouble();
double Bottom = BinaryFile.ReadDouble();
double Right = BinaryFile.ReadDouble();
double Top = BinaryFile.ReadDouble();
// shp中尚未使用的边界盒
BinaryFile.ReadBytes(32);
int j = 0;
// BinaryFile.PeekChar() = -1 是文件结束
while (BinaryFile.PeekChar() != -1)
{
ObjCount++;
//记录头8个字节和一个int(4个字节)的shapetype
BinaryFile.ReadBytes(12);
x = BinaryFile.ReadDouble();
y = BinaryFile.ReadDouble();
ListViewItem liv = new ListViewItem();
// li.SubItems.Clear();
lv.Items[j].SubItems[8].Text = x.ToString();
lv.Items[j].SubItems[9].Text = y.ToString();
j++;
}
}
catch (FileNotFoundException ex)
{
ex.ToString();
}
return ObjCount;
}
private void Form1_Load(object sender, EventArgs e)
{
this.Width = 500;
this.Height = 500;
//this.Left = 0;
// this.Top = 0;
// this.Text = "在ListView中显示数据库内容!";
// lv.Left = 0;
// lv.Top = 0;
// lv.Width = 500;
// lv.Height = 500;
/* lv.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));*/
lv.Dock = DockStyle.Fill;
lv.GridLines = true;
// file://显示各个记录的分隔线
lv.FullRowSelect = true;
// file://要选择就是一行
lv.View = View.Details;
// file://定义列表显示的方式
lv.Scrollable = true;
// file://需要时候显示滚动条
lv.MultiSelect = false; // 不可以多行选择
lv.HeaderStyle = ColumnHeaderStyle.Clickable;
//lv.HeaderStyle = ColumnHeaderStyle.Nonclickable;
// 针对数据库的字段名称,建立与之适应显示表头
lv.Columns.Add("ID", 60, HorizontalAlignment.Right);
lv.Columns.Add("BSM", 200, HorizontalAlignment.Left);
lv.Columns.Add("JZDBM", 200, HorizontalAlignment.Left);
lv.Columns.Add("JZDBMLSH", 200, HorizontalAlignment.Left);
lv.Columns.Add("YSDM", 200, HorizontalAlignment.Left);
lv.Columns.Add("JZDH", 200, HorizontalAlignment.Left);
lv.Columns.Add("JBLX", 200, HorizontalAlignment.Left);
lv.Columns.Add("JZDLX", 200, HorizontalAlignment.Left);
lv.Columns.Add("x", 200, HorizontalAlignment.Left);
lv.Columns.Add("y", 200, HorizontalAlignment.Left);
lv.Visible = true;
OleDbDataReader reader;
string strCommand = "SELECT * FROM jzd";
this.conConnection.Open();// 打开数据连接
OleDbCommand cmd = new OleDbCommand(strCommand, conConnection);
reader = cmd.ExecuteReader();//获得数据集
// 不断往列表中添加数据记录
while (reader.Read())
{
ListViewItem li = new ListViewItem();
li.SubItems.Clear();
li.SubItems[0].Text = reader["ID"].ToString();
li.SubItems.Add(reader["BSM"].ToString());
li.SubItems.Add(reader["JZDBM"].ToString());
li.SubItems.Add(reader["JZDBMLSH"].ToString());
li.SubItems.Add(reader["YSDM"].ToString());
li.SubItems.Add(reader["JZDH"].ToString());
li.SubItems.Add(reader["JBLX"].ToString());
li.SubItems.Add(reader["JZDLX"].ToString());
li.SubItems.Add("0".ToString());
li.SubItems.Add("0".ToString());
lv.Items.Add(li);
}
reader.Close(); // 关闭数据集
// 在Form中添加此列表
// ListViewItem liv = new ListViewItem();
// lv.Items [0].SubItems[8].Text="0".ToString(); lv.Items.Add(liv);
ReadPointShp(); //lv.Items.Add(li);
this.Controls.Add(lv);
// 关闭Form的时候,同时也关闭数据连接
this.Closed += new EventHandler(this_Closed);
}
protected void this_Closed(object sender, EventArgs eArgs)
{
this.conConnection.Close(); //file://关闭数据连接
}
}
}
--------------------编程问答-------------------- 它丢了 --------------------编程问答-------------------- 还有个类文件没有了吧,Form1.Design.cs
另外多下嘴:
BinaryFile.ReadBytes(32); //先读出36个字节,紧接着是Box边界合
这个是32还是36? --------------------编程问答--------------------
应该是的 --------------------编程问答-------------------- 恩
丢了 --------------------编程问答-------------------- Desiner.cs 文件中InitializeComponent
补充:.NET技术 , C#