C# Rich GUI Application - c#

I want to create an app to declare microprocessor's pin as input/output with mouse clicks. I created a mockup - http://i.stack.imgur.com/GOHQ5.png. I think it would be best to declare each pin as an separate class so I can change its state easily, but I dont know how to achieve that along with graphical representation of it. Each square should be clickable and changin its color. Then foreach loop to iterate throu them and get state information of each.Should I go with WPF or Silverlight or just simple click events? What is the best approach to implement that in .NET?

If you want a website, do Silverlight. Otherwise do WPF because it will be easier.
I'd just do an image for the center piece, unless it's going to change size, in which case you could just draw it out of lines and an ellipse. Use a Canvas in your main window, not a grid. Make a Pin class that handles the state/color/positioning information. You can draw the square with a Rectangle.
Don't worry about MVVM, that's going to be more trouble than it's worth for your case.

Silverlight or WPF doesn't make much of a difference in this case. Deployment of the application (web or not) might help you chose.
Implement the state machine/processor as a class (ViewModel) and implement the UI as a View. That will help to keep the code clean. Look up MVVM Model-View-ViewModel.

You could do this in WPF, Silverlight or Winforms.
From a graphical perspective, it might be easier to reproduce your mockup in WPF or Silverlight. Choosing between WPF and Silverlight really comes down to how you want to deploy the app (eg for SL you need a web server).
Make your choice, start writing code and then come back here with specific issues as you encounter them.
Good Luck.

Related

Editable midi editor in UWP

I'm looking to make a midi editor for UWP (in c#). I've got many plans but I'm lost on exactly how to display it. What is a good UI control to start with for displaying my notes (sort of like Garage Band). I'm making my own UserControl but I don't know if I should go fancy with grids, or use a canvas in front of some form for displaying it.
Using grid might be simpler at first, but if you want to make complex custom UI it's better to write it from scratch.
For this I recommend Win2d which makes it very easy to draw custom interface in your app.

How to create a drawing in a window in WPF

I've decided to learn a bit of WPF and I've created an application with the Mahapps Metro library and it interacts with a SQLite database (Unrelated but a bit of background).
I'd like to draw an object, let's say a triangle, in a new window.
I've seen this - Click - but the drawing of the shape needs to be visible to the user. So the user will see the line being drawn from point A to B to C to A. The image will "reload" after a few seconds i.e. Clearing the window/canvas and redrawing the triangle.
Are they any libraries out there that might make this easier or does WPF have something else I can use to achieve this?
Also, the redrawing of the triangle will be in a separate thread running a loop. Something tells me this isn't going to be very efficient. Is there a better way initiate a "redraw"?
My "answer" are some helpful searches and a few results that might help you get to the next step of deciding on a design that works for you.
Yes, WPF does have facilities to help you achieve some animation in drawing lines.
I searched for "wpf animate line drawing" and some interesting links for your research are:
How do you animate a line on a canvas in C#?
generating animated line
Drawing line "slowly" programmatically with wpf
Hopefully this gets you going in a good direction. Best of luck with your project.

Rotate Windows form upside down

I have a C# application that has an existing WinForm that I now need to display upside down.
The application will be displayed on a touchscreen Windows 7 device. If two people are using the device, one person is viewing it right-side-up while another user will be simultaneously viewing it upside-down. I will need to have one control displayed right-side-up while another control is displayed upside-down, each duplicate forms. Both need to be functional. It is not necessary for the title bar and Windows close, maximize, and minimize to be rotated.
Is there a way to easily rotate this Form and all of its contents without having to rewrite it from scratch?
Unfortunately, rotating controls is not directly possible in WinForms.
At least, not if you want them to retain their functionality. It would be relatively simple to draw the control into a bitmap, rotate the bitmap, and then draw that back to the desired location on the form. But you would obviously lose the ability to interact with the controls. They would just be static representatives of their original selves.
But making functional upside-down controls just isn't going to happen. I mean, you could try to write a bunch of custom drawing code for owner-drawn controls, but you'll still run into a bunch of bugs, corner cases, and compatibility problems. The Win32 controls that WinForms is based on just don't support this. No big surprise, really, considering they were invented some 20–25 years before anyone thought of computer screens that you could carry around in your pocket and rotate in any direction. There is a good reason that UI technologies like WPF came out around the time that touch screens and tablets did.
There are some possibilities that can be explored when it comes to flipping the entire screen, but that's not going to help when you want different controls going different directions. (And I guess it betrays my vantage point as a desktop app guy when I say this, but that just sounds like an incredibly confusing UI.)
If you absolutely have to have this, someone else is going to have to give you another route to hack it, perhaps along the lines of Dhawalk's comment: hosting the WinForms control inside of a WPF app that does provide built-in support for rotated controls. I don't know enough about this to make any concrete suggestions down that path. From a few minutes of searching, it appears that WindowsFormsHost does not actually support rotation transforms, so this may be a non-starter anyway.

Language and Approach to a Drag-and-Drop Drawing Area for a new CAD GUI?

I'm trying to make a new CAD program from scratch. The GUI is mostly easy to make in C#; it's just dragging-and-dropping things like command buttons and writing their associated code.
However I want the user of my CAD to be able to drag-and-drop icons from a toolbar onto a drawing pane. I also want them to be able to resize those icons, draw connections between them, etc. And I don't know how to do this part.
After doing a good bit of research, I'm still lost on what approach I should take for it. It's basically a 2D flowsheet, so do I need hardware acceleration? Do I make C# bitmaps and just print those after modifications on mouse events? Etc.
What should I study to learn how to do this?
Thank you!
You probably need to work with WPF. You might find these articles useful
A Beginners Guide to
WPF
A Guided Tour of WPF
Drag and Drop
Drag and Drop in WPF
WPF Drag and Drop Smorgasbord
Drag And Drop in WPF Explained (an end-to-end explanation)
WPF Diagram Designer
These were the ones that help me while I was going to do something similar. Hope they will be useful to you.

What is the equivalent to Java's canvas object in C#?

I'm working on creating a basic application that will let a user draw (using a series of points) and I plan to do something with these points.
If this were Java, I think I would probably use a canvas object and some Java2D calls to draw what I want.
All the tutorials I've read on C#/Drawing involve writing your own paint method and adding it to the paint event for the form. However, I'm interested in having some traditional Form controls as well and I don't want to be drawing over them. So, is there a "Canvas" object where I can constrain what I'm drawing on?
Also, is WinForms a poor choice given this use case? Would WPF have more features that would help enable me to do what I want? Or Silverlight?
A Bitmap will work fine, display it with the PictureBox.Image property. Use Graphics.FromImage() to get the Graphics object you'll need to draw on the bitmap. Use PictureBox.Invalidate() to let the PB know that it needs to update the image on the screen.
Well, there is a control called 'canvas' in WPF which may suite you. If you are using Windows Forms, i think the best choice will be to draw on a panel control. Windows forms are in no way a poor choice. Indeed, when using them you can even develop a cross-platform applications. However, WPF is more 'rich' in some way. I think that if you are not aiming at any other platforms, and you don't have to stick with .NET 2.0 WPF is a preferred choice (especially, if you are going to use some graphics in your application, because WPF uses hardware acceleration).

Categories

Resources