I am creating a plotting program and I was wondering how to move a chart's legend with the mouse? So you would click on the legend and then you could move it anywhere inside the chart area.
Using manual double-buffering of the chart, draw the legend at the current mouse position (perhaps + (15,15)) on the back-buffer just prior to drawing the back buffer to the screen. You can also set an Alpha to make the legend semi-transparent until the user drops it.
You can create a little form without borders to build your legend or use a ToolTip item. Then you could move with mouseMove event:
private void frmMain_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button = System.Windows.Forms.MouseButtons.Left)
ChangeLegendPosition(e.X, e.Y);
}
Where ChangeLegendPosition is your function that updates your form/tooltip position.
Related
In panel, when label text exceed horizontal and vertical it create auto scroll bar horizontal and vertically. both scroll are link to each other so, when i move mouse scroll (mouse wheel) both scrolled but my requirement is to scrolled horizontally. Is there any way to do that??
I tried this one but it doesn't work....
panel.MouseWheel += delegate (object sender, MouseEventArgs e)
{
((HandledMouseEventArgs)e).Handled = false;
};
So I want to increase the width of a picturebox from the left side of the picturebox and have been unable to find a way to do this...
imgBeam1.Left += xChange;
imgBeam1.Width -= xChange; //I want this to move the width from the left side.
My plan is to move the picturebox to the right, while extending the width to the left.
Can anyone help?
Maybe there is a more creative way of doing this?
EDIT:
This was for a DBZ beam race / beam struggle game I was working on in my spare time, and in the beam struggle part of the game, the character of the right side of the form has a much nicer way of displaying the beam as I can move the width of the picturebox to the right, while moving the picturebox left. While with the character on the left side of the form, I can only extend the width to the right which just shows sections of the image at a time.
Because of how images are loaded in to a picturebox (from left to right with the leftside showing first) I'm not sure if I could get the same effect. And I cannot find a way to extend the left side of the pictureboxes width anyways.
But thankyou for your replys. I made this account today, and didn't think this would be too hard to explain, but it was. Maybe next time I will show images instead, as it's much easier to explain that way. Thanks!
EDIT 2:
-visual explanation
From what I understand your post is not really about changing the outer size of the PictureBox but about moving the Image inside it.
But this is not possible. All you can do is choose between the two SizeModes:
Normal will put the image to the top left.
Center will, yes, center it in the control.
So to make it look like it is moving or placed differently, e.g. aligned to the right you can use this workaround:
Add the PictureBox to a Panel.
Make the Panel as small as you had your PictureBox to make it act as a 'viewport'.
Make the Image larger, maybe even full sized, i.e. SizeMode Autosize.
Remove the Border from the PictureBox and add it to the Panel instead.
Keep the PictureBox Backcolor Transparent.
Now you can move the PictureBox inside the Panel and it will look as if only the Image is moving under the viewport..:
Here is the code to move it left and back right with the mouse :
Point mDown = Point.Empty;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
mDown = e.Location;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button.HasFlag(MouseButtons.Left))
pictureBox1.Left += e.X - mDown.X;
}
Note that the large PictureBox is nested inside the small Panel, not the other way around!
Of course animations or other layout changes are also possible..
I have a problem with my code. I want to make a method to drag and drop an small image contained on a drawing panel, but this is only an image, is not contained in a pictureBox control.
private void panel2_Paint(object sender, PaintEventArgs e)
{
g.DrawPath(pluma, gP);
if(nuevobloque)
{
g.DrawImage(bloque, new Point(200, 200));
nuevobloque = false;
}
}
There I draw the image on the panel, but I don't know how I can drag and drop that image. Once again, is not contained on a pictureBox control.
Also, I want to know how can I keep the images in place even if I scroll over the panel (I don't want them to dissapear when I scroll the panel).
Thank you.
I'm working on an application where I have a grid of buttons (can be various number of them). Atm I'm using a 4x4 Grid to place them and stretch them to size. The issue is that these buttons can be dragged around, and they should be hovering over the rest of the buttons while they are dragged. They can be also clicked, in which case they slowly hover over to another point on the screen.
The problem arises from the fact that Grid doesn't handle zIndex, and putting a canvas under the Grid wouldn't help. I'm not sure if having a canvas with absolute coordinates would work on different sized screens, and the buttons are also supposed to hover over other elements outside the grid as well (and the grid is in a pivot - the button has to hover over whatever is outside the pivot as well).
The question is if there is any way other than a canvas with zIndex, and if not, how can I achieve a proper Grid-like layout with a canvas.
UPDATE:
I'm using the following code to move the button:
private TranslateTransform dragTranslation = new TranslateTransform();
private void Button_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
if (dragTranslation.X + dragTranslation.Y > 100)
{
//ClickLock to avoid the tap event from firing
clickLock = true;
}
draggedButton.RenderTransform = dragTranslation;
dragTranslation.X += e.DeltaManipulation.Translation.X;
dragTranslation.Y += e.DeltaManipulation.Translation.Y;
}
Note that I've skipped parts such as reassigning dragTranslation in the ManipulationStarted event.
The code can generate rectangles (Rectangle rectangle) at runtime. The position of rectangles may change according to users' choices.
I want to add code in the method where it creates rectangles to make the rectangles clickable. And after user clicking the rectangle, there will be a new window to show content just like text.
You can use Contains method of the Rectangle object.
private Rectangle _myRectangle;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (this._myRectangle.Contains(e.Location))
{
}
}
Create a label control with the border property and transaparent background(so that it will look as rectangle) and add click event handler for each label you add. It will be good if you create your own Rectangle control by deriving from Label class or you can create your own control(Many other solutions).
I would consider handling the click event on the window itself (or whatever your "background" control is), getting its coordinates, and comparing those to the known locations/sizes of your rectangles.