Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Window resizing

Window resizing

Scheduled Pinned Locked Moved C#
help
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    XeoN Kc
    wrote on last edited by
    #1

    Hi there. I'm created a borderless window, on which I put 8 panels containing my custom window border. I want the window to be resized when the user clicks+ drags from the right border. I created 3 event handlers for the right border panel...mousedown, mouseUp and mouseMove. On mouseDown, a flag is set and I get the location of the click. On MouseUp I unset the flag. On mouse move I do the following: //check if flag is set if (this.resizeRDown) { //calculate the difference int Xdiff; Xdiff = e.X - this.ResizeRXY.X; this.Width = this.Width + Xdiff; } But the resizing is acting very weird...making the window a single pixel wide. Can anyone give me a hint on this(or an article for that matter) that can help out. Thanks ------------------------------------------------------------------------------ Programming......THE DEVINE GIFT! :cool:

    L R 2 Replies Last reply
    0
    • X XeoN Kc

      Hi there. I'm created a borderless window, on which I put 8 panels containing my custom window border. I want the window to be resized when the user clicks+ drags from the right border. I created 3 event handlers for the right border panel...mousedown, mouseUp and mouseMove. On mouseDown, a flag is set and I get the location of the click. On MouseUp I unset the flag. On mouse move I do the following: //check if flag is set if (this.resizeRDown) { //calculate the difference int Xdiff; Xdiff = e.X - this.ResizeRXY.X; this.Width = this.Width + Xdiff; } But the resizing is acting very weird...making the window a single pixel wide. Can anyone give me a hint on this(or an article for that matter) that can help out. Thanks ------------------------------------------------------------------------------ Programming......THE DEVINE GIFT! :cool:

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      What does the debugger say when you examine e.X and ResizeRXY.X? What values do they have at runtime? Maybe you just calulate them wrong.

      X 1 Reply Last reply
      0
      • L Lost User

        What does the debugger say when you examine e.X and ResizeRXY.X? What values do they have at runtime? Maybe you just calulate them wrong.

        X Offline
        X Offline
        XeoN Kc
        wrote on last edited by
        #3

        Well, that's what I actually prompted me to write here. I discovered that hovering was affecting this so I handled mousehover, so that it would unset the flag. It improved, but still acting kind of funny. Well...for XDiff..the value is small. What I want to know is whether e.X, e.Y (mouse location) is the coordinate with respect to the top,left (first location of window) or with respect to :cool:0,0 of screen? -------------------------------------------------- Programming...the golden price!:cool:

        L 1 Reply Last reply
        0
        • X XeoN Kc

          Well, that's what I actually prompted me to write here. I discovered that hovering was affecting this so I handled mousehover, so that it would unset the flag. It improved, but still acting kind of funny. Well...for XDiff..the value is small. What I want to know is whether e.X, e.Y (mouse location) is the coordinate with respect to the top,left (first location of window) or with respect to :cool:0,0 of screen? -------------------------------------------------- Programming...the golden price!:cool:

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Depends on what e is. If it's a point from Cursor.Position, then MSDN says: A Point that represents the cursor's position in screen coordinates. But you can use the PointToClient method to convert them into client coordinates. regards

          1 Reply Last reply
          0
          • X XeoN Kc

            Hi there. I'm created a borderless window, on which I put 8 panels containing my custom window border. I want the window to be resized when the user clicks+ drags from the right border. I created 3 event handlers for the right border panel...mousedown, mouseUp and mouseMove. On mouseDown, a flag is set and I get the location of the click. On MouseUp I unset the flag. On mouse move I do the following: //check if flag is set if (this.resizeRDown) { //calculate the difference int Xdiff; Xdiff = e.X - this.ResizeRXY.X; this.Width = this.Width + Xdiff; } But the resizing is acting very weird...making the window a single pixel wide. Can anyone give me a hint on this(or an article for that matter) that can help out. Thanks ------------------------------------------------------------------------------ Programming......THE DEVINE GIFT! :cool:

            R Offline
            R Offline
            Robert Rohde
            wrote on last edited by
            #5

            Hi, the code seems good at first glance but some parts are missing to clear this out. I assume you are setting ResizeRXY not correctly. Be beware of the affect that the X and Y coordinate of the MouseEventArgs are relative to the control which generated the event in relation to its parent (to the whole screen when working with a Form). I quickly put together the following (where panel1 is a Panel docked to the right of a Form - but it shouldn't matter what kind of control it is):

            private Point _resizePoint;

            private void panel1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
            {
            _resizePoint = new Point(e.X, e.Y);
            }

            private void panel1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
            {
            _resizePoint = Point.Empty;
            }

            private void panel1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
            {
            if (_resizePoint != Point.Empty)
            {
            this.Width += (e.X - _resizePoint.X);
            }
            }

            X 1 Reply Last reply
            0
            • R Robert Rohde

              Hi, the code seems good at first glance but some parts are missing to clear this out. I assume you are setting ResizeRXY not correctly. Be beware of the affect that the X and Y coordinate of the MouseEventArgs are relative to the control which generated the event in relation to its parent (to the whole screen when working with a Form). I quickly put together the following (where panel1 is a Panel docked to the right of a Form - but it shouldn't matter what kind of control it is):

              private Point _resizePoint;

              private void panel1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
              {
              _resizePoint = new Point(e.X, e.Y);
              }

              private void panel1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
              {
              _resizePoint = Point.Empty;
              }

              private void panel1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
              {
              if (_resizePoint != Point.Empty)
              {
              this.Width += (e.X - _resizePoint.X);
              }
              }

              X Offline
              X Offline
              XeoN Kc
              wrote on last edited by
              #6

              Hi, Thanks. Helped a lot. -------------------------------------------- Programming is a devine gift

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups