//protected bool bolEnableDragMove = true; ///// <summary> ///// 是否允许鼠标拖拽移动图片 ///// </summary> //public bool EnableDragMode //{ // get // { // return bolEnableDragMove ; // } // set // { // bolEnableDragMove = value; // if( value == false ) // myDragPoint = null; // } //} private ReversibleDrawer CreateReversibleDrawer() { ReversibleDrawer drawer = ReversibleDrawer.FromHwnd(this.Handle); drawer.PenColor = Color.White; drawer.PenStyle = PenStyle.PS_SOLID; drawer.LineWidth = 1; return(drawer); }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { if (myImage != null) { System.Drawing.Point sp = this.AutoScrollPosition; System.Drawing.Rectangle rect = this.ImageBounds; System.Drawing.Point ip = rect.Location; System.Drawing.Rectangle ClipRect = e.ClipRectangle; ClipRect.Offset(0 - sp.X, 0 - sp.Y); rect = System.Drawing.Rectangle.Intersect(ClipRect, rect); if (rect.Width > 0 || rect.Height > 0) { e.Graphics.DrawImage(myImage, new System.Drawing.Rectangle (rect.Left + sp.X, rect.Top + sp.Y, rect.Width, rect.Height), new System.Drawing.Rectangle(rect.Left - ip.X, rect.Top - ip.Y, rect.Width, rect.Height), System.Drawing.GraphicsUnit.Pixel); // rect = this.ImageBounds ; // rect.Offset( - sp.X , - sp.Y ); // if( this.Focused ) // System.Windows.Forms.ControlPaint.DrawFocusRectangle( e.Graphics , rect ); } //string strText = "宽:" + myImage.Size.Width + " 高:" + myImage.Size.Height + " 格式:" + myImage.PixelFormat ; } if (this.BehaviorStyle == XPictureBoxBehaviorStyle.DragSelect) { using (ReversibleDrawer drawer = new ReversibleDrawer(e.Graphics)) { drawer.PenColor = Color.White; drawer.PenStyle = PenStyle.PS_SOLID; drawer.LineWidth = 1; Rectangle rect2 = this.SelectionBounds; if (rect2.IsEmpty == false) { rect2.Offset(this.AutoScrollPosition.X, this.AutoScrollPosition.Y); rect2.Offset(this.ImageBounds.Location); drawer.DrawRectangle(rect2); } if (myLastPoint != null) { drawer.DrawLine(0, myLastPoint.Y, this.ClientSize.Width, myLastPoint.Y); drawer.DrawLine(myLastPoint.X, 0, myLastPoint.X, this.ClientSize.Height); myLastPoint = null; } } } base.OnPaint(e); }
protected override void OnMouseLeave(EventArgs e) { if (myLastPoint != null) { using (ReversibleDrawer drawer = this.CreateReversibleDrawer()) { drawer.DrawLine(0, myLastPoint.Y, this.ClientSize.Width, myLastPoint.Y); drawer.DrawLine(myLastPoint.X, 0, myLastPoint.X, this.ClientSize.Height); myLastPoint = null; } } base.OnMouseLeave(e); }
/// <summary> /// 使用视图坐标绘制一个可逆矩形边框 /// </summary> /// <param name="left">矩形的左端位置</param> /// <param name="top">矩形的顶端位置</param> /// <param name="width">矩形的宽度</param> /// <param name="height">矩形的高度</param> public void ReversibleViewDrawRect( int left, int top, int width, int height) { //throw new NotImplementedException("documentviewcontrol:ReversibleViewDrawRect"); using (ReversibleDrawer drawer = ReversibleDrawer.FromHwnd(this.Handle)) { drawer.PenStyle = PenStyle.PS_DOT; drawer.PenColor = System.Drawing.Color.Red; this.RefreshScaleTransform(); System.Drawing.Rectangle rect = this.myTransform.UnTransformRectangle(left, top, width, height); drawer.DrawRectangle(rect); } }
private void cap_Draw(object sender, CaptureMouseMoveEventArgs e) { DragPointStyle hit = (DragPointStyle)e.Sender.Tag; System.Drawing.Rectangle rect = Rectangle.Ceiling(this.AbsBounds); System.Drawing.Point p1 = e.StartPosition; System.Drawing.Point p2 = e.CurrentPosition; SimpleRectangleTransform trans = this.OwnerDocument.EditorControl.GetTransformItemByDescPoint(rect.Left, rect.Top); if (trans != null) { p1 = trans.TransformPoint(p1); p2 = trans.TransformPoint(p2); rect = DragRectangle.CalcuteDragRectangle( (int)(p2.X - p1.X), (int)(p2.Y - p1.Y), hit, Rectangle.Ceiling(this.AbsBounds)); if (rect.Width > (int)this.OwnerDocument.Width) { rect.Width = (int)this.OwnerDocument.Width; } if (this.WidthHeightRate > 0.1) { rect.Height = (int)(rect.Width / this.WidthHeightRate); } LastDragBounds = rect; rect = trans.UnTransformRectangle(rect); using (ReversibleDrawer drawer = ReversibleDrawer.FromHwnd(this.OwnerDocument.EditorControl.Handle)) { drawer.PenStyle = PenStyle.PS_DOT; drawer.PenColor = System.Drawing.Color.Red; drawer.DrawRectangle(rect); } } }
protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) { if (this.BehaviorStyle == XPictureBoxBehaviorStyle.DragScroll) { if (myDragPoint != null) { System.Drawing.Point p = new System.Drawing.Point( 0 - this.AutoScrollPosition.X, 0 - this.AutoScrollPosition.Y); p.Offset(-e.X + myDragPoint.X, -e.Y + myDragPoint.Y); myDragPoint.X = e.X; myDragPoint.Y = e.Y; this.AutoScrollPosition = p; } else { if (myImage != null) { int x = e.X - this.AutoScrollPosition.X; int y = e.Y - this.AutoScrollPosition.Y; if (myImage.Size.Width > this.ClientSize.Width || myImage.Size.Height > this.ClientSize.Height) { if (this.ImageBounds.Contains(x, y)) { this.Cursor = System.Windows.Forms.Cursors.SizeAll; } else { this.Cursor = System.Windows.Forms.Cursors.Default; } } else { this.Cursor = System.Windows.Forms.Cursors.Default; } } } } else if (this.BehaviorStyle == XPictureBoxBehaviorStyle.DragSelect) { using (ReversibleDrawer drawer = this.CreateReversibleDrawer()) { if (myLastPoint != null) { drawer.DrawLine(0, myLastPoint.Y, this.ClientSize.Width, myLastPoint.Y); drawer.DrawLine(myLastPoint.X, 0, myLastPoint.X, this.ClientSize.Height); } else { myLastPoint = new myPointClass(); } if (this.ImageBounds.Contains(e.X, e.Y)) { myLastPoint.X = e.X; myLastPoint.Y = e.Y; drawer.DrawLine(0, myLastPoint.Y, this.ClientSize.Width, myLastPoint.Y); drawer.DrawLine(myLastPoint.X, 0, myLastPoint.X, this.ClientSize.Height); } else { myLastPoint = null; } } } base.OnMouseMove(e); }