Example #1
0
        public Vector2 ClampRectSizeDelta(Vector2 rectSizeDelta, ResizeAnchor anchor)
        {
            var rect = rectTransform.rect;

            if (RectConstrain != null)
            {
                var rectConstrainRect = GetRectConstrainRect();

                if (anchor == ResizeAnchor.BottomLeft || anchor == ResizeAnchor.TopLeft)
                {
                    rectSizeDelta.x = Mathf.Min(rectSizeDelta.x, rect.xMin - rectConstrainRect.xMin);
                }
                else if (anchor == ResizeAnchor.BottomRight || anchor == ResizeAnchor.TopRight)
                {
                    rectSizeDelta.x = Mathf.Min(rectSizeDelta.x, rectConstrainRect.xMax - rect.xMax);
                }

                if (anchor == ResizeAnchor.BottomLeft || anchor == ResizeAnchor.BottomRight)
                {
                    rectSizeDelta.y = Mathf.Min(rectSizeDelta.y, rect.yMin - rectConstrainRect.yMin);
                }
                else if (anchor == ResizeAnchor.TopLeft || anchor == ResizeAnchor.TopRight)
                {
                    rectSizeDelta.y = Mathf.Min(rectSizeDelta.y, rectConstrainRect.yMax - rect.yMax);
                }
            }

            return(ClampRectSize(rectSizeDelta + rect.size) - rect.size);
        }
 /// <summary>
 /// Determines resizing anchor and sets appropriate Cursor.
 /// </summary>
 /// <param name="p">Coordinates of the mouse pointer.</param>
 public void SetCursor(Point p)
 {
     if (p.Y < ResizingArea && p.X < ResizingArea)
     {
         anchor         = ResizeAnchor.TopLeft;
         element.Cursor = Cursors.SizeNWSE;
     }
     else if (p.Y < ResizingArea && p.X >= (element.ActualWidth - ResizingArea))
     {
         anchor         = ResizeAnchor.TopRight;
         element.Cursor = Cursors.SizeNESW;
     }
     else if (p.Y < ResizingArea)
     {
         if (CanResizeVertically)
         {
             anchor         = ResizeAnchor.Top;
             element.Cursor = Cursors.SizeNS;
         }
     }
     else if (p.X < ResizingArea && p.Y >= (element.ActualHeight - ResizingArea))
     {
         anchor         = ResizeAnchor.BottomLeft;
         element.Cursor = Cursors.SizeNESW;
     }
     else if (p.X < ResizingArea)
     {
         if (CanResizeHorizontally)
         {
             anchor         = ResizeAnchor.Left;
             element.Cursor = Cursors.SizeWE;
         }
     }
     else if (p.X >= (element.ActualWidth - ResizingArea) && p.Y >= (element.ActualHeight - ResizingArea))
     {
         anchor         = ResizeAnchor.BottomRight;
         element.Cursor = Cursors.SizeNWSE;
     }
     else if (p.X >= (element.ActualWidth - ResizingArea))
     {
         if (CanResizeHorizontally)
         {
             anchor         = ResizeAnchor.Right;
             element.Cursor = Cursors.SizeWE;
         }
     }
     else if (p.Y >= (element.ActualHeight - ResizingArea))
     {
         if (CanResizeVertically)
         {
             anchor         = ResizeAnchor.Bottom;
             element.Cursor = Cursors.SizeNS;
         }
     }
     else
     {
         anchor         = ResizeAnchor.None;
         element.Cursor = null;
     }
 }
 /// <summary>
 /// Constructs a new ResizeDialog for resizing a TilemapLayer 
 /// </summary>
 public ResizeDialog(TilemapLayer layer)
 {
     InitializeComponent();
     Layer = layer;
     textBoxWidth.Text = layer.Width.ToString();
     textBoxHeight.Text = layer.Height.ToString();
     resizeAnchor = ResizeAnchor.TopRight;
 }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ResizeController"/> class.
        /// </summary>
        /// <param name="resizableElement">The resizable element.</param>
        public ResizeController(IResizableElement resizableElement)
        {
            if (resizableElement == null)
                throw new ArgumentNullException("resizableElement");

            element = resizableElement;
            anchor = ResizeAnchor.None;
            ResizingArea = ResizingAreaDefaultValue;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ResizeController"/> class.
        /// </summary>
        /// <param name="resizableElement">The resizable element.</param>
        public ResizeController(IResizableElement resizableElement)
        {
            if (resizableElement == null)
            {
                throw new ArgumentNullException("resizableElement");
            }

            element      = resizableElement;
            anchor       = ResizeAnchor.None;
            ResizingArea = ResizingAreaDefaultValue;
        }
Example #6
0
        public Window()
        {
            InitializeComponent();

            this.innerContentPresenterOffset = -1.0;
            this.isMaximized     = false;
            this.showMinButton   = true;
            this.showMaxButton   = true;
            this.draggingEnabled = true;
            this.caption         = "";
            this.isDragging      = false;
            this.isResizing      = false;
            this.resizeAnchor    = ResizeAnchor.None;
            this.resizeEnabled   = true;
            base.Loaded         += new RoutedEventHandler(Windows_Loaded);
            base.LayoutUpdated  += new EventHandler(this.Windows_LayoutUpdated);
        }
Example #7
0
        void window_MouseMove(object sender, MouseEventArgs e)
        {
            if (ResizeEnabled)
            {
                if (!isResizing)
                {
                    Point pos = e.GetPosition(window);

                    if ((pos.Y <= HotSpotWidth) && (pos.X <= HotSpotWidth))
                    {
                        window.Cursor = Cursors.Hand;
                        resizeAnchor  = ResizeAnchor.TopLeft;
                    }
                    else if ((pos.Y <= HotSpotWidth) && (pos.X >= (window.ActualWidth - HotSpotWidth)))
                    {
                        window.Cursor = Cursors.Hand;
                        resizeAnchor  = ResizeAnchor.TopRight;
                    }
                    else if (pos.Y <= HotSpotWidth)
                    {
                        window.Cursor = Cursors.SizeNS;
                        resizeAnchor  = ResizeAnchor.Top;
                    }
                    else if ((pos.Y >= (window.ActualHeight - HotSpotWidth)) && (pos.X <= HotSpotWidth))
                    {
                        window.Cursor = Cursors.Hand;
                        resizeAnchor  = ResizeAnchor.BottomLeft;
                    }
                    else if ((pos.Y >= (window.ActualHeight - HotSpotWidth)) && (pos.X >= (window.ActualWidth - HotSpotWidth)))
                    {
                        window.Cursor = Cursors.Hand;
                        resizeAnchor  = ResizeAnchor.BottomRight;
                    }
                    else if (pos.Y >= (window.ActualHeight - HotSpotWidth))
                    {
                        window.Cursor = Cursors.SizeNS;
                        resizeAnchor  = ResizeAnchor.Bottom;
                    }
                    else if (pos.X <= HotSpotWidth)
                    {
                        window.Cursor = Cursors.SizeWE;
                        resizeAnchor  = ResizeAnchor.Left;
                    }
                    else if (pos.X >= (window.ActualWidth - HotSpotWidth))
                    {
                        window.Cursor = Cursors.SizeWE;
                        resizeAnchor  = ResizeAnchor.Right;
                    }
                    else
                    {
                        window.Cursor = null;
                        resizeAnchor  = ResizeAnchor.None;
                    }
                }
                else
                {
                    Point position = e.GetPosition(this.Parent as UIElement);

                    double deltaX = position.X - initialResizePoint.X;
                    double deltaY = position.Y - initialResizePoint.Y;

                    switch (resizeAnchor)
                    {
                    case ResizeAnchor.Left:
                        ResizeLeft(deltaX);
                        break;

                    case ResizeAnchor.Top:
                        ResizeTop(deltaY);
                        break;

                    case ResizeAnchor.Right:
                        ResizeRight(deltaX);
                        break;

                    case ResizeAnchor.Bottom:
                        ResizeBottom(deltaY);
                        break;

                    case ResizeAnchor.TopLeft:
                        ResizeLeft(deltaX);
                        ResizeTop(deltaY);
                        break;

                    case ResizeAnchor.TopRight:
                        ResizeRight(deltaX);
                        ResizeTop(deltaY);
                        break;

                    case ResizeAnchor.BottomLeft:
                        ResizeLeft(deltaX);
                        ResizeBottom(deltaY);
                        break;

                    case ResizeAnchor.BottomRight:
                        ResizeRight(deltaX);
                        ResizeBottom(deltaY);
                        break;
                    }

                    // let's resize the contentpresenter to fix the resize bug of controls inside a scrollviewer with
                    // horizontal scrollbar visible
                    contentpresenter.Width = this.Width - innerContentPresenterOffset;
                }
            }
        }
Example #8
0
 /// <summary>
 /// Determines resizing anchor and sets appropriate Cursor.
 /// </summary>
 /// <param name="p">Coordinates of the mouse pointer.</param>
 public void SetCursor(Point p)
 {
     if (p.Y < ResizingArea && p.X < ResizingArea)
     {
         anchor = ResizeAnchor.TopLeft;
         element.Cursor = Cursors.SizeNWSE;
     }
     else if (p.Y < ResizingArea && p.X >= (element.ActualWidth - ResizingArea))
     {
         anchor = ResizeAnchor.TopRight;
         element.Cursor = Cursors.SizeNESW;
     }
     else if (p.Y < ResizingArea)
     {
         if (CanResizeVertically)
         {
             anchor = ResizeAnchor.Top;
             element.Cursor = Cursors.SizeNS;
         }
     }
     else if (p.X < ResizingArea && p.Y >= (element.ActualHeight - ResizingArea))
     {
         anchor = ResizeAnchor.BottomLeft;
         element.Cursor = Cursors.SizeNESW;
     }
     else if (p.X < ResizingArea)
     {
         if (CanResizeHorizontally)
         {
             anchor = ResizeAnchor.Left;
             element.Cursor = Cursors.SizeWE;
         }
     }
     else if (p.X >= (element.ActualWidth - ResizingArea) && p.Y >= (element.ActualHeight - ResizingArea))
     {
         anchor = ResizeAnchor.BottomRight;
         element.Cursor = Cursors.SizeNWSE;
     }
     else if (p.X >= (element.ActualWidth - ResizingArea))
     {
         if (CanResizeHorizontally)
         {
             anchor = ResizeAnchor.Right;
             element.Cursor = Cursors.SizeWE;
         }
     }
     else if (p.Y >= (element.ActualHeight - ResizingArea))
     {
         if (CanResizeVertically)
         {
             anchor = ResizeAnchor.Bottom;
             element.Cursor = Cursors.SizeNS;
         }
     }
     else
     {
         anchor = ResizeAnchor.None;
         element.Cursor = null;
     }
 }
Example #9
0
    /// <summary>
    /// อัพโหลดภาพ พร้อมย่อขนาด
    /// </summary>
    /// <param name="fuPhoto"></param>
    /// <param name="pathShort"></param>
    /// <param name="photoName"></param>
    /// <param name="errorMessage"></param>
    /// <param name="outFileName"></param>
    /// <param name="maxSizeKB"></param>
    /// <param name="maxWidth"></param>
    /// <param name="maxHeight"></param>
    /// <param name="resizeAnchor"></param>
    /// <param name="resizeMode"></param>
    /// <param name="resizeFormat"></param>
    /// <returns></returns>
    /// <example>
    /// clsIO clsIO = new clsIO();
    /// string outErrorMessage;
    /// string outFileName;
    /// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName);
    /// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName,maxWidth:200,resizeFormat:clsIO.ResizeFormat.png);
    /// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName,maxWidth:200,maxHeight:200,resizeFormat:clsIO.ResizeFormat.png);
    /// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName,maxWidth:200,maxHeight:200,resizeMode:clsIO.ResizeMode.crop,resizeQuality:100);
    /// </example>
    public bool UploadPhoto(FileUpload fuPhoto, string pathShort, string photoName, out string errorMessage, out string outFileName, int maxSizeKB = 0, int maxWidth = 0, int maxHeight = 0, ResizeAnchor resizeAnchor = ResizeAnchor.middlecenter, ResizeMode resizeMode = ResizeMode.crop, ResizeFormat resizeFormat = ResizeFormat.original, int resizeQuality = 90)
    {
        bool rtnValue = true;

        errorMessage = "";
        outFileName  = "";

        if (fuPhoto.HasFile == true)
        {
            #region Error Checker
            if (FileTypeChecker(fuPhoto.FileName) != "IMG")
            {
                errorMessage = "โปรดเลือกเฉพาะไฟล์รูปภาพ";
                fuPhoto.Focus();
                return(false);
            }
            if (maxSizeKB > 0)
            {
                if (fuPhoto.PostedFile.ContentLength > maxSizeKB * 1000)
                {
                    errorMessage = "ขนาดไฟล์ใหญ่เกิน " + maxSizeKB + " KB";
                    fuPhoto.Focus();
                    return(false);
                }
            }
            #endregion

            #region Out FileName
            if (resizeFormat != ResizeFormat.original)
            {
                outFileName = photoName + "." + resizeFormat.ToString();
            }
            else
            {
                outFileName = photoName + System.IO.Path.GetExtension(fuPhoto.FileName).ToLower();
            }
            #endregion

            FileExist(pathShort + outFileName, true);

            #region Upload Photo
            try
            {
                fuPhoto.SaveAs(System.Web.HttpContext.Current.Server.MapPath(pathShort + outFileName));
            }
            catch (Exception ex)
            {
                errorMessage = "เกิดข้อผิดพลาด ขณะอัพโหลดไฟล์ไว้ที่ " + System.Web.HttpContext.Current.Server.MapPath(pathShort + outFileName + "<br/>" + ex.Message);
                fuPhoto.Focus();
                return(false);
            }
            #endregion

            #region Resize Photo
            try
            {
                #region Condition Builder
                string resizeSetting = "";
                if (maxWidth > 0)
                {
                    if (resizeSetting.Length > 0)
                    {
                        resizeSetting += "&";
                    }
                    resizeSetting += "width=" + maxWidth.ToString();
                }
                if (maxHeight > 0)
                {
                    if (resizeSetting.Length > 0)
                    {
                        resizeSetting += "&";
                    }
                    resizeSetting += "height=" + maxHeight.ToString();
                }
                if (resizeMode != ResizeMode.pad)
                {
                    if (resizeSetting.Length > 0)
                    {
                        resizeSetting += "&";
                    }
                    resizeSetting += "mode=" + resizeMode.ToString();
                }
                if (resizeAnchor != ResizeAnchor.middlecenter)
                {
                    if (resizeSetting.Length > 0)
                    {
                        resizeSetting += "&";
                    }
                    resizeSetting += "anchor=" + resizeAnchor.ToString();
                }
                if (resizeFormat != ResizeFormat.original)
                {
                    if (resizeSetting.Length > 0)
                    {
                        resizeSetting += "&";
                    }
                    resizeSetting += "format=" + resizeFormat.ToString();
                }
                if (resizeQuality != 90)
                {
                    if (resizeSetting.Length > 0)
                    {
                        resizeSetting += "&";
                    }
                    resizeSetting += "quality=" + resizeQuality.ToString();
                }
                #endregion

                if (resizeSetting.Length > 0)
                {
                    ResizeSettings imageResizerSetting = new ResizeSettings(resizeSetting);
                    ImageBuilder.Current.Build(
                        System.Web.HttpContext.Current.Server.MapPath(pathShort + outFileName),
                        System.Web.HttpContext.Current.Server.MapPath(pathShort + outFileName), imageResizerSetting);
                }
            }
            catch (Exception ex)
            {
                errorMessage = "เกิดข้อผิดพลาด ขณะย่อขนาดภาพ : " + ex.Message;
                fuPhoto.Focus();
                return(false);
            }
            #endregion
        }
        else
        {
            errorMessage = "ไม่พบไฟล์ที่ต้องการอัพโหลด";
            fuPhoto.Focus();
            return(false);
        }

        return(rtnValue);
    }
Example #10
0
        private void window_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.ResizeEnabled)
            {
                if (!this.isResizing)
                {
                    Point position = e.GetPosition(this.window);
                    if ((position.Y <= 10.0) && (position.X <= 10.0))
                    {
                        this.window.Cursor = Cursors.Hand;
                        this.resizeAnchor = ResizeAnchor.TopLeft;
                    }
                    else if ((position.Y <= 10.0) && (position.X >= (this.window.ActualWidth - 10.0)))
                    {
                        this.window.Cursor = Cursors.Hand;
                        this.resizeAnchor = ResizeAnchor.TopRight;
                    }
                    else if (position.Y <= 3.0)
                    {
                        this.window.Cursor = Cursors.SizeNS;
                        this.resizeAnchor = ResizeAnchor.Top;
                    }
                    else if ((position.Y >= (this.window.ActualHeight - 10.0)) && (position.X <= 10.0))
                    {
                        this.window.Cursor = Cursors.Hand;
                        this.resizeAnchor = ResizeAnchor.BottomLeft;
                    }
                    else if ((position.Y >= (this.window.ActualHeight - 10.0)) && (position.X >= (this.window.ActualWidth - 10.0)))
                    {
                        this.window.Cursor = Cursors.Hand;
                        this.resizeAnchor = ResizeAnchor.BottomRight;
                    }
                    else if (position.Y >= (this.window.ActualHeight - 3.0))
                    {
                        this.window.Cursor = Cursors.SizeNS;
                        this.resizeAnchor = ResizeAnchor.Bottom;
                    }
                    else if (position.X <= 3.0)
                    {
                        this.window.Cursor = Cursors.SizeWE;
                        this.resizeAnchor = ResizeAnchor.Left;
                    }
                    else if (position.X >= (this.window.ActualWidth - 3.0))
                    {
                        this.window.Cursor = Cursors.SizeWE;
                        this.resizeAnchor = ResizeAnchor.Right;
                    }
                    else
                    {
                        this.window.Cursor = null;
                        this.resizeAnchor = ResizeAnchor.None;
                    }
                }
                else
                {
                    Point point2 = e.GetPosition(base.Parent as UIElement);
                    double deltaX = point2.X - this.initialResizePoint.X;
                    double deltaY = point2.Y - this.initialResizePoint.Y;
                    switch (this.resizeAnchor)
                    {
                        case ResizeAnchor.Left:
                            this.ResizeLeft(deltaX);
                            break;

                        case ResizeAnchor.TopLeft:
                            this.ResizeLeft(deltaX);
                            this.ResizeTop(deltaY);
                            break;

                        case ResizeAnchor.Top:
                            this.ResizeTop(deltaY);
                            break;

                        case ResizeAnchor.TopRight:
                            this.ResizeRight(deltaX);
                            this.ResizeTop(deltaY);
                            break;

                        case ResizeAnchor.Right:
                            this.ResizeRight(deltaX);
                            break;

                        case ResizeAnchor.BottomRight:
                            this.ResizeRight(deltaX);
                            this.ResizeBottom(deltaY);
                            break;

                        case ResizeAnchor.Bottom:
                            this.ResizeBottom(deltaY);
                            break;

                        case ResizeAnchor.BottomLeft:
                            this.ResizeLeft(deltaX);
                            this.ResizeBottom(deltaY);
                            break;
                    }
                }
            }
        }
Example #11
0
 /// <summary>
 /// Event handler for Top Right button; changes the resize anchor point
 /// </summary>
 private void radioButtonTR_CheckedChanged(object sender, EventArgs e)
 {
     resizeAnchor = ResizeAnchor.TopRight;
 }
Example #12
0
 /// <summary>
 /// Event handler for Center button; changes the resize anchor point
 /// </summary>
 private void radioButtonC_CheckedChanged(object sender, EventArgs e)
 {
     resizeAnchor = ResizeAnchor.Center;
 }
Example #13
0
 /// <summary>
 /// Event handler for Bottom Left button; changes the resize anchor point
 /// </summary>
 private void radioButtonBL_CheckedChanged(object sender, EventArgs e)
 {
     resizeAnchor = ResizeAnchor.BottomLeft;
 }
Example #14
0
    /// <summary>
    /// อัพโหลดภาพ พร้อมย่อขนาด
    /// </summary>
    /// <param name="fuPhoto"></param>
    /// <param name="pathShort"></param>
    /// <param name="photoName"></param>
    /// <param name="errorMessage"></param>
    /// <param name="outFileName"></param>
    /// <param name="maxSizeKB"></param>
    /// <param name="maxWidth"></param>
    /// <param name="maxHeight"></param>
    /// <param name="resizeAnchor"></param>
    /// <param name="resizeMode"></param>
    /// <param name="resizeFormat"></param>
    /// <returns></returns>
    /// <example>
    /// clsIO clsIO = new clsIO();
    /// string outErrorMessage;
    /// string outFileName;
    /// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName);
    /// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName,maxWidth:200,resizeFormat:clsIO.ResizeFormat.png);
    /// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName,maxWidth:200,maxHeight:200,resizeFormat:clsIO.ResizeFormat.png);
    /// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName,maxWidth:200,maxHeight:200,resizeMode:clsIO.ResizeMode.crop,resizeQuality:100);
    /// </example>
    public bool UploadPhoto(FileUpload fuPhoto, string pathShort, string photoName, out string errorMessage, out string outFileName, int maxSizeKB = 0, int maxWidth = 0, int maxHeight = 0, ResizeAnchor resizeAnchor = ResizeAnchor.middlecenter, ResizeMode resizeMode = ResizeMode.crop, ResizeFormat resizeFormat = ResizeFormat.original, int resizeQuality = 90)
    {

        bool rtnValue = true;
        errorMessage = "";
        outFileName = "";

        if (fuPhoto.HasFile == true)
        {
            #region Error Checker
            if (FileTypeChecker(fuPhoto.FileName) != "IMG")
            {
                errorMessage = "โปรดเลือกเฉพาะไฟล์รูปภาพ";
                fuPhoto.Focus();
                return false;
            }
            if (maxSizeKB > 0)
            {
                if (fuPhoto.PostedFile.ContentLength > maxSizeKB * 1000)
                {
                    errorMessage = "ขนาดไฟล์ใหญ่เกิน " + maxSizeKB + " KB";
                    fuPhoto.Focus();
                    return false;
                }
            }
            #endregion

            #region Out FileName
            if (resizeFormat != ResizeFormat.original)
            {
                outFileName = photoName + "." + resizeFormat.ToString();
            }
            else
            {
                outFileName = photoName + System.IO.Path.GetExtension(fuPhoto.FileName).ToLower();
            }
            #endregion

            FileExist(pathShort + outFileName, true);

            #region Upload Photo
            try
            {
                fuPhoto.SaveAs(System.Web.HttpContext.Current.Server.MapPath(pathShort + outFileName));
            }
            catch (Exception ex)
            {
                errorMessage = "เกิดข้อผิดพลาด ขณะอัพโหลดไฟล์ไว้ที่ " + System.Web.HttpContext.Current.Server.MapPath(pathShort + outFileName + "<br/>" + ex.Message);
                fuPhoto.Focus();
                return false;
            }
            #endregion

            #region Resize Photo
            try
            {
                #region Condition Builder
                string resizeSetting = "";
                if (maxWidth > 0)
                {
                    if (resizeSetting.Length > 0) resizeSetting += "&";
                    resizeSetting += "width=" + maxWidth.ToString();
                }
                if (maxHeight > 0)
                {
                    if (resizeSetting.Length > 0) resizeSetting += "&";
                    resizeSetting += "height=" + maxHeight.ToString();
                }
                if (resizeMode != ResizeMode.pad)
                {
                    if (resizeSetting.Length > 0) resizeSetting += "&";
                    resizeSetting += "mode=" + resizeMode.ToString();
                }
                if (resizeAnchor != ResizeAnchor.middlecenter)
                {
                    if (resizeSetting.Length > 0) resizeSetting += "&";
                    resizeSetting += "anchor=" + resizeAnchor.ToString();
                }
                if (resizeFormat != ResizeFormat.original)
                {
                    if (resizeSetting.Length > 0) resizeSetting += "&";
                    resizeSetting += "format=" + resizeFormat.ToString();
                }
                if (resizeQuality != 90)
                {
                    if (resizeSetting.Length > 0) resizeSetting += "&";
                    resizeSetting += "quality=" + resizeQuality.ToString();
                }
                #endregion

                if (resizeSetting.Length > 0)
                {
                    ResizeSettings imageResizerSetting = new ResizeSettings(resizeSetting);
                    ImageBuilder.Current.Build(
                        System.Web.HttpContext.Current.Server.MapPath(pathShort + outFileName),
                        System.Web.HttpContext.Current.Server.MapPath(pathShort + outFileName), imageResizerSetting);
                }
            }
            catch (Exception ex)
            {
                errorMessage = "เกิดข้อผิดพลาด ขณะย่อขนาดภาพ : " + ex.Message;
                fuPhoto.Focus();
                return false;
            }
            #endregion
        }
        else
        {
            errorMessage = "ไม่พบไฟล์ที่ต้องการอัพโหลด";
            fuPhoto.Focus();
            return false;
        }

        return rtnValue;
    }
