Click here to Skip to main content
14,699,613 members
Home » Discussions » C#
   

C#

 
AnswerRe: Can not compare a file and same file stored in mysql - sha256 Pin
Luc Pattyn29-Apr-20 9:07
sitebuilderLuc Pattyn29-Apr-20 9:07 
GeneralRe: Can not compare a file and same file stored in mysql - sha256 Pin
wilcodk30-Apr-20 2:32
Memberwilcodk30-Apr-20 2:32 
AnswerRe: Can not compare a file and same file stored in mysql - sha256 Pin
Mycroft Holmes29-Apr-20 13:18
professionalMycroft Holmes29-Apr-20 13:18 
GeneralRe: Can not compare a file and same file stored in mysql - sha256 Pin
wilcodk30-Apr-20 2:28
Memberwilcodk30-Apr-20 2:28 
AnswerRe: Can not compare a file and same file stored in mysql - sha256 Pin
Eddy Vluggen30-Apr-20 7:34
professionalEddy Vluggen30-Apr-20 7:34 
QuestionCompare string time to timer time (noobie) Pin
Member 1481029228-Apr-20 6:36
MemberMember 1481029228-Apr-20 6:36 
AnswerRe: Compare string time to timer time (noobie) Pin
Gerry Schmitz28-Apr-20 7:48
mveGerry Schmitz28-Apr-20 7:48 
QuestionResize and move a drawn rectangle in win forms Pin
Member 1223285027-Apr-20 13:23
MemberMember 1223285027-Apr-20 13:23 
I read this source code then I built my form to draw a rectangle and make it able to resize/ move it, some how, the logic I follow is wrong, because the mouse when it moves up the small rectangles then the mouse cursor should change, it is some times change and others not, even in the console I can see the mouse cursor should apply. Also if I try to resize it then a new rectangle drawn. My form source code:

public partial class Form2 : Form
{
    private enum ResizableRect
    {
        RightUp,
        RightMiddle,
        RightBottom,

        LeftUp,
        LeftMiddle,
        LeftBottom,

        UpMiddle,
        BottomMiddle,
        None
    };

    private int m_resizableRectSize = 6;

    private ResizableRect m_resizableRectNodeSelected = ResizableRect.None;

    Rectangle rect;
    Point StartXY;
    Point EndXY;

    int x = 0;
    int y = 0;

    bool m_isMouseDown = false;
    bool m_movingRect = false;

    public Form2()
    {
        InitializeComponent();
        this.DoubleBuffered = true;
    }

    private void panel1_Paint(object sender, PaintEventArgs e)
    {
        //if(rect != null)
        {
            Graphics gObj = panel1.CreateGraphics();

            Pen rectPen = new Pen(Color.Red, 2);
            rectPen.DashStyle = DashStyle.Dash;

            x = Math.Min(StartXY.X, EndXY.X);
            y = Math.Min(StartXY.Y, EndXY.Y);

            int height = Math.Abs(StartXY.X - EndXY.X);
            int width = Math.Abs(StartXY.Y - EndXY.Y);

            rect = new Rectangle(x, y, height, width);
            gObj.DrawRectangle(rectPen, rect);
            foreach (ResizableRect pos in Enum.GetValues(typeof(ResizableRect)))
            {
                gObj.DrawRectangle(new Pen(Color.Red), GetResizableRectNode(pos));
            }
        }
    }

    private void panel1_MouseDown(object sender, MouseEventArgs e)
    {
        m_resizableRectNodeSelected = GetNodeSelectable(e.Location);
        StartXY = e.Location;
        m_isMouseDown = true;
    }

