UserControl1.cs
上传用户:yan_wy
上传日期:2007-06-09
资源大小:112k
文件大小:9k
源码类别:

ICQ/即时通讯

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Windows.Forms;
  7. using System.Threading;
  8. using System.IO;
  9. using System.Text;
  10. using System.Net;
  11. using System.Net.Sockets;
  12. namespace qq
  13. {
  14. /// <summary>
  15. /// UserControl1 的摘要说明。
  16. /// </summary>
  17. public class UserControl1 : System.Windows.Forms.UserControl
  18. {
  19. public Form1 form;
  20. public System.Timers.Timer timer;
  21. private System.Windows.Forms.Button button1;
  22. private System.Windows.Forms.Label label1;
  23. private System.Windows.Forms.ContextMenu contextMenu1;
  24. private System.Windows.Forms.MenuItem menuItem1;
  25. private System.Windows.Forms.MenuItem menuItem2;
  26. private System.Windows.Forms.MenuItem menuItem3;
  27. public string uid;
  28. public string name;
  29. public string sex;
  30. public string jianjie;
  31. public string state;
  32. public string age;
  33. public string picture;
  34. public string ip;
  35. public string tempxiao;
  36. public bool xiaoxi;
  37. private System.Windows.Forms.MenuItem menuItem4;
  38. private System.Windows.Forms.SaveFileDialog saveFileDialog1;
  39. private System.ComponentModel.IContainer components=null;
  40. public UserControl1(Form1 f)
  41. {
  42. // 该调用是 Windows.Forms 窗体设计器所必需的。
  43. timer=new System.Timers.Timer(1000);
  44. form=f;
  45. xiaoxi=false;
  46. InitializeComponent();
  47.             timer.Stop();
  48. // TODO: 在 InitializeComponent 调用后添加任何初始化
  49. }
  50. /// <summary> 
  51. /// 清理所有正在使用的资源。
  52. /// </summary>
  53. protected override void Dispose( bool disposing )
  54. {
  55. if( disposing )
  56. {
  57. if(components != null)
  58. {
  59. components.Dispose();
  60. }
  61. }
  62. base.Dispose( disposing );
  63. }
  64. #region 组件设计器生成的代码
  65. /// <summary> 
  66. /// 设计器支持所需的方法 - 不要使用代码编辑器 
  67. /// 修改此方法的内容。
  68. /// </summary>
  69. private void InitializeComponent()
  70. {
  71. this.button1 = new System.Windows.Forms.Button();
  72. this.contextMenu1 = new System.Windows.Forms.ContextMenu();
  73. this.menuItem1 = new System.Windows.Forms.MenuItem();
  74. this.menuItem2 = new System.Windows.Forms.MenuItem();
  75. this.menuItem3 = new System.Windows.Forms.MenuItem();
  76. this.menuItem4 = new System.Windows.Forms.MenuItem();
  77. this.label1 = new System.Windows.Forms.Label();
  78. this.timer = new System.Timers.Timer();
  79. this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
  80. ((System.ComponentModel.ISupportInitialize)(this.timer)).BeginInit();
  81. this.SuspendLayout();
  82. // 
  83. // button1
  84. // 
  85. this.button1.Anchor = System.Windows.Forms.AnchorStyles.None;
  86. this.button1.ContextMenu = this.contextMenu1;
  87. this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  88. this.button1.Location = new System.Drawing.Point(40, 0);
  89. this.button1.Name = "button1";
  90. this.button1.Size = new System.Drawing.Size(35, 35);
  91. this.button1.TabIndex = 0;
  92. this.button1.Click += new System.EventHandler(this.button1_Click);
  93. this.button1.MouseEnter += new System.EventHandler(this.button1_MouseEnter);
  94. this.button1.MouseLeave += new System.EventHandler(this.button1_MouseLeave);
  95. // 
  96. // contextMenu1
  97. // 
  98. this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  99.  this.menuItem1,
  100.  this.menuItem2,
  101.  this.menuItem3,
  102.  this.menuItem4});
  103. // 
  104. // menuItem1
  105. // 
  106. this.menuItem1.Index = 0;
  107. this.menuItem1.Text = "查看资料";
  108. this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
  109. // 
  110. // menuItem2
  111. // 
  112. this.menuItem2.Index = 1;
  113. this.menuItem2.Text = "发送消息";
  114. this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
  115. // 
  116. // menuItem3
  117. // 
  118. this.menuItem3.Index = 2;
  119. this.menuItem3.Text = "删除用户";
  120. this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
  121. // 
  122. // menuItem4
  123. // 
  124. this.menuItem4.Index = 3;
  125. this.menuItem4.Text = "传输文件";
  126. this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
  127. // 
  128. // label1
  129. // 
  130. this.label1.Anchor = System.Windows.Forms.AnchorStyles.None;
  131. this.label1.Location = new System.Drawing.Point(24, 40);
  132. this.label1.Name = "label1";
  133. this.label1.Size = new System.Drawing.Size(80, 16);
  134. this.label1.TabIndex = 1;
  135. this.label1.Text = "啊峰";
  136. this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
  137. // 
  138. // timer
  139. // 
  140. this.timer.Enabled = true;
  141. this.timer.SynchronizingObject = this;
  142. this.timer.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Tick);
  143. // 
  144. // UserControl1
  145. // 
  146. this.Controls.Add(this.label1);
  147. this.Controls.Add(this.button1);
  148. this.Name = "UserControl1";
  149. this.Size = new System.Drawing.Size(120, 56);
  150. this.SizeChanged += new System.EventHandler(this.UserControl1_SizeChanged);
  151. ((System.ComponentModel.ISupportInitialize)(this.timer)).EndInit();
  152. this.ResumeLayout(false);
  153. }
  154. #endregion
  155. public void setname(string ab)
  156. {
  157. this.label1.Text=ab;
  158. }
  159. private void button1_MouseEnter(object sender, System.EventArgs e)
  160. {
  161. // this.button1.FlatStyle=FlatStyle.Standard;
  162. }
  163. private void button1_MouseLeave(object sender, System.EventArgs e)
  164. {
  165. // this.button1.FlatStyle=FlatStyle.Flat;
  166. }
  167. private void UserControl1_SizeChanged(object sender, System.EventArgs e)
  168. {
  169. }
  170. private void button1_Click(object sender, System.EventArgs e)
  171. {
  172. Message message=new Message(this.form,this);
  173. message.Show();
  174. timer.Stop();
  175. }
  176. public void setm(int a)
  177. {
  178. button1.ImageIndex=a;
  179. }
  180. public void setimage(string a)
  181. {
  182. // Assign an image to the ImageList.
  183. ImageList ImageList1=new ImageList();
  184. ImageList1.Images.Add(Image.FromFile(form.path+@"newface"+a+".bmp"));
  185. ImageList1.Images.Add(Image.FromFile(form.path+@"newface"+a+"-1.bmp"));
  186. ImageList1.Images.Add(Image.FromFile(form.path+@"newface"+a+"-2.bmp"));
  187. ImageList1.Images.Add(Image.FromFile(form.path+@"newface"+a+"-3.bmp"));
  188. // Assign the ImageList to the button control.   
  189. button1.ImageList = ImageList1;
  190. ImageList1.ImageSize=new Size(35,35);
  191. // Select the image from the ImageList (using the ImageIndex property).
  192. if(this.state=="1")
  193. button1.ImageIndex=0;
  194. else button1.ImageIndex=2;
  195. }
  196. private void timer1_Tick(object sender, System.Timers.ElapsedEventArgs e)
  197. {
  198. if(this.button1.FlatStyle==FlatStyle.Popup)
  199. this.button1.FlatStyle=FlatStyle.Standard;
  200. else this.button1.FlatStyle=FlatStyle.Popup;
  201. }
  202. private void menuItem2_Click(object sender, System.EventArgs e)
  203. {
  204. Message message=new Message(this.form,this);
  205. message.Show();
  206. timer.Stop();
  207. }
  208. public void setup()
  209. {
  210. fclient f=new fclient(this);
  211. DialogResult result=f.ShowDialog();
  212. if(result==DialogResult.Cancel)
  213. {
  214. }
  215. else
  216. {
  217. System.Net .Sockets .TcpClient  client;
  218. System.Net.Sockets .NetworkStream socketstream;
  219. BinaryWriter writer;
  220. BinaryReader reader;
  221. string path = @"c:tempMyTest.txt";
  222. client=new TcpClient (ip.Trim(),5002);
  223. socketstream=client.GetStream();
  224. reader=new BinaryReader(socketstream);
  225. byte[] b = new byte[1024];
  226. string length=reader.ReadString();
  227. long len=long.Parse(length);
  228. string fname=reader.ReadString();
  229. this.saveFileDialog1.FileName=fname;
  230. if(this.saveFileDialog1.ShowDialog()==DialogResult.OK)
  231. { path=this.saveFileDialog1.FileName;
  232. FileStream fs = File.Create(path);
  233. writer=new BinaryWriter (fs);
  234. while(socketstream.CanRead &&len>0)
  235. {
  236. len-=1024;
  237. b=reader.ReadBytes(1024);
  238. writer.Write(b,0,1024);
  239. }
  240. MessageBox.Show("传输结束");
  241. writer.Close();fs.Close();
  242. }
  243. socketstream.Close();
  244. reader.Close();
  245. client.Close();
  246. }
  247. }
  248. //资料
  249. private void menuItem1_Click(object sender, System.EventArgs e)
  250. {
  251. 资料 zilao=new 资料(this);
  252. zilao.Show();
  253. }
  254. //删除用户
  255. private void menuItem3_Click(object sender, System.EventArgs e)
  256. {
  257. form.panel4.Controls.Remove(this);
  258. form.userlist.Remove(this);
  259. try
  260. {
  261. System.Data.SqlClient.SqlCommand insert=new System.Data.SqlClient.SqlCommand();
  262. insert.CommandText = "delete  from [friends] where uid="+form.userid+"and friendid="+this.uid;
  263. insert.Connection=this.form.sdata.sqlConnection1;
  264. this.form.sdata.sqlConnection1.Open();
  265. insert.ExecuteNonQuery();
  266. this.form.sdata.sqlConnection1.Close();
  267. }
  268. catch(Exception ee)
  269. {
  270. MessageBox.Show(ee.ToString());
  271. }
  272. }
  273. private void menuItem4_Click(object sender, System.EventArgs e)
  274. {
  275. fserver serv=new fserver(form,this.uid);
  276. serv.Show();
  277. }
  278. }
  279. }