Example #15
0
        public Window()
        {
            InitializeComponent();

            this.innerContentPresenterOffset = -1.0;
            this.isMaximized = false;
            this.showMinButton = true;
            this.showMaxButton = true;
            this.draggingEnabled = true;
            this.caption = "";
            this.isDragging = false;
            this.isResizing = false;
            this.resizeAnchor = ResizeAnchor.None;
            this.resizeEnabled = true;
            base.Loaded += new RoutedEventHandler(Windows_Loaded);
            base.LayoutUpdated += new EventHandler(this.Windows_LayoutUpdated);
        }
Example #16
0
        private void sizingBorderMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (WindowState == WindowState.Normal && CanResize)
            {
                FrameworkElement borderSegment = (FrameworkElement)sender;

                ResizeOperation op;
                if (_resizeBorders.TryGetValue(borderSegment, out op))
                {
                    _resizeAnchor = new ResizeAnchor(this, e.GetPosition(this), op);
                    borderSegment.CaptureMouse();
                }
            }
        }
Example #17
0
        private void window_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.ResizeEnabled)
            {
                if (!this.isResizing)
                {
                    Point position = e.GetPosition(this.window);
                    if ((position.Y <= 10.0) && (position.X <= 10.0))
                    {
                        this.window.Cursor = Cursors.Hand;
                        this.resizeAnchor  = ResizeAnchor.TopLeft;
                    }
                    else if ((position.Y <= 10.0) && (position.X >= (this.window.ActualWidth - 10.0)))
                    {
                        this.window.Cursor = Cursors.Hand;
                        this.resizeAnchor  = ResizeAnchor.TopRight;
                    }
                    else if (position.Y <= 3.0)
                    {
                        this.window.Cursor = Cursors.SizeNS;
                        this.resizeAnchor  = ResizeAnchor.Top;
                    }
                    else if ((position.Y >= (this.window.ActualHeight - 10.0)) && (position.X <= 10.0))
                    {
                        this.window.Cursor = Cursors.Hand;
                        this.resizeAnchor  = ResizeAnchor.BottomLeft;
                    }
                    else if ((position.Y >= (this.window.ActualHeight - 10.0)) && (position.X >= (this.window.ActualWidth - 10.0)))
                    {
                        this.window.Cursor = Cursors.Hand;
                        this.resizeAnchor  = ResizeAnchor.BottomRight;
                    }
                    else if (position.Y >= (this.window.ActualHeight - 3.0))
                    {
                        this.window.Cursor = Cursors.SizeNS;
                        this.resizeAnchor  = ResizeAnchor.Bottom;
                    }
                    else if (position.X <= 3.0)
                    {
                        this.window.Cursor = Cursors.SizeWE;
                        this.resizeAnchor  = ResizeAnchor.Left;
                    }
                    else if (position.X >= (this.window.ActualWidth - 3.0))
                    {
                        this.window.Cursor = Cursors.SizeWE;
                        this.resizeAnchor  = ResizeAnchor.Right;
                    }
                    else
                    {
                        this.window.Cursor = null;
                        this.resizeAnchor  = ResizeAnchor.None;
                    }
                }
                else
                {
                    Point  point2 = e.GetPosition(base.Parent as UIElement);
                    double deltaX = point2.X - this.initialResizePoint.X;
                    double deltaY = point2.Y - this.initialResizePoint.Y;
                    switch (this.resizeAnchor)
                    {
                    case ResizeAnchor.Left:
                        this.ResizeLeft(deltaX);
                        break;

                    case ResizeAnchor.TopLeft:
                        this.ResizeLeft(deltaX);
                        this.ResizeTop(deltaY);
                        break;

                    case ResizeAnchor.Top:
                        this.ResizeTop(deltaY);
                        break;

                    case ResizeAnchor.TopRight:
                        this.ResizeRight(deltaX);
                        this.ResizeTop(deltaY);
                        break;

                    case ResizeAnchor.Right:
                        this.ResizeRight(deltaX);
                        break;

                    case ResizeAnchor.BottomRight:
                        this.ResizeRight(deltaX);
                        this.ResizeBottom(deltaY);
                        break;

                    case ResizeAnchor.Bottom:
                        this.ResizeBottom(deltaY);
                        break;

                    case ResizeAnchor.BottomLeft:
                        this.ResizeLeft(deltaX);
                        this.ResizeBottom(deltaY);
                        break;
                    }
                }
            }
        }
