Posted: 16 Sep 2016 10:48 EDT Last activity: 13 Oct 2016 8:53 EDT
Moving a borderless form
I'm trying to program a way to move my borderless form by clicking and dragging the header labels. I'm working from within an Openspan project, not a C# project, so would anyone be able to help me do this?
I have the following script, which I was hoping to use in the Script component, but I get valiation errors:
private void lbxQualityTitle_MouseUp(object sender, MouseEventArgs e)
isMouseDown = false;
private void lbxQualityTitle_MouseMove(object sender, MouseEventArgs e)
int newY = this.Top + (e.Y - yLast);
int newX = this.Left + (e.X - xLast);
this.Location = new Point(newX, newY);
private void lbxQualityTitle_MouseDown(object sender, MouseEventArgs e)
isMouseDown = true;
xLast = e.X;
yLast = e.Y;
Are there certain references I need to use to get this code it to work? or is there a way I can get the desired affect using only toolbox components?
***Updated by moderator: Marissa to update categories***
Yes, you can do this without the script component. If you view the events and properties of a label control, you will see that there is a MouseDown, MouseUp, and MouseMove Event available. In the properties, there is also the Location variable for you to manipulate. After dragging the events over, you can click the 'expand' icon on the component to reveal the event properties.
On a side note, the script you have written will not validate because you are including multiple methods within a single method container. The script component automatically wraps your code in a method which creates an issue with your code due to nested methods.
Yes Mitchell, I tried using MouseDown, Up and Move before I asked the question here but I couldn't see where to go from there. I had the UI forms desktop location property ready to manipulate but I couldn't figure out where to get the location of the cursor from. I am still unable to find this, could you elaborate please? I've clicked Explore Component Properties, which is what I'm assuming you meant when you said click 'expand' icon? but the only location there is the location of the label for which I'm doing MouseDown.
Jeff, I have set this property as you said already, however the way I have designed my form means that only a few narrow slits of the standard form background (shown in grey below) are visible and so I was hoping to set the labels at the head as a clickable area to drag.
Thank you both for your responses. If you can provide any more help, I'd be very grateful.
To solve your issue you might provide a drag zone. Make the form a little larger to expose a section of the underlying form or create transparent sections where there is no text. For instance, make the background of your headers match the transparency color of the form. This will allow the user to click through the headers to the form. This can get a little tricky if you lots of layers but can be done.
The way my form is laid out at the moment, for each of the 4 sections, is with a large panel going from top to bottom, with 2 small panels in the middle and a label up top, with autosize turned off so that it can be stretched across the width of the large panel.
I could turn autosize on for the label, move the large panel down and set the form background to purple, like this:
However, as the labels are quite large, this would still not give me much area to click around them and drag the form background. To seperate the 4 sections, I would probably also look to add some slim grey panels in the middles, as per the original design, giving even less room to click and drag.
Is there no way to achieve this using the MouseDown methods? or with a C# script?