Window resizing
-
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: -
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: -
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.
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:
-
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:
-
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: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);
}
} -
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);
}
}