    private void panel1_MouseMove(object sender, MouseEventArgs e)
    {
        this.Cursor = GetResizableRectCursorType(GetNodeSelectable(e.Location));

        if (rect.Contains(new Point(e.X, e.Y)))
        {
            //mMove = true;
            this.Cursor = Cursors.SizeAll;
        }
        else
        {
            switch (m_resizableRectNodeSelected)
            {
                case ResizableRect.LeftUp:
                    rect.X += e.X - EndXY.X;
                    rect.Width -= e.X - EndXY.X;
                    rect.Y += e.Y - EndXY.Y;
                    rect.Height -= e.Y - EndXY.Y;
                    break;
                case ResizableRect.LeftMiddle:
                    rect.X += e.X - EndXY.X;
                    rect.Width -= e.X - EndXY.X;
                    break;
                case ResizableRect.LeftBottom:
                    rect.Width -= e.X - EndXY.X;
                    rect.X += e.X - EndXY.X;
                    rect.Height += e.Y - EndXY.Y;
                    break;
                case ResizableRect.BottomMiddle:
                    rect.Height += e.Y - EndXY.Y;
                    break;
                case ResizableRect.RightUp:
                    rect.Width += e.X - EndXY.X;
                    rect.Y += e.Y - EndXY.Y;
                    rect.Height -= e.Y - EndXY.Y;
                    break;
                case ResizableRect.RightBottom:
                    rect.Width += e.X - EndXY.X;
                    rect.Height += e.Y - EndXY.Y;
                    break;
                case ResizableRect.RightMiddle:
                    rect.Width += e.X - EndXY.X;
                    break;

                case ResizableRect.UpMiddle:
                    rect.Y += e.Y - EndXY.Y;
                    rect.Height -= e.Y - EndXY.Y;
                    break;

                default:
                    if (m_isMouseDown)
                    {
                        rect.X = rect.X + e.X - EndXY.X;
                        rect.Y = rect.Y + e.Y - EndXY.Y;
                    }
                    break;
            }
        }

        if (m_isMouseDown)
        {
            EndXY = e.Location;
            panel1.Invalidate();
        }
    }

    private void panel1_MouseUp(object sender, MouseEventArgs e)
    {
        EndXY = e.Location;
        m_isMouseDown = false;
        m_movingRect = false;
        Invalidate();
    }

    private Rectangle DrawResizableRectNode(int x, int y)
    {
        return new Rectangle(x - m_resizableRectSize / 2, y - m_resizableRectSize / 2, m_resizableRectSize, m_resizableRectSize);
    }

    private ResizableRect GetNodeSelectable(Point p)
    {
        foreach (ResizableRect r in Enum.GetValues(typeof(ResizableRect)))
        {
            if (GetResizableRectNode(r).Contains(p))
            {
                //MessageBox.Show(r.ToString());
                Console.WriteLine("GetNodeSelectable: " + r.ToString());
                return r;
            }
        }

        return ResizableRect.None;
    }

    private Rectangle GetResizableRectNode(ResizableRect p)
    {
        switch (p)
        {
            case ResizableRect.LeftUp:
                return DrawResizableRectNode(rect.X, rect.Y);

            case ResizableRect.LeftMiddle:
                return DrawResizableRectNode(rect.X, rect.Y + rect.Height / 2);

            case ResizableRect.LeftBottom:
                return DrawResizableRectNode(rect.X, rect.Y + rect.Height);

            case ResizableRect.BottomMiddle:
                return DrawResizableRectNode(rect.X + rect.Width / 2, rect.Y + rect.Height);

            case ResizableRect.RightUp:
                return DrawResizableRectNode(rect.X + rect.Width, rect.Y);

            case ResizableRect.RightBottom:
                return DrawResizableRectNode(rect.X + rect.Width, rect.Y + rect.Height);

            case ResizableRect.RightMiddle:
                return DrawResizableRectNode(rect.X + rect.Width, rect.Y + rect.Height / 2);

            case ResizableRect.UpMiddle:
                return DrawResizableRectNode(rect.X + rect.Width / 2, rect.Y);
            default:
                return new Rectangle();
        }
    }


