📄 cfrmmain.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace SmartIP
{
/// <summary>
/// CfrmMain 的摘要说明。
/// </summary>
public class CfrmMain : System.Windows.Forms.Form
{
private System.Windows.Forms.MenuItem miFile;
private System.Windows.Forms.MenuItem miExit;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem miAbout;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.TextBox tbIP;
private System.Windows.Forms.Label lblIP;
private System.Windows.Forms.Label lblAddr;
private System.Windows.Forms.MainMenu mmMain;
private System.Windows.Forms.OpenFileDialog openFileDialog;
private IpSearcher ipSearcher = new IpSearcher();
public CfrmMain()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
loadDB();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.mmMain = new System.Windows.Forms.MainMenu();
this.miFile = new System.Windows.Forms.MenuItem();
this.miExit = new System.Windows.Forms.MenuItem();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.miAbout = new System.Windows.Forms.MenuItem();
this.btnOK = new System.Windows.Forms.Button();
this.tbIP = new System.Windows.Forms.TextBox();
this.lblIP = new System.Windows.Forms.Label();
this.lblAddr = new System.Windows.Forms.Label();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
//
// mmMain
//
this.mmMain.MenuItems.Add(this.miFile);
this.mmMain.MenuItems.Add(this.menuItem1);
//
// miFile
//
this.miFile.MenuItems.Add(this.miExit);
this.miFile.Text = "文件";
//
// miExit
//
this.miExit.Text = "退出";
this.miExit.Click += new System.EventHandler(this.miExit_Click);
//
// menuItem1
//
this.menuItem1.MenuItems.Add(this.miAbout);
this.menuItem1.Text = "帮助";
//
// miAbout
//
this.miAbout.Text = "关于";
this.miAbout.Click += new System.EventHandler(this.miAbout_Click);
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(160, 48);
this.btnOK.Text = "查询";
this.btnOK.Click += new System.EventHandler(this.button1_Click);
//
// tbIP
//
this.tbIP.Location = new System.Drawing.Point(8, 24);
this.tbIP.Size = new System.Drawing.Size(224, 21);
this.tbIP.Text = "";
//
// lblIP
//
this.lblIP.Location = new System.Drawing.Point(8, 8);
this.lblIP.Size = new System.Drawing.Size(176, 16);
this.lblIP.Text = "请输入您要查询的IP地址";
//
// lblAddr
//
this.lblAddr.Location = new System.Drawing.Point(8, 88);
this.lblAddr.Size = new System.Drawing.Size(224, 48);
//
// openFileDialog
//
this.openFileDialog.FileName = "QQwry.dat";
this.openFileDialog.Filter = "IP数据库(*.dat)|*.dat";
//
// CfrmMain
//
this.Controls.Add(this.lblAddr);
this.Controls.Add(this.lblIP);
this.Controls.Add(this.tbIP);
this.Controls.Add(this.btnOK);
this.Menu = this.mmMain;
this.Text = "SmartIP v0.9.0";
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
static void Main()
{
Application.Run(new CfrmMain());
}
private void loadDB()
{
string path = "";
if (DialogResult.OK == openFileDialog.ShowDialog())
{
path = openFileDialog.FileName;
}
int errCode = ipSearcher.loadIpDB(path);//加载数据库Directory.GetCurrentDirectory()
switch (errCode)
{
case 0:
MessageBox.Show("无法找到IP数据库");
break;
case 1:
MessageBox.Show("无法打开IP数据库");
break;
case 2:
MessageBox.Show("IP数据库损坏");
break;
}
}
private void miExit_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, System.EventArgs e)
{
lblAddr.Text = ipSearcher.ip2Address(tbIP.Text);
if(""==lblAddr.Text)
{
MessageBox.Show("无法加载IP数据库");
}
}
private void miAbout_Click(object sender, System.EventArgs e)
{
MessageBox.Show("power by zbird");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -