//点击出现聊天框 private void mousedown(object sender, MouseButtonEventArgs e) { ListBox user = (ListBox)sender; int index = user.SelectedIndex; //MessageBox.Show(index.ToString()); int i = 0; if (index < user.Items.Count && index != -1) { for (i = 0; i < parent.talklist.Count; i++) { if (parent.talklist[i].Title == parent.userlist[index].ip) { break; } } if (i == parent.talklist.Count) { TalkWindow talkwindow = new TalkWindow(parent.userlist[index],parent.MyFont, parent); parent.talklist.Add(talkwindow); if (parent.GetMsgList.Count != 0) { for (i = 0; i < parent.GetMsgList.Count; i++) { if (parent.GetMsgList[i].user.ip == parent.GetMsgList[0].user.ip) { talkwindow.ShowMessage(parent.GetMsgList[i].content, parent.GetMsgList[i].font); parent.GetMsgList.RemoveAt(i); i--; } } } talkwindow.Show(); //请求获得共享文件 parent.GetSharedFiles(parent.userlist[index].ip); } else { if (parent.talklist[i].WindowState == WindowState.Minimized) { parent.talklist[i].WindowState = WindowState.Normal; } parent.talklist[i].Activate(); } } }
/// /// 鼠标单击 /// private void notifyIcon_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { if (GetMsgList.Count != 0) { TalkWindow talkwindow = new TalkWindow(GetMsgList[0].user, MyFont, this); for (int i = GetMsgList.Count-1; i >= 0; i--) { if (GetMsgList[i].user.ip == GetMsgList[0].user.ip) { if (GetMsgList[i].ID == MessageID.UserSendFile) { talkwindow.AddRecvFile(GetMsgList[i].file, GetMsgList[i].filesize); } else { talkwindow.ShowMessage(GetMsgList[i].content, GetMsgList[i].font); } GetMsgList.RemoveAt(i); } } talklist.Add(talkwindow); talkwindow.Show(); talkwindow.Activate(); //请求获得共享文件 GetSharedFiles(talkwindow.TalkUser.ip); } else if (this.Visibility == Visibility.Visible) { this.Visibility = Visibility.Visible; this.Activate(); if (this.Top == TOPPOINT) { this.ShowWindow(); this.Top = 1; } else if (this.Top == 1) { this.Top = 0; } } else if(miniwindow != null) { miniwindow.WindowState = System.Windows.WindowState.Normal; miniwindow.Visibility = Visibility.Visible; miniwindow.Activate(); } } }
private void ListDoubleClick(object sender, MouseEventArgs e) { ListBox user = (ListBox)sender; int index = user.SelectedIndex; int i = 0; if (index < user.Items.Count && index != -1) { for (i = 0; i < talklist.Count; i++) { if (talklist[i].Title == userlist[index].ip) { break; } } if (i == talklist.Count) { TalkWindow talkwindow = new TalkWindow(userlist[index],MyFont,this); talklist.Add(talkwindow); if (GetMsgList.Count != 0) { for (i = GetMsgList.Count-1; i >= 0; i--) { if (GetMsgList[i].user.ip == GetMsgList[0].user.ip) { if (GetMsgList[i].ID == MessageID.UserSendFile) { talkwindow.AddRecvFile(GetMsgList[i].file, GetMsgList[i].filesize); } else { talkwindow.ShowMessage(GetMsgList[i].content, GetMsgList[i].font); } GetMsgList.RemoveAt(i); } } } talkwindow.Show(); talkwindow.Activate(); //请求获得共享文件 GetSharedFiles(userlist[index].ip); } else { if (talklist[i].WindowState == WindowState.Minimized) { talklist[i].WindowState = WindowState.Normal; } talklist[i].Activate(); } } }
private void DownloadSharedFileClick(object sender, RoutedEventArgs e) { int index = Down_list.SelectedIndex; int i = 0; if (index != -1) { for (i = 0; i < talklist.Count; i++) { if (talklist[i].Title == AllFiles[index].ip) { break; } } if (i == talklist.Count) { for (i = 0; i < userlist.Count; i++) { if (userlist[i].ip == AllFiles[index].ip) { break; } } if (i != userlist.Count) { TalkWindow talkwindow = new TalkWindow(userlist[i], MyFont, this); talklist.Add(talkwindow); talkwindow.Show(); talkwindow.Activate(); //请求获得共享文件 GetSharedFiles(AllFiles[index].ip); //开始下载文件 talkwindow.DownloadFile(AllFiles[index]); } else { MessageBox.Show("拥有该资源的用户已不在!", "错误"); UpdateDownClick(sender, e); } } else { if (talklist[i].WindowState == WindowState.Minimized) { talklist[i].WindowState = WindowState.Normal; } talklist[i].Activate(); //开始下载文件 talklist[i].DownloadFile(AllFiles[index]); } } }
//打开文件窗口 private void CreateTalkWindiwToFile(Object msg) { Message ReadMessage = (Message)msg; int i = 0; TalkWindow talkwindow = new TalkWindow(ReadMessage.user, MyFont, this); talklist.Add(talkwindow); if (GetMsgList.Count != 0) { for (i = 0; i < GetMsgList.Count; i++) { if (GetMsgList[i].user.ip == GetMsgList[0].user.ip) { talkwindow.ShowMessage(GetMsgList[i].content, GetMsgList[i].font); GetMsgList.RemoveAt(i); i--; } } } notifyIcon.BalloonTipText = ReadMessage.user.name + "发来文件"; notifyIcon.ShowBalloonTip(1000); talkwindow.AddRecvFile(ReadMessage.file, ReadMessage.filesize); talkwindow.Show(); talkwindow.Activate(); System.Windows.Threading.Dispatcher.Run(); }
private void mouseleftup(object sender, MouseButtonEventArgs e) { if (IsWindowMove == false) { if (parent.GetMsgList.Count != 0) { TalkWindow talkwindow = new TalkWindow(parent.GetMsgList[0].user, parent.MyFont, parent); for (int i = parent.GetMsgList.Count-1; i >= 0 ; i--) { if (parent.GetMsgList[i].user.ip == parent.GetMsgList[0].user.ip) { if (parent.GetMsgList[i].ID == MessageID.UserSendFile) { talkwindow.AddRecvFile(parent.GetMsgList[i].file, parent.GetMsgList[i].filesize); } else { talkwindow.ShowMessage(parent.GetMsgList[i].content, parent.GetMsgList[i].font); } parent.GetMsgList.RemoveAt(i); } } parent.talklist.Add(talkwindow); talkwindow.Show(); } else if (userwindow.IsVisible == false) { if ((this.Left + 70 + 600) <= clientWidth) { userwindow.Left = this.Left + 70; } else { userwindow.Left = this.Left - 580; } if ((this.Top + 400) <= clientHeight) { userwindow.Top = this.Top; } else { userwindow.Top = this.Top - 340; } userwindow.Show(); userwindow.Activate(); } else { userwindow.Hide(); } } else { IsWindowMove = false; } }