Render Tube and resize, dynamically add text - c#

What I am looking to do in my Windows Forms application (or even WPF). Is to dynamically render an image of a tube, or cylinder (with a 3d look or having some sort of depth for a better visual experience), setting the length and hieght and so on, (also need rulers and such to zoom in and out). But then allow the user to enter some text, which will then be placed on that tube or cylinder, for display purposes, able to scale the text size, to create a visual representation of what it would look like IRL.
Any ideas on where I can start, or some examples I can build off of? This vector type display is new to me, so any help would be appreciated.

This article looked interesting. I would imagine you could tweak it to do what you were after.
http://kindohm.com/technical/WPF3DTutorial.htm
Also I googled "WPF 3D drawing".
If you have the choice WPF is better suited for graphics than WinForms out of the box. Though a good programmer can make WinForms do similar.

Related

Resizable views UWP

How do I make it so that a desktop UWP app will resize based on resolution? Mainly I need it to work between a surface pro and a Surface Studio. I've researched around google and I haven't seen anything that goes into detail. I know of things like RelativePanel and VisualStateManagers, but I have not clue how to use them. Any guidance would be much appreciated.
Use Grids to Place your elements. Specify the row height and column width as fractions (0.2*,0.2*,0.6*) so that it adds upto 1 (not necessarily, but for convenience). Then your UI will scale automatically based on resolution. You don't even have to use relative layouts. Just place them within these Grids. If you want complex actions, go with VisualStateManagers.
After doing more searching I came across this. I think I understand it now.
https://channel9.msdn.com/Series/Windows-10-development-for-absolute-beginners/UWP-037-Utilizing-the-VisualStateManager-to-Create-Adaptive-Triggers

How to change the color of an Image

I am a decent winforms programmer and I have done a little programming in XNA, I am trying to learn WPF.
I have a bunch of greyscale images that I want to add color to dynamically. to do this in XNA is easy simply indicate the color you want to use in the SpriteBatch.Draw method
SpriteBatch.Draw(Image,0,0,Color.blue)
Or something like that. That would draw my greyscale image with a blue hue to it. The purpose of this is to change the look of an Item, without having to draw them all manually.
I can't seem to find a good option in WPF
Ok, well I hope your are a decent ... programmer. This kind of image processing in WPF is not for the feint hearted. You certainly can't do it with the same ease that you displayed in your question example. Your best bet is to use someone else's code to do it for you. Please see the following articles for further help:
Image Processing Lab in C#
Image Processing is Done using WPF
If you're really hardcore, you can even plug High Level Shading Language (HLSL) pixel shader files into WPF to create all sorts of crazy visual effects. See Chapter 13 of the wonderful WPF Control
Development UNLEASHED book online for a great introduction to this subject.

Create an Object Editor in C# for WinForms

I need to find, or create an editor that will handle text and images as objects. For instance I have a 3 line string of text, to be able to move it around and position it within a canvas, also the ability to add an image, and possibly resize it within that canvas. and take the result, and save it, whether I get the the offsets and positions manually, of each of the objects (preferable) , or get the entire canvas as an image, to be able to save and print.
Rulers would be great... Im not trying to re-create Photoshop, but the idea is similar.
I will be doing this in a C# WinForms application, it does seem however that a WPF solution might be better suited, and I think I can have a WPF control within winforms...
Any direction or advice would be greatly appreciated.
Forget winforms. It doesn't support anything. Your best bet is to do it in WPF and if you need, you can integrate it into an existing winforms application via the ElementHost.
Please see my similar answers/samples about this:
https://stackoverflow.com/a/15580293/643085
https://stackoverflow.com/a/15469477/643085
https://stackoverflow.com/a/15821573/643085
Also, see this example with support for zoom, panning and resizing functionality:
https://stackoverflow.com/a/16947081/643085
They're all MVVM based and have some interesting features.
You can easily customize these samples and add ANY type of elements:
images,
geometries,
usable interactive UI elements with functionality (TextBoxes, ComboBoxes, whatever),
text,
videos,
FlowDocuments,
or whatever that's visible on screen)
by adding additional data items and their corresponding DataTemplates.

How to let controls maintain position after Window size changes

