Figure 1,i have one or a few pictures,and some mp3 files. i want to develop a winform and load picture into winform,then, when mouse over certain areas of the picture,the area change,and play mp3 file when the mouse click.
question:How do I know the mouse over the designated area?and then change the color of the area? how to know which areas of mouse clicks? and play mp3 files
These areas may be round, oval, rectangular...
perhaps this is hotspot image question.
anyone help me? thanks!
Use OvalShape and the MouseHover event. Then simply call code to modify the opacity/color/whatever of the oval, and play an mp3 which is a separate problem.
One way to do that is to create a hidden bitmap of the same size with a white or black background, and shade each bubble with a different color.
Then you can just do something like this:
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
int foundColor = _Mask.GetPixel(e.X, e.Y).ToArgb();
if (foundColor == Color.Red.ToArgb())
// do something with this bubble
else if (foundColor == Color.Blue.ToArgb())
// do something with this bubble
else
// do nothing
}
Related
I am creating an app that will allow the user to click on images and then they will transform into something else, and the code to do that is below:
private void Image_Tapped(object sender, TappedRoutedEventArgs e)
{
BitmapImage bitmap = new BitmapImage(new Uri("ms-appx:///Assets/smallImage.png"));
imageHolder.Source = bitmap;
e.Handled = true;
}
Now the hard part is that I have to get these pre-transformed images to fly up onto the screen so the user can rush to click on them before they fall. I figured I would need to create storyboards and add those effects, if that is right word for it, but how exactly would I go about this in blend?
So to make fly out from another image in blend, I created individual storyboards for each image and recorded them flying around in whatever direction I wanted for as long as I needed. So for 3 seconds each and so on. Really easy once I got the hang of it, but hoping for new tutorials on blend for developers!
I'm making a C# inventory application. However, I want there to be a map where the user can click several areas and interact with the inventory on that certain area.
Currently I photoshopped the map and made it the background of the form. I'm planning on putting pictureboxes over the different areas and code manually the mouse over, click, and mouse down events to give the button appearance.
Anyway, my question is, is this a good idea? Should I just load the map into a picturebox, get rid of the buttonish visual effects and track the coordinates of the click?
While I don't think this is a bad idea, one alternative would be to use Rectangles and have an onclick function consisting of a series of Rectangle.Contains(Point) to find out if the point clicked by the mouse is contained in any of the clickable areas.
E.G.
Rectangle R1 = new Rectangle(/*Passed Variables*/);
Rectangle R2 = new Rectangle(/*Passed Variables*/);
//...
OnClick(object sender, MouseEventArgs e)
{
If (R1.Contains(e.Location))
{
//Stuff
}
else
{
If (R2.Contains(e.Location))
{
//Stuff
}
}
}
If you have a larger list of Rectangle objects, though, you could always use an array of Rectangles and a for loop for a more efficient way of checking if the clicked location is inside any Rectangle.
At CodeProject, someone has created an ImageMap Control for this very purpose. I imagine others are available.
I'm trying to animate an image in C#. Basically, I want to take an image and connect it to another function and based on a scale of 1 to 10, make the image move up or down. By default, the image will start out at 1. I have searched and I've found ways to make shapes move up and down on the screen, but not an actual image. The image is small, say 60x60 pixels. I feel like this should be simple, but I have yet to figure it out. I was thinking of just having an image placed on the Windows form and then basically have it move up or down the y-axis of the form, but I would like it to move smoothly.
Ok, I was able to hook a button up to a timer function and get the button to move smoothly up and down the screen. The button has to keep moving for the duration of the program running. However, I'm having a hard time writing a function that stops the timer and the image(button) from moving once the image reaches a certain location. Without that, the timer continues and the image(button) moves off the screen. I've tried messing with button.Location.Y functions, but I have yet to get it work right. Can anyone please advise? Thanks. Oh yea, once the image(button) reaches Y location of 192 or 447, it should stop moving.
An example of what I have:
private void timer2_Tick(object sender, EventArgs e)
{
button2.Top = button2.Top + 1;
if (button2.Location.Y == button2.Location.Y - 192)
{
timer2.Stop();
timer3.Stop();
}
//if (timer_limit < 100)
//{
// button2.Top = button2.Top + 1;
// timer_limit++;
//}
//else
//{
// timer2.Stop();
//}
}
Several ways to do this. You could just use a PictureBox and change its Location property. Or you could draw the image in the form's OnPaint() override and change the argument to e.Graphics.DrawImage(). You'll then have to call Invalidate() to force the OnPaint method to run. It is the cheapest way.
I think this would be simple question and should be asked in the pas few years but unable to google around and dont know if there is a specific keyword.
In c# WinForm I want to do drag and drop but I dont want the image of DragDropEffects Move, Copy or whatever. I want to display an image with half opaque. Just like Firefox when dragging an image, you would see the image folowing the mouse pointer like a ghost :)
I already Implement DoDragDrop, DragEnter and DragDrop events. I just want to customize the dragging effects with overlay image.
Might be 9 years too late to the party 😄
I always liked Drag&Drop interactions but found it complicated to use in WinForms. Especially if you want it to look professional with overlays.
I made my own library for WinForms the last time I needed Drag&Drop. You can find it here or on NuGet:
https://github.com/awaescher/FluentDragDrop
Here's everything you need to implement Drag&Drop like shown above:
private void picControlPreviewBehindCursor_MouseDown(object sender, MouseEventArgs e)
{
var pic = (PictureBox)sender;
pic.InitializeDragAndDrop()
.Copy()
.Immediately()
.WithData(pic.Image)
.WithPreview().BehindCursor()
.To(PreviewBoxes, (target, data) => target.Image = data);
// Copy(), Move() or Link() to define allowed effects
// Immediately() or OnMouseMove() for deferred start on mouse move
// WithData() to pass any object you like
// WithPreview() to define your preview and how it should behave
// BehindCursor() or RelativeToCursor() to define the preview placement
// To() to define target controls and how the dragged data should be used on drop
}
I am trying to make it so that the user can scroll a richtextbox by clicking the window the richtexbox is on and dragging the mouse. Unfortunately I haven't gotten very far:
private void Main_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
}
}
I've seen some suggestions on the web to track the last several x,y coordinates of the mouse and compare them to the x,y coordinates each time the mouse move event is triggered. Is there any less messy way to do this?
None that I know of. Unless you're using an API that handles it for you, you have to keep track of the information manually. And even if you did use an API just for mouse drags, it'd do the storing itself and likely just pass back the current X and Y, and the difference in X and Y, since the API wouldn't know what you want done with the information.
You'd be handling a little bit less information, but saving only about 5 lines or so of code to get the same result.