    private Cursor GetResizableRectCursorType(ResizableRect resizableRectPoint)
    {
        Cursor rectPositionCursor;
        switch (resizableRectPoint)
        {
            case ResizableRect.LeftUp:
                rectPositionCursor = Cursors.SizeNWSE;
                break;

            case ResizableRect.LeftMiddle:
                rectPositionCursor = Cursors.SizeWE;
                break;

            case ResizableRect.LeftBottom:
                rectPositionCursor = Cursors.SizeNESW;
                break;

            case ResizableRect.BottomMiddle:
                rectPositionCursor = Cursors.SizeNS;
                break;

            case ResizableRect.RightUp:
                rectPositionCursor = Cursors.SizeNESW;
                break;

            case ResizableRect.RightBottom:
                rectPositionCursor = Cursors.SizeNWSE;
                break;

            case ResizableRect.RightMiddle:
                rectPositionCursor = Cursors.SizeWE;
                break;

            case ResizableRect.UpMiddle:
                rectPositionCursor = Cursors.SizeNS;
                break;

            default:
                rectPositionCursor = Cursors.Default;
                break;
        }

        Console.WriteLine("GetResizableRectCursorType: " + rectPositionCursor.ToString());
        return rectPositionCursor;
    }
}

AnswerRe: Resize and move a drawn rectangle in win forms Pin
Luc Pattyn27-Apr-20 14:17
sitebuilderLuc Pattyn27-Apr-20 14:17 
GeneralRe: Resize and move a drawn rectangle in win forms Pin
Member 1223285027-Apr-20 20:38
MemberMember 1223285027-Apr-20 20:38 
GeneralRe: Resize and move a drawn rectangle in win forms Pin
Luc Pattyn28-Apr-20 5:50
sitebuilderLuc Pattyn28-Apr-20 5:50 
GeneralRe: Resize and move a drawn rectangle in win forms Pin
Member 1223285028-Apr-20 18:56
MemberMember 1223285028-Apr-20 18:56 
GeneralRe: Resize and move a drawn rectangle in win forms Pin
Luc Pattyn29-Apr-20 3:30
sitebuilderLuc Pattyn29-Apr-20 3:30 
QuestionDate compare Pin
Carlos5827-Apr-20 11:42
MemberCarlos5827-Apr-20 11:42 
AnswerRe: Date compare Pin
Luc Pattyn27-Apr-20 12:00
sitebuilderLuc Pattyn27-Apr-20 12:00 
GeneralRe: Date compare Pin
Carlos5827-Apr-20 13:31
MemberCarlos5827-Apr-20 13:31 
GeneralRe: Date compare Pin
Luc Pattyn27-Apr-20 13:48
sitebuilderLuc Pattyn27-Apr-20 13:48 
GeneralRe: Date compare Pin
Carlos5828-Apr-20 3:19
MemberCarlos5828-Apr-20 3:19 
GeneralRe: Date compare Pin
Luc Pattyn28-Apr-20 3:24
sitebuilderLuc Pattyn28-Apr-20 3:24 
SuggestionRe: Date compare Pin
Richard Deeming28-Apr-20 1:40
mveRichard Deeming28-Apr-20 1:40 
AnswerRe: Date compare Pin
Carlos5828-Apr-20 3:23
MemberCarlos5828-Apr-20 3:23 
QuestionRename files in WinScp Directory using C# Pin
Sriram Valluri27-Apr-20 2:13
MemberSriram Valluri27-Apr-20 2:13 
AnswerRe: Rename files in WinScp Directory using C# Pin
ZurdoDev27-Apr-20 2:21
mveZurdoDev27-Apr-20 2:21 
GeneralRe: Rename files in WinScp Directory using C# Pin
Sriram Valluri27-Apr-20 3:15
MemberSriram Valluri27-Apr-20 3:15 
GeneralRe: Rename files in WinScp Directory using C# Pin
ZurdoDev27-Apr-20 3:27
mveZurdoDev27-Apr-20 3:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.