protected override void WndProc(ref Message m) { if (m.Msg == WIN32.WM_LBUTTONDOWN || m.Msg == WIN32.WM_RBUTTONDOWN || m.Msg == WIN32.WM_LBUTTONDBLCLK || m.Msg == WIN32.WM_MOUSELEAVE || m.Msg == WIN32.WM_MOUSEMOVE) { WIN32.PostMessage(this.Parent.Handle, (uint)m.Msg, m.WParam, m.LParam); } else if (m.Msg == WIN32.WM_LBUTTONUP) { this.Parent.Invalidate(); } base.WndProc(ref m); }
/* Will clean this up later doing something like this * enum CaptureOptions : long * { * PRF_CHECKVISIBLE= 0x00000001L, * PRF_NONCLIENT = 0x00000002L, * PRF_CLIENT = 0x00000004L, * PRF_ERASEBKGND = 0x00000008L, * PRF_CHILDREN = 0x00000010L, * PRF_OWNED = 0x00000020L * } */ public static bool CaptureWindow(System.Windows.Forms.Control control, ref System.Drawing.Bitmap bitmap) { //This function captures the contents of a window or control Graphics g2 = Graphics.FromImage(bitmap); //PRF_CHILDREN // PRF_NONCLIENT int meint = (int)(PRF_CLIENT | PRF_ERASEBKGND); //| PRF_OWNED ); // ); System.IntPtr meptr = new System.IntPtr(meint); System.IntPtr hdc = g2.GetHdc(); WIN32.SendMessage(control.Handle, WIN32.WM_PRINT, hdc, meptr); g2.ReleaseHdc(hdc); g2.Dispose(); return(true); }
private Point findCaret() { Point pointCaret = new Point(0); int i_char_loc = this.SelectionStart; IntPtr pi_char_loc = new IntPtr(i_char_loc); int i_point = WIN32.SendMessage(this.Handle, WIN32.EM_POSFROMCHAR, pi_char_loc, IntPtr.Zero); pointCaret = new Point(i_point); if (i_char_loc == 0) { pointCaret = new Point(0); } else if (i_char_loc >= this.Text.Length) { pi_char_loc = new IntPtr(i_char_loc - 1); i_point = WIN32.SendMessage(this.Handle, WIN32.EM_POSFROMCHAR, pi_char_loc, IntPtr.Zero); pointCaret = new Point(i_point); Graphics g = this.CreateGraphics(); String t1 = this.Text.Substring(this.Text.Length - 1, 1) + "X"; SizeF sizet1 = g.MeasureString(t1, this.Font); SizeF sizex = g.MeasureString("X", this.Font); g.Dispose(); int xoffset = (int)(sizet1.Width - sizex.Width); pointCaret.X = pointCaret.X + xoffset; if (i_char_loc == this.Text.Length) { String slast = this.Text.Substring(Text.Length - 1, 1); if (slast == "\n") { pointCaret.X = 1; pointCaret.Y = pointCaret.Y + myFontHeight; } } } return(pointCaret); }
private void GetBitmaps() { if (myBitmap == null || myAlphaBitmap == null || myBitmap.Width != Width || myBitmap.Height != Height || myAlphaBitmap.Width != Width || myAlphaBitmap.Height != Height) { myBitmap = null; myAlphaBitmap = null; } if (myBitmap == null) { myBitmap = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);//(Width,Height); myUpToDate = false; } if (!myUpToDate) { this.SetStyle(ControlStyles.UserPaint, false); WIN32.CaptureWindow(this, ref myBitmap); this.SetStyle(ControlStyles.UserPaint, true); this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); this.BackColor = Color.FromArgb(myBackAlpha, myBackColor); } Rectangle r2 = new Rectangle(0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height); ImageAttributes tempImageAttr = new ImageAttributes(); ColorMap[] tempColorMap = new ColorMap[1]; tempColorMap[0] = new ColorMap(); tempColorMap[0].OldColor = Color.FromArgb(255, myBackColor); tempColorMap[0].NewColor = Color.FromArgb(myBackAlpha, myBackColor); tempImageAttr.SetRemapTable(tempColorMap); if (myAlphaBitmap != null) { myAlphaBitmap.Dispose(); } myAlphaBitmap = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height); Graphics tempGraphics1 = Graphics.FromImage(myAlphaBitmap); //tempGraphics1.DrawImage(myBitmap, r2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, GraphicsUnit.Pixel, tempImageAttr); tempGraphics1.DrawImage(myBitmap, r2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, GraphicsUnit.Pixel, tempImageAttr); tempGraphics1.Dispose(); //if (this.Focused && (this.SelectionLength == 0)) //{ // Graphics tempGraphics2 = Graphics.FromImage(myAlphaBitmap); // if (myCaretState) // { // Point caret = this.findCaret(); // Pen p = new Pen(this.ForeColor, 3); // tempGraphics2.DrawLine(p, caret.X, caret.Y + 0, caret.X, caret.Y + myFontHeight); // tempGraphics2.Dispose(); // } //} }
/// <summary> /// 显示和消失动画 /// </summary> private void animate() { if (!timer1.Enabled) { if (backImg != null) { backImg.Dispose(); } backImg = null; backImg = new Bitmap(base.ClientRectangle.Width, base.ClientRectangle.Height); base.DrawToBitmap(backImg, base.ClientRectangle); if (alphaback != null) { alphaback.Dispose(); } alphaback = null; alphaback = new Bitmap(base.ClientRectangle.Width, base.ClientRectangle.Height); if (base.BackgroundImage != null) { backgroundTemp = (Bitmap)base.BackgroundImage; base.BackgroundImage = null; } if (base.BackColor != Color.Transparent) { backcolorTemp = base.BackColor; base.BackColor = Color.Transparent; } WIN32.CaptureWindow(this, ref alphaback); if (picbox != null) { picbox.Dispose(); } picbox = null; picbox = new uPictureBox(); this.Controls.Add(picbox); picbox.Dock = DockStyle.Fill; if (!shown) { picbox.Image = alphaback; } else { picbox.Image = backImg; } picbox.BringToFront(); base.Visible = true; if (!shown) { if (gbackImg != null) { gbackImg.Dispose(); } gbackImg = null; gbackImg = Graphics.FromImage(alphaback); gbackImg.SmoothingMode = SmoothingMode.HighQuality; } else { if (gbackImg != null) { gbackImg.Dispose(); } gbackImg = null; gbackImg = Graphics.FromImage(backImg); gbackImg.SmoothingMode = SmoothingMode.HighQuality; } isfirst = true; this.timer1.Start(); } }