I am developing an application in C# .NET using WPF. I want the users to be able to draw shapes on a draw area. The shapes are zigzag lines and polygons. The end points of line segments should be small squares as shown in the image below. In some cases, I need arrows in the middle of line segments as shown in the image below.
I have partially implemented the drawing by adding lines to a canvas and resizing the lines on mouse events. However, I have not been able to implement creation of small squares on the end points of line segments and arrows.
Is there any package or tool that provides the functionality of drawing such shapes?
Thank you for any help which you can provide.
A common way to approach this is to use Adorners. Basically, there is a virtual layer rendered for adorners. You can use these to drag / resize (among other things) visual elements on the screen with a little bit of glue code.
Here is a page from Microsoft on the subject:
http://msdn.microsoft.com/en-us/library/ms743737.aspx?ppud=4
Related
I'm using the WPF InkCanvas for a drawing application. The canvas is over a image. I can scribble over the image OK but I need it to have a glow effect - i.e. the actual lines drawn must have this effect. Is there a way to do this in XAML or in the C# code?
You want to use a ShaderEffect and attach it to the UIElement.Effect of the InkCanvas. This MSDN article contains a sample that shows how to write ShaderEffects.
Try starting with the excellent set of ShaderEffects implemented in the Windows Presentation Foundation Pixel Shader Effects Library.
We are developing an application that must be used by people that may have some visual problem involving the use of kinect to move the cursor, so we need to make it bigger than usual. However, this application does not interfaces directly with kinect, so we can't use its APIs.
We are programming in C# (.NET 4.5) using WPF. The problem is that the default cursor size cannot be bigger than 32x32 pixel or 64x64 pixel in high res devices.
We first tried to make the actual mouse cursor invisible and then use a Graphics object, taken using Graphics.FromHwnd(applicationWindowHandler). It succeeds to draw the image but it leaves the trail of the past cursor positions.
Is there a way to do using the regular windows mouse cursor, or at least a way to remove the trail (like an "invalidate" method that force the current window to refresh)?
We already tried these solutions but with no luck:
www.hsys.com/CustomCursorArticlePart1.htm
www.hsys.com/CustomCursorArticlePart2.htm
csharparticles.blogspot.it/2005/03/custom-drawing-cursors.html
Couldn't you just use a Canvas control that covers the entire window, set the cursor to none and then put an Image control with a suitably large cursor image in the Canvas, with its Left and Top properties bound to the cursor's X and Y coordinates relative to the Canvas??
How to make a movable control in c#?
Two circles with a line joining b/w them.
if we move one circle in any direction the other circle remains fixed but the line changes its position according to the first circle.
i want the idea .....pls help me if u have?
You are not telling us if this is a Winform application, WPF or Silverlight.
To me it sounds like WPF could be the right technology for this.
You could use the shape objects to draw circles and lines.
Link to MSDN documentation
I want to do basic WPF graphics, i.e. rectangles, lines, circles and text.
When should I use Drawing and when should I use a DrawingVisual?
I have some code that uses Drawing and I render those to a DrawingImage and display that in an image control. Is this the right way? I could not see how to add text to a drawing. I had trouble positioning it too. Should I be rendering to a Canvas?
I have some code that uses DrawingVisual and writes to a DrawingContext. That is like WinForms. Is this the recommended way?
Do you have any high level advice on which APIs to use for basic graphics and labels? Will they options work on Silver Light and Desktop?
You mention in your comment that you're actually implementing scatter plots or similar graphs. Typically in WPF this is created by templating the existing controls, like a listview. It sounds counterintuitive, but this is far easier and more powerful than drawing your own.
This article by Charles Petzhold shows a scatter plot implemented in this way and goes into great detail about how to make it performant to 10,000+ data points.
You'll most likely want to just render to a Canvas. If you add "shapes" to a canvas, WPF will handle all of the drawing for you.
For details, see Shapes and Basic Drawing in WPF.
I am using NPlot charting library to draw several plots illustrating signal fluctuations. The plots are inserted one beneath the other in a flowlayoutpanel1.
The x axis is the time. The y is the value of the signal.
I've added a trackbar at the bottom, along the x axis. When the user moves the trackbar, the value of each signal is displayed somewhere (in relation to the trackbar's position).
All of this is already functional.
I've been asked to add some visual way to illustrate the precise time where the trackbar is. They want some sort of vertical line that would move with the trackbar, over all the Nplots. However they are open to alternatives.
I have tried drawing the line but it's difficult to draw in relation to the trackbar's position. Also it ends up being drawn BEHIND the Nplots.
I've also tried drawing a static grid on the flowpanel but the Nplots are not transparent, and my boss doesn't like each plot having a individual grid for aesthetic purposes.
At this point i'm open to any "out-of-the-box" suggestions, or corrections on my implementation. I'm self taught in C# so i haven't done anything like this before.
Please help!
EDIT: I have gotten something slightly better by using a label with a border, stretching it to be tall and having width of 1. This creates a Line that goes over all other control. Now my biggest challenge is calculating the position of the trackbar pointer to make the line match it...
After a lot of fiddling, i found that the only way to have a line drawn over all other controls was NOT to use the Graphics drawline, as the controls placed on top were not transparent and i could not access their graphics component (was a imported control not a .NET class).
I ended up going with the EDIT solution, took a label with a border and put the width to 1, creating a simple line instead of a box.
The position formula took a lot of fine tuning, the way to go was to calculate (estimate) the width between two trackbar ticks an add a tiny offset for the control itself. Using the traback's pointer Value property, i could calculate the position of the label/line so that it would follow the trackbar pointer. There is a minuscule offset sometimes formed but not well seen to the naked eye.