Beispiel #1
0
        /// <summary>Resizes the bitmap to the specified size.</summary>
        /// <remarks>This should be overloaded to speed up the resize.</remarks>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="mode">The resize mode.</param>
        /// <returns></returns>
        public virtual Bitmap32 Resize(int width, int height, ResizeMode mode = 0)
        {
            var   result = new Bitmap32(width, height);
            float w      = width;
            float h      = height;

            if (mode != ResizeMode.None)
            {
                float fw = w / (float)Width;
                float fh = h / (float)Height;
                float f;
                if (mode.HasFlag(ResizeMode.TouchFromInside))
                {
                    f = Math.Min(fw, fh);
                }
                else
                {
                    f = Math.Max(fw, fh);
                }
                w = Width * f;
                h = Height * f;
            }
            float x = (width - w) / 2;
            float y = (height - h) / 2;

            result.Draw(this, x, y, w, h);
            return(result);
        }
Beispiel #2
0
 // Use Windows messages to handle resizing of the ruler at the edges
 // and moving of the cursor marker.
 protected override void WndProc(ref Message m)
 {
     switch (m.Msg)
     {
     //WM_NCHITTEST (sent for all mouse events)
     case 0x84:
         // Get mouse position and convert to app coordinates
         Point pos = Cursor.Position;
         pos = this.PointToClient(pos);
         // Check if inside grip area (5 pixels next to border)
         if (ResizeMode.HasFlag(FormResizeMode.Horizontal))
         {
             if (pos.X <= GRIP_OFFSET)
             {
                 m.Result = (IntPtr)HTLEFT;
                 return;
             }
             else if (pos.X >= this.ClientSize.Width - GRIP_OFFSET)
             {
                 m.Result = (IntPtr)HTRIGHT;
                 return;
             }
         }
         if (ResizeMode.HasFlag(FormResizeMode.Vertical))
         {
             if (pos.Y <= GRIP_OFFSET)
             {
                 m.Result = (IntPtr)HTTOP;
                 return;
             }
             else if (pos.Y >= this.ClientSize.Height - GRIP_OFFSET)
             {
                 m.Result = (IntPtr)HTBOTTOM;
                 return;
             }
         }
         break;
     }
     // Pass return message down to base class
     base.WndProc(ref m);
 }