I am creating a Windows Store app, using XAML and C#.
If for example I run my application on the Windows Simulator (tablet), the layout is perfect. When I run my application on my local machine, the layout does not at all look like what it looks on the simulator.
How do I design my application to fit both perfectly?
Should I have multiple designs, and with start up check screen resolution and choose the layout best suited for that resolution?
Basically, how do I make sure my app will always look its best, no matter on what screen size it my run out there in the real world?
I am currently making use of a Grid for the layout of the controls, 3 columns, and 3 rows, with the Width and Height set to "*". I understand that with larger screen sizes, the column width and row heights will increase, and the opposite for smaller screen sizes.
I am basically just looking for good design practices, as to always try best and avoid massive layout changes.
I attended a Microsoft seminar lastly for 2 days. I asked if ViewBox exist for Windows Store Apps. They said "I don't think so" :)
But it exist :D
I'm sure it will be easy with a ViewBox http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.controls.viewbox
Put your design in a view box. That's all. We use it for silverlight.

Is it practical to port code from Flash to C#?

My goal is to gain a better understanding of the characteristics of C#, and become more comfortable creating simple apps. I am fairly competent with Flash (Actionscript 3), and found an old Tic-Tac-Toe game I'd written. I started wondering about porting this code into a C# application. Not knowing much about C#, I'm wondering how difficult the migration would be.
On the one hand, the underlying game logic is syntactically similar, and therefore would be easy to port.
However, as far as the graphics are concerned, I don't even know where to begin. So far, I've only exposed myself to Windows Forms and Console apps in C#.
I'm wondering if these Flash concepts have similar analogs in C#, or if the procedures and syntax are radically different:
Placing graphic elements on a stage
Rendering lines from start/end coordinates
Event listeners on movie clips
Swapping the image inside a graphic element (or, in my Flash version, nextFrame() in a movie clip)
You may want to try developping your little game using Silverlight. Silverlight applications, coded using C# and Xaml, are pretty similar in form with flash applications, and you should find everything you need without trouble.
So I suggest you download the Silverlight SDK (free) and give it a try.
Firstly, Flash is to WPF (close enough) as ActionScript is to C#.
The WPF/Silverlight model is much more similar to Flex that it is to Flash. Everything is added to the UI tree as a object, even lines.
Likewise, adding event handlers to controls (like a button click) can be done in the "code behind" (the code that lives with the view), but the recommendation is to use the MVVM pattern. If you are new to the concepts of separation of concerns and unit testing, feel free to start with the simpler "code behind" method.
While WPF and Silverlight are very similar, I'd recommend starting with Silverlight as the SDK and available samples are richer. You can easily move onto WPF later on (though porting an application from Silverlight to WPF is not automatic).
Swapping images, as you mentioned, would be done via "Visual States" in Silverlight (or possibly changing the image reference, which is more "hacky").
Have a look at the following links to get started:
Learn # Silverlight.net
Silverlight on MSDN
Shapes and Drawing (Silverlight)
If you're looking specifically to do games and the like, you may wish to look into the free XNA framework. However, there will be differences as Flash gives you far more ability to "set up" things beforehand and modify them.
Placing graphic elements on a stage
If you go the XNA route, you will be drawing sprites using the spritebatch, you tell them where and how to draw and that's where they will go
Rendering lines from start/end coordinates
In windows forms you can do this via a simple System.Drawing call, however if you wish to do this in XNA, you will either have to make a 1 pixel square and stretch/rotate it to what you want, or use 3d primitives (Though this will limit you to a 1 pixel line)
Event listeners on movie clips
Look into delegates, but there isn't really an equivalent for movie clips to my knowledge
Swapping the image inside a graphic element (or, in my Flash version, nextFrame() in a movie clip)
This is fairly simple, depending on what you mean. If you want to, say, animate a sprite. You can do this by moving the source rectangle or changing the texture of the spritesheet. If you mean the screen as a whole, this is mostly handled for you provided you use the spritebatch. In windows forms you'll have to do more of it yourself, but the base concepts are the same.
Overall it's not that bad, but if that doesn't sound appealing check out Silverlight. It's basically C# styled flash so you may find the transition easier.
Good luck and hope this helps.

Categories