public void AddStroke(MyStroke stroke) { VisibleStroke p = stroke.ToStroke(da.Clone()); p.Visibility = this.Visibility; strokes.Add(p); App.ink.Dispatcher.Invoke(new Action(() => { App.ink.Strokes.Add(p); })); }
static void client_answer(object sender, AnswerEventArgs args) { var message = args.data as UserMessage; try{ switch (message.type) { case 1://传输线条 { // MessageBox.Show(String.Format("线条来自{0}", message.name)); MyStroke p = message.data as MyStroke; Custom c; MainData.user_dic.TryGetValue(message.name, out c); if (c != null && p != null) { c.AddStroke(p); } } break; case 2://登录,表示有某个人登录了 { // MessageBox.Show(String.Format("登录{0}", message.name)); if (MainData.user_dic.ContainsKey(message.name)) { MessageBox.Show("Error 请不要重复登录"); } var p = new Custom(); p.name = message.name; MainData.user_dic.Add(message.name, p); } break; case 3://登录反馈,收到的服务器发过来的在线人的名字列表 { List <string> s = message.data as List <string>; string str = ""; foreach (var item in s) { str = str + item + " "; } // if (s != null) MessageBox.Show(str); // else MessageBox.Show("Get But No Data"); foreach (var item in s) { var p = new Custom(); p.name = item; MainData.user_dic.Add(item, p); } } break; case 4://线宽变化 { var d = (double)message.data; Custom c; MainData.user_dic.TryGetValue(message.name, out c); if (c != null) { c.ChangeWidth(d); } } break; case 5://颜色变化 { var cc = message.data as string; // MessageBox.Show(cc); Custom c; MainData.user_dic.TryGetValue(message.name, out c); if (c != null) { c.ChangeColor(cc); } } break; case 6: { Custom c; MainData.user_dic.TryGetValue(message.name, out c); if (c != null) { c.Undo(); } } break; case 7: { Custom c; MainData.user_dic.TryGetValue(message.name, out c); if (c != null) { c.Clear(); } } break; case 8://下线通知 此时name是下线者 { // MessageBox.Show("Offline"); Custom c; MainData.user_dic.TryGetValue(message.name, out c); if (c != null) { c.Remove(); } MainData.user_dic.Remove(message.name); } break; default: break; } } catch (Exception e1) { MessageBox.Show("Client.client_answer" + e1.Message); } }
internal static void SendStroke(Stroke stroke) { MyStroke my = new MyStroke(stroke); SendMessage(1, my); }