📄 frmlogin.cs
字号:
namespace Listener
{
// Library includes
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Net; // added for httprequest and responses and hostname resolving
using System.IO; // added for file streaming
using System.Text; // added for text encodings
using WorkingWithXML;
using System.Net.Sockets;
using System.Threading;
using System.Runtime.InteropServices;
using System.Windows.Forms.Design;
public class frmLogin : System.Windows.Forms.Form
{
Socket newSock;
[DllImport("Shell32.dll")]
public static extern int ShellExecute(int hwnd,
string lpVerb,
string lpFile,
string lpParameters,
string lpDirectory,
int nShowCmd );
// State maintainig variables;
private bool bLoggedIn;
private int IconNo;
private bool bShareDialogOpend;
private bool bDownLoading;
private Byte[] buffer;
private string LoginName;
private int ChatWindowCount;
// Variable required in communication with server
private ServerCommunication xmlServerComm;
// Communcation facilitators on sockets.
private Socket servSock;
// Xml reuests and responses are created using these objects
private XMLCreater xmlCreater;
private XMLParser xmlParser;
// Threads of this application's being.
// Threads for continious update on sys tray
// and for continious seeking for connections
// from browsers, respactively.
private Thread AcceptThread,ThreadIcon,RespondingThread;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Label lbCopyright;
private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.MenuItem ctxMenuShare;
private System.Windows.Forms.MenuItem ctxMenuQuit;
private System.Windows.Forms.TextBox textLoginID;
private System.Windows.Forms.Button btnShareFileFolder;
private System.Windows.Forms.Label labelLoginID;
private System.Windows.Forms.CheckBox chkRemeberID;
private System.Windows.Forms.Button btnLogin;
private System.Windows.Forms.Button btnQuit;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem ListenCntxtMenu;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.NotifyIcon ListenIcon;
private System.Windows.Forms.ContextMenu contextMenu;
private System.Windows.Forms.Button button1;
// First functions that gets called in this form's life cycle
// Initailizes all the GUI controls and reads username last
//used, if any and puts that on the form.
public frmLogin()
{
InitializeComponent();
// initialise objects getting used while communication
// and parsing
xmlServerComm = new WorkingWithXML.ServerCommunication();
xmlParser = new WorkingWithXML.XMLParser();
xmlParser.LOGINXML = Application.StartupPath + "\\Login.xml";
textLoginID.Text = ReadUsername();
bLoggedIn = false;
bShareDialogOpend = false;
bDownLoading = false;
IconNo = 1;
ChatWindowCount = 0;
LoginName = "";
AcceptThread = null;
ThreadIcon = null;
RespondingThread = null;
}
// Reads user name and returns that to the caller
public string ReadUsername()
{
string Username, sTemp;
Username = null;
if ( File.Exists(Application.StartupPath + "\\UserInfo.ini") )
{
// open userinof.ini file and read user name
Stream fstr = File.OpenRead(Application.StartupPath + "\\UserInfo.ini");
Byte[] buffer = new Byte[Convert.ToInt32(fstr.Length)];
fstr.Read(buffer,0,Convert.ToInt32(fstr.Length));
sTemp = Encoding.ASCII.GetString(buffer,0,Convert.ToInt32(buffer.Length));
Username = sTemp.Substring(sTemp.IndexOf("=")+1);
chkRemeberID.Checked = true;
fstr.Close();
}
else
chkRemeberID.Checked = false;
return Username;
}
// Writes user name to a files for next instenciation
public void WriteUsername()
{
string buffer = "username=";
Stream fstr = File.OpenWrite(Application.StartupPath + "\\UserInfo.ini");
buffer += textLoginID.Text;
fstr.Write(Encoding.ASCII.GetBytes(buffer),0,buffer.Length);
fstr.Close();
}
/// Clean up resources this application was using.
public override void Dispose()
{
base.Dispose();
components.Dispose();
}
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmLogin));
this.contextMenu = new System.Windows.Forms.ContextMenu();
this.ctxMenuQuit = new System.Windows.Forms.MenuItem();
this.ctxMenuShare = new System.Windows.Forms.MenuItem();
this.ListenIcon = new System.Windows.Forms.NotifyIcon(this.components);
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.btnQuit = new System.Windows.Forms.Button();
this.btnLogin = new System.Windows.Forms.Button();
this.labelLoginID = new System.Windows.Forms.Label();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.btnShareFileFolder = new System.Windows.Forms.Button();
this.textLoginID = new System.Windows.Forms.TextBox();
this.chkRemeberID = new System.Windows.Forms.CheckBox();
this.ListenCntxtMenu = new System.Windows.Forms.MenuItem();
this.lbCopyright = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// contextMenu
//
this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.ctxMenuQuit,
this.ctxMenuShare});
//
// ctxMenuQuit
//
this.ctxMenuQuit.Index = 0;
this.ctxMenuQuit.Text = "Quit";
this.ctxMenuQuit.Click += new System.EventHandler(this.ctxMenuQuit_Click);
//
// ctxMenuShare
//
this.ctxMenuShare.Index = 1;
this.ctxMenuShare.Text = "Share File/Folders";
this.ctxMenuShare.Click += new System.EventHandler(this.ctxMenuShare_Click);
//
// ListenIcon
//
this.ListenIcon.ContextMenu = this.contextMenu;
this.ListenIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("ListenIcon.Icon")));
this.ListenIcon.Text = "Peering Peers";
this.ListenIcon.Visible = true;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(895, 211);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 6;
this.textBox1.Text = "";
this.textBox1.Visible = false;
this.textBox1.WordWrap = false;
//
// button1
//
this.button1.Location = new System.Drawing.Point(450, 72);
this.button1.Name = "button1";
this.button1.TabIndex = 7;
this.button1.Visible = false;
//
// menuItem1
//
this.menuItem1.Index = -1;
this.menuItem1.Text = "";
//
// btnQuit
//
this.btnQuit.BackColor = System.Drawing.SystemColors.Control;
this.btnQuit.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnQuit.Location = new System.Drawing.Point(349, 145);
this.btnQuit.Name = "btnQuit";
this.btnQuit.Size = new System.Drawing.Size(75, 24);
this.btnQuit.TabIndex = 5;
this.btnQuit.Text = "Quit";
this.toolTip1.SetToolTip(this.btnQuit, "Quit and Close");
this.btnQuit.Click += new System.EventHandler(this.btnQuit_Click);
//
// btnLogin
//
this.btnLogin.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(0)));
this.btnLogin.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnLogin.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnLogin.ForeColor = System.Drawing.Color.LemonChiffon;
this.btnLogin.Location = new System.Drawing.Point(74, 76);
this.btnLogin.Name = "btnLogin";
this.btnLogin.Size = new System.Drawing.Size(83, 29);
this.btnLogin.TabIndex = 4;
this.btnLogin.Text = "Login";
this.toolTip1.SetToolTip(this.btnLogin, "Log-in with this LoginID.");
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
//
// labelLoginID
//
this.labelLoginID.Location = new System.Drawing.Point(18, 30);
this.labelLoginID.Name = "labelLoginID";
this.labelLoginID.Size = new System.Drawing.Size(54, 14);
this.labelLoginID.TabIndex = 2;
this.labelLoginID.Text = "Login ID :";
//
// btnShareFileFolder
//
this.btnShareFileFolder.BackColor = System.Drawing.SystemColors.Control;
this.btnShareFileFolder.Location = new System.Drawing.Point(199, 145);
this.btnShareFileFolder.Name = "btnShareFileFolder";
this.btnShareFileFolder.Size = new System.Drawing.Size(143, 24);
this.btnShareFileFolder.TabIndex = 1;
this.btnShareFileFolder.Text = "Share Files/Folders";
this.toolTip1.SetToolTip(this.btnShareFileFolder, "Share your folders with other peers");
this.btnShareFileFolder.Click += new System.EventHandler(this.btnShareFileFolder_Click);
//
// textLoginID
//
this.textLoginID.Location = new System.Drawing.Point(74, 28);
this.textLoginID.Name = "textLoginID";
this.textLoginID.Size = new System.Drawing.Size(281, 20);
this.textLoginID.TabIndex = 0;
this.textLoginID.Text = "";
this.toolTip1.SetToolTip(this.textLoginID, "Write your Login name here.");
//
// chkRemeberID
//
this.chkRemeberID.Location = new System.Drawing.Point(74, 54);
this.chkRemeberID.Name = "chkRemeberID";
this.chkRemeberID.Size = new System.Drawing.Size(134, 18);
this.chkRemeberID.TabIndex = 3;
this.chkRemeberID.Text = "Remeber My Login ID";
this.toolTip1.SetToolTip(this.chkRemeberID, "System will remember LoginID.");
//
// ListenCntxtMenu
//
this.ListenCntxtMenu.Index = -1;
this.ListenCntxtMenu.Text = "";
//
// lbCopyright
//
this.lbCopyright.Location = new System.Drawing.Point(226, 6);
this.lbCopyright.Name = "lbCopyright";
this.lbCopyright.Size = new System.Drawing.Size(196, 12);
this.lbCopyright.TabIndex = 8;
this.lbCopyright.Text = "
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -