UserControl1.cs
资源名称:类似QQ聊天程序.rar [点击查看]
上传用户:yan_wy
上传日期:2007-06-09
资源大小:112k
文件大小:9k
源码类别:
ICQ/即时通讯
开发平台:
C#
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Windows.Forms;
- using System.Threading;
- using System.IO;
- using System.Text;
- using System.Net;
- using System.Net.Sockets;
- namespace qq
- {
- /// <summary>
- /// UserControl1 的摘要说明。
- /// </summary>
- public class UserControl1 : System.Windows.Forms.UserControl
- {
- public Form1 form;
- public System.Timers.Timer timer;
- private System.Windows.Forms.Button button1;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.ContextMenu contextMenu1;
- private System.Windows.Forms.MenuItem menuItem1;
- private System.Windows.Forms.MenuItem menuItem2;
- private System.Windows.Forms.MenuItem menuItem3;
- public string uid;
- public string name;
- public string sex;
- public string jianjie;
- public string state;
- public string age;
- public string picture;
- public string ip;
- public string tempxiao;
- public bool xiaoxi;
- private System.Windows.Forms.MenuItem menuItem4;
- private System.Windows.Forms.SaveFileDialog saveFileDialog1;
- private System.ComponentModel.IContainer components=null;
- public UserControl1(Form1 f)
- {
- // 该调用是 Windows.Forms 窗体设计器所必需的。
- timer=new System.Timers.Timer(1000);
- form=f;
- xiaoxi=false;
- InitializeComponent();
- timer.Stop();
- // TODO: 在 InitializeComponent 调用后添加任何初始化
- }
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region 组件设计器生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器
- /// 修改此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.button1 = new System.Windows.Forms.Button();
- this.contextMenu1 = new System.Windows.Forms.ContextMenu();
- this.menuItem1 = new System.Windows.Forms.MenuItem();
- this.menuItem2 = new System.Windows.Forms.MenuItem();
- this.menuItem3 = new System.Windows.Forms.MenuItem();
- this.menuItem4 = new System.Windows.Forms.MenuItem();
- this.label1 = new System.Windows.Forms.Label();
- this.timer = new System.Timers.Timer();
- this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
- ((System.ComponentModel.ISupportInitialize)(this.timer)).BeginInit();
- this.SuspendLayout();
- //
- // button1
- //
- this.button1.Anchor = System.Windows.Forms.AnchorStyles.None;
- this.button1.ContextMenu = this.contextMenu1;
- this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
- this.button1.Location = new System.Drawing.Point(40, 0);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(35, 35);
- this.button1.TabIndex = 0;
- this.button1.Click += new System.EventHandler(this.button1_Click);
- this.button1.MouseEnter += new System.EventHandler(this.button1_MouseEnter);
- this.button1.MouseLeave += new System.EventHandler(this.button1_MouseLeave);
- //
- // contextMenu1
- //
- this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.menuItem1,
- this.menuItem2,
- this.menuItem3,
- this.menuItem4});
- //
- // menuItem1
- //
- this.menuItem1.Index = 0;
- this.menuItem1.Text = "查看资料";
- this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
- //
- // menuItem2
- //
- this.menuItem2.Index = 1;
- this.menuItem2.Text = "发送消息";
- this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
- //
- // menuItem3
- //
- this.menuItem3.Index = 2;
- this.menuItem3.Text = "删除用户";
- this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
- //
- // menuItem4
- //
- this.menuItem4.Index = 3;
- this.menuItem4.Text = "传输文件";
- this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
- //
- // label1
- //
- this.label1.Anchor = System.Windows.Forms.AnchorStyles.None;
- this.label1.Location = new System.Drawing.Point(24, 40);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(80, 16);
- this.label1.TabIndex = 1;
- this.label1.Text = "啊峰";
- this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
- //
- // timer
- //
- this.timer.Enabled = true;
- this.timer.SynchronizingObject = this;
- this.timer.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Tick);
- //
- // UserControl1
- //
- this.Controls.Add(this.label1);
- this.Controls.Add(this.button1);
- this.Name = "UserControl1";
- this.Size = new System.Drawing.Size(120, 56);
- this.SizeChanged += new System.EventHandler(this.UserControl1_SizeChanged);
- ((System.ComponentModel.ISupportInitialize)(this.timer)).EndInit();
- this.ResumeLayout(false);
- }
- #endregion
- public void setname(string ab)
- {
- this.label1.Text=ab;
- }
- private void button1_MouseEnter(object sender, System.EventArgs e)
- {
- // this.button1.FlatStyle=FlatStyle.Standard;
- }
- private void button1_MouseLeave(object sender, System.EventArgs e)
- {
- // this.button1.FlatStyle=FlatStyle.Flat;
- }
- private void UserControl1_SizeChanged(object sender, System.EventArgs e)
- {
- }
- private void button1_Click(object sender, System.EventArgs e)
- {
- Message message=new Message(this.form,this);
- message.Show();
- timer.Stop();
- }
- public void setm(int a)
- {
- button1.ImageIndex=a;
- }
- public void setimage(string a)
- {
- // Assign an image to the ImageList.
- ImageList ImageList1=new ImageList();
- ImageList1.Images.Add(Image.FromFile(form.path+@"newface"+a+".bmp"));
- ImageList1.Images.Add(Image.FromFile(form.path+@"newface"+a+"-1.bmp"));
- ImageList1.Images.Add(Image.FromFile(form.path+@"newface"+a+"-2.bmp"));
- ImageList1.Images.Add(Image.FromFile(form.path+@"newface"+a+"-3.bmp"));
- // Assign the ImageList to the button control.
- button1.ImageList = ImageList1;
- ImageList1.ImageSize=new Size(35,35);
- // Select the image from the ImageList (using the ImageIndex property).
- if(this.state=="1")
- button1.ImageIndex=0;
- else button1.ImageIndex=2;
- }
- private void timer1_Tick(object sender, System.Timers.ElapsedEventArgs e)
- {
- if(this.button1.FlatStyle==FlatStyle.Popup)
- this.button1.FlatStyle=FlatStyle.Standard;
- else this.button1.FlatStyle=FlatStyle.Popup;
- }
- private void menuItem2_Click(object sender, System.EventArgs e)
- {
- Message message=new Message(this.form,this);
- message.Show();
- timer.Stop();
- }
- public void setup()
- {
- fclient f=new fclient(this);
- DialogResult result=f.ShowDialog();
- if(result==DialogResult.Cancel)
- {
- }
- else
- {
- System.Net .Sockets .TcpClient client;
- System.Net.Sockets .NetworkStream socketstream;
- BinaryWriter writer;
- BinaryReader reader;
- string path = @"c:tempMyTest.txt";
- client=new TcpClient (ip.Trim(),5002);
- socketstream=client.GetStream();
- reader=new BinaryReader(socketstream);
- byte[] b = new byte[1024];
- string length=reader.ReadString();
- long len=long.Parse(length);
- string fname=reader.ReadString();
- this.saveFileDialog1.FileName=fname;
- if(this.saveFileDialog1.ShowDialog()==DialogResult.OK)
- { path=this.saveFileDialog1.FileName;
- FileStream fs = File.Create(path);
- writer=new BinaryWriter (fs);
- while(socketstream.CanRead &&len>0)
- {
- len-=1024;
- b=reader.ReadBytes(1024);
- writer.Write(b,0,1024);
- }
- MessageBox.Show("传输结束");
- writer.Close();fs.Close();
- }
- socketstream.Close();
- reader.Close();
- client.Close();
- }
- }
- //资料
- private void menuItem1_Click(object sender, System.EventArgs e)
- {
- 资料 zilao=new 资料(this);
- zilao.Show();
- }
- //删除用户
- private void menuItem3_Click(object sender, System.EventArgs e)
- {
- form.panel4.Controls.Remove(this);
- form.userlist.Remove(this);
- try
- {
- System.Data.SqlClient.SqlCommand insert=new System.Data.SqlClient.SqlCommand();
- insert.CommandText = "delete from [friends] where uid="+form.userid+"and friendid="+this.uid;
- insert.Connection=this.form.sdata.sqlConnection1;
- this.form.sdata.sqlConnection1.Open();
- insert.ExecuteNonQuery();
- this.form.sdata.sqlConnection1.Close();
- }
- catch(Exception ee)
- {
- MessageBox.Show(ee.ToString());
- }
- }
- private void menuItem4_Click(object sender, System.EventArgs e)
- {
- fserver serv=new fserver(form,this.uid);
- serv.Show();
- }
- }
- }