I'm learning C# and I'm trying to make a basic application with Visual Studio.
One of the things I want to achieve is to download several weather maps from the Internet and make a loop with them (show one after the other after sorting them chronologically) so that you can see how the weather changes over time.
Downloading the images was quite simple, but now I can't decide what's the best approach (or at the least the most common) to show them one after the other.
Should I have one single PictureBox and change it's image over time?
Should I have several PictureBoxes one on top of each other and make them appear and dissapear over time?
Any other approach you would recommend?
Also... when I tried changing the image with a loop to get the effect I'm looking for (sleeping the app after each change for a second), the app takes 10 seconds to start (the whole loop) and I can only see the last image in the PictureBox.
This obviously has to do with the app being busy and not refreshing the form.
After googling a bit I saw that I could add a BackgroundWorker... is that correct? Should I go down that path or am I missing something completely?
Would you be able to give me a few clues on how would you approach this application? I don't necessarily need to see the code.
As you can see I'm only beginning to code in Visual Studio and trying to learn by trial and error, so I'm just looking for a bit of guidance.
Thanks a lot for the help!
There is a nice Tutorial called A Simple Image Slide Show
This should solve your problem
Related
I've been trying to create a roll-playing game for a little over a year now, and I thought a good way to test it and flesh it out a bit would be to turn it into a Dungeons and Dragons variant. However, the inherent problem with using a DnD setup is that there's a lot to keep track of, to the point where it becomes impossible for a single person to do by themselves. As such, I thought of writing a C# program to help.
I ran into this problem when I tried using a series of PictureBox objects to represent the spaces on the map where characters can move. I wanted to use PictureBoxes because that would allow me to use images to represent terrain and characters occupying the given space. However, the map I am using is roughly 46 x 75 1-inch squares, totaling 3450 PictureBoxes. This, understandably, slows the application down so much that it actually freezes for minutes at a time while it redraws the map every so often.
I tried two solutions. First, I tried using a Panel object for its free scrolling capabilities in the hopes that the application wouldn't have to redraw the whole map, but rather only the subset of PictureBoxes visible at that time. This helped only a little, and not enough to make the application usable. Second, I looked online, including this forum, and found people having similar problems. However, the problems they were having were entirely unrelated to mine (aside from the whole slow redraw thing) and thus the solutions didn't really apply to me. I did see a few recurring lines that I tried:
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
I'm not really sure what they do, but they did help a bit. I am still seeing way too much lag, though.
I'm out of ideas at the moment. Is there a better control I could use or a different way of drawing? Thanks in advance for your help!
I would try to develop a solution that only renders the images that are visible on the screen at any given time. Images should only be rendered when you scroll them into focus.
This is a common technique since rendering UI is usually the slowest operation by far. I would bind a view model object to the visible objects, which means you only have to render a subset of the images instead of the entire screen.
Grids with endless scroll sometimes use this approach.
Is there a convenient way to rearrange how multiple displays are positioned via C#?
I'm working on a display wall and every time someone unplugs the displays from the computers that are driving them, I have to spend time in the Screen Resolution tool dragging them around. I can automate this process if I can find a way to change the display positions from code.
It looks like using the win32 API is the way to go.
ChangeDisplaySettingsEx with friends seems to be the way to go.
I'm wanting to create an animation in C# such as what you would see in a slot machine where the pictures spin round. I know I could manually move the location of a PictureBox or something like that but that seems like not a good idea to me.
How would you guys do it? It doesn't actually matter whether its in standard forms or WPF or anything else similar. Possibly using XNA?
I suggest you use WPF.
With Expression Blend you can easily do the animation you need.
I think I've already seen a slot machine WPF sample somewhere on the web.
I'll search for it and post it if I find it again
Edit
Nope it was a silverlight application, but code is almost the same. Here is the link:
http://www.dolittle.com/Silverlight/SlotMachine/SlotMachine.html
Anyway, if you find that approach to difficult I suggest you read a bit about simple WPF programatically driven animations. They're very easy to do, and with a few lines of code you can accomplish your needs.
Best regards
I'm working on a solution for my new project (in C#). I'm trying to make a dynamic image/animation combiner (maybe later even work with video's, but that's not required atm).
So basically my program is reading a xml file with all kinds of instructions the user needs to do. In the xml file it is possible that for 1 instruction multiple pictures are needed. So when there are 2 or 3 pictures (the maximum amount of pictures is 4) they need to be combined to 1 picture so I can show that on the image object on the main form. Also it is important that the pictures keep there proportions so the image doesn't look deformed.
I found a solution with GDI+ but it isn't that good as I wanted it and runs pretty slow on a bit older computers. Also combining animations with normal images is a real pain and goes very slow!
Is there a faster/easier way to do this? Maybe WPF is a solution but I got no experience with this.
Thnx for any help in advance!
This questsion is open now for mor then a year but I found the solution some time ago so I will post it here in case it is usefull for somebody else.
The best way to do this was creating to set up a grid dynamic. And then fill up each element of the grid with the needed media (Video, Image, animated gif's and even Viewport3D from another xaml file). Creating a grid in code is really easy so it should be a good solution for everybody who wants to do this in WPF.
I can place a couple of buttons in Silverlight, but I'm not that experienced with the Silverlight tools and capabilities.
What do you think I should use to create something like this?
The control would have to pull and ID from the database and according to that place an image asociated with the record.
I need it to be animated with some crispy movement.
How can I achieve this?
It's all possible, but you need to break the task down into smaller steps.
Once you've done that you should find that you can solve some of these with your current knowledge, others will resolve themselves with a little more research, but there will be some you need to ask questions about here.
I'd suggest you start that break down and try to solve the little problems. Then if you get stuck come back and ask more specific questions.
Well, with Silverlight and c# you can make the animations needed and such, and you can set a Silverlight Image control with a data bound source, so it loads the images dynamically, but Silverlight can't talk with databases directly, you'll need to use a webservice to interact between Silverlight and the database. Don't know how much you know but to not leave anything out, with Expression Blend you can make the graphical part of you're app fast and easy, and with Visual Studio you'll add the code-behind and functionality.
In this link you can find a example of how to make an image slide show with Silverlight, it may not be exactly what you're looking for, but it should give you a heads start.