void ChatBox_DoubleClick(object sender, EventArgs arg) { try { if (!this.popoutImageWhenDoubleClick) { return; } MouseEventArgs e = arg as MouseEventArgs; if (e == null) { return; } GifBox box = this.HitTest(e.Location, true); if (box == null) { return; } ImageForm form = new ImageForm(box.Image); form.Show(); } catch (Exception ee) { MessageBox.Show(ee.Message); } }
void ChatBox_SizeChanged(object sender, EventArgs e) { if (this.RichEditOle == null) { return; } List <REOBJECT> list = this.RichEditOle.GetAllREOBJECT(); for (int i = 0; i < list.Count; i++) { GifBox box = (GifBox)Marshal.GetObjectForIUnknown(list[i].poleobj); box.Size = this.ComputeGifBoxSize(box.Image.Size); } }
/// <summary> /// 在position位置处,插入图片。 /// </summary> /// <param name="image">要插入的图片</param> /// <param name="position">插入的位置</param> public void InsertImage(Image image, int position) { try { GifBox gif = new GifBox(); gif.Cursor = Cursors.Hand; gif.BackColor = base.BackColor; gif.Size = this.ComputeGifBoxSize(image.Size); gif.Image = image; this.RichEditOle.InsertControl(gif, position, 10000); } catch (Exception ee) { MessageBox.Show(ee.Message); } }
/// <summary> /// 在position位置处,插入系统内置表情。 /// </summary> /// <param name="position">插入的位置</param> /// <param name="emotionID">表情图片在内置列表中的index</param> public void InsertDefaultEmotion(uint emotionID, int position) { try { Image image = this.defaultEmotionDictionary[emotionID]; GifBox gif = new GifBox(); gif.Cursor = Cursors.Hand; gif.BackColor = base.BackColor; gif.Size = this.ComputeGifBoxSize(image.Size); gif.Image = image; this.RichEditOle.InsertControl(gif, position, emotionID); } catch (Exception ee) { MessageBox.Show(ee.Message); } }
public new void Clear() { try { List <REOBJECT> list = this.RichEditOle.GetAllREOBJECT(); for (int i = 0; i < list.Count; i++) { if (list[i].dwUser == 10000) { GifBox box = (GifBox)Marshal.GetObjectForIUnknown(list[i].poleobj); box.Dispose(); } } base.Clear(); } catch (Exception ee) { MessageBox.Show(ee.Message); } }
private GifBox HitTest(Point pt, bool selectTarget) { int index = this.GetCharIndexFromPosition(pt); Point origin = this.GetPositionFromCharIndex(index); GifBox box = null; bool backOne = false; List <REOBJECT> list = this.RichEditOle.GetAllREOBJECT(); for (int i = 0; i < list.Count; i++) { if (list[i].posistion == index || list[i].posistion + 1 == index) { box = (GifBox)Marshal.GetObjectForIUnknown(list[i].poleobj); if (list[i].posistion + 1 == index) { origin = new Point(origin.X - box.Width, origin.Y); backOne = true; } break; } } if (box == null) { return(null); } Rectangle rect = new Rectangle(origin.X, origin.Y, box.Width, box.Height); if (!rect.Contains(pt)) { return(null); } if (selectTarget) { this.Select(backOne ? index - 1 : index, 1); } return(box); }
/// <summary> /// 获取Box中的所有内容。 /// </summary> /// <param name="containsForeignObject">内容中是否包含不是由IImagePathGetter管理的图片对象</param> /// <returns>key为位置,val为图片的ID</returns> public ChatBoxContent GetContent() { ChatBoxContent content = new ChatBoxContent(this.Text, this.Font, this.ForeColor); List <REOBJECT> list = this.RichEditOle.GetAllREOBJECT(); for (int i = 0; i < list.Count; i++) { uint pos = (uint)list[i].posistion; content.PicturePositions.Add(pos); if (list[i].dwUser != 10000) { content.AddEmotion(pos, list[i].dwUser); } else { GifBox box = (GifBox)Marshal.GetObjectForIUnknown(list[i].poleobj); content.AddForeignImage(pos, box.Image); } } return(content); }
void ChatBox_MouseDown(object sender, MouseEventArgs e) { if (e.Button != System.Windows.Forms.MouseButtons.Right) { return; } if (this.contextMenuMode == ChatBoxContextMenuMode.None) { this.ContextMenuStrip = null; return; } if (this.contextMenuMode == ChatBoxContextMenuMode.ForInput) { this.toolStripMenuItem9.Visible = !string.IsNullOrEmpty(this.SelectedText); this.ContextMenuStrip = this.contextMenuStrip1; return; } GifBox box = this.HitTest(e.Location, true); if (box == null) { if (!string.IsNullOrEmpty(this.SelectedText)) { this.imageOnRightClick = null; this.ContextMenuStrip = this.contextMenuStrip4; return; } this.imageOnRightClick = null; this.ContextMenuStrip = this.contextMenuStrip3; return; } this.imageOnRightClick = box.Image; this.ContextMenuStrip = this.contextMenuStrip2; }