Example #18
0
        private void UpdateResizeHandle(ResizeAnchor resizeAnchor)
        {
            ChatPanelResizeHandleUI resizeHandle = null;

            if (_resizeHandles.ContainsKey(resizeAnchor))
            {
                resizeHandle = _resizeHandles[resizeAnchor];
            }

            if ((ResizeHandleAnchors & resizeAnchor) == resizeAnchor)
            {
                if (resizeHandle == null && IsResizable)
                {
                    var go = new GameObject("Panel Resize Handle");
                    go.AddComponent <RectTransform>();
                    go.AddComponent <Image>().color = Color.clear;
                    resizeHandle = go.AddComponent <ChatPanelResizeHandleUI>();
                    resizeHandle.transform.SetParent(rectTransform.transform, false);
                    _resizeHandles.Add(resizeAnchor, resizeHandle);
                }

                if (resizeHandle != null)
                {
                    if (IsResizable)
                    {
                        resizeHandle.enabled = true;

                        Vector2 pivot = Vector2.zero;

                        if (ResizeAnchor.BottomLeft == resizeAnchor)
                        {
                            pivot = new Vector2(0.0f, 0.0f);
                        }
                        else if (ResizeAnchor.TopLeft == resizeAnchor)
                        {
                            pivot = new Vector2(0.0f, 1.0f);
                        }
                        else if (ResizeAnchor.BottomRight == resizeAnchor)
                        {
                            pivot = new Vector2(1.0f, 0.0f);
                        }
                        else if (ResizeAnchor.TopRight == resizeAnchor)
                        {
                            pivot = new Vector2(1.0f, 1.0f);
                        }

                        resizeHandle.rectTransform.anchorMin     =
                            resizeHandle.rectTransform.anchorMax = resizeHandle.rectTransform.pivot = pivot;

                        resizeHandle.rectTransform.anchoredPosition = Vector2.zero;
                        resizeHandle.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal,
                                                                             ResizeHandleSize.x);
                        resizeHandle.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical,
                                                                             ResizeHandleSize.y);

                        resizeHandle.Anchor = resizeAnchor;

                        resizeHandle.transform.SetAsLastSibling();
                        resizeHandle.ChatPanelUI = this;
                    }
                    else
                    {
                        resizeHandle.enabled = false;
                    }
                }
            }
            else if (resizeHandle != null)
            {
                resizeHandle.enabled = false;
            }
        }