How do I draw a caret on an image? - c#

In my application the user can write from keyboard on an image. Is it possible to display the caret on the image (as in TextBox for example)?

You've got 3 separate issues:
1) Drawing Text at arbitrary locations.
See MSDN DrawString Method
2) Merging two separate images (the original and the text) into one.
As far as I know the image host controls, that you're likely using to show the image, provide a bitmap object property, so you need to be able to save that bitmap object to a file once you've done the DrawString.
3) Draw the caret symbol at arbitrary locations
You can do this with basic drawing commands to create your own caret, that's using Graphics with Pens and Paths.
Then the issue is to make it flash (which means drawing what's underneath your caret again, then your caret etc)
I think there's options on the Pen object that might achieve this for you.
I would tackle each in turn then put them together.

If you are referring to the Caret (the blinking indicator which shows the position when inputting text), you probably have to use P/Invoke. You should start here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ff468799(v=vs.85).aspx

Related

C# Removing a certain line in Graphics/Drawing

Is it possible to remove some lines in my graphic panel without erasing the rest?
PanelGraphics.Clear(Color.Black); erases all the graphics but I only want to remove one line, or a certain color.
Is this possible?
Is it possible to remove some lines in my graphic panel without erasing the rest?
Not really. The Graphics does not tell you anything about the actual context, it can be the screen, a printer, a bitmap, a metafile, the surface of a control or something similar. If you draw a Panel or a control you must always re-draw the whole content once it is invalidated. Otherwise, you will get a messy result. Just try to move your window partly out of the screen, the custom-drawn content will be "erased" unless you redraw it.
However, if you have a concrete image, such as a Bitmap, you can replace its colors; however, you must know the exact PixelFormat of the image. See my answer here if you are interested: https://stackoverflow.com/a/33562891/5114784

How do I select a Rectangle that's already been drawn?

I've been learning how to draw lines in winforms apps, and I'd like to be able to select something (rectangle, for example) that has already been drawn by left clicking it, and then be able to move it around to another location by dragging it with the mouse.
How can this be done? I don't see any methods for this so I think I will need to figure out if there is anything where I left-click on the form, and if there is, then somehow figure out the dimensions of it and redraw it appropriately. Is this correct? And how would I know where the reactangle starts, where it ends, how heigh it is, what color(s) it has, and what if it's overlapping another line, rectangle or another shape?
I've not been able to find much on the System.Drawing namespace for things like this, and what I have found so far is just basic "How to draw lines" type stuff.
Your drawing is a bitmap, not a vectorial image. Basically, it's just lots of pixels. Once your rectangle is drawn, it's just some pixels, but the rectangle itself (with coordinates and size) doesn't exist anymore.
What you can do is saving data for every shape (in a List for example). Then, when you click on your image to select something, you test every object in your list in reverse order until the mouse coordinates are within your shape. Then, if, for example, you want to delete the shape, you remove the shape from your list, then you clear your image and redraw every shape in your list.

Custom mouse cursor size in WPF

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 can I draw on two side by side inkcanvases

I have two inkCanvas elements in WPF displayed side by side. I want to be able to draw lines seamlessly from one inkCanvas to the next. Right now the stroke gets clipped at the boundary and you have to release the mouse and press it again on the next canvas to continue the line.
I also read that inkCanvas wasn't really the way to go for drawing. It was more for simple things like signatures. What are you supposed to use instead?
First try with one inkcancas:
add tiles by replacing the current inkcanvas with a bigger one and copying the strokes
it might work
if it doesn't you will know what you need more
Yes inkcanvas is for simple things but before you start coding a lot try to specify what you need.

WPF control for image manipulation

I need to load an image in a WPF window, an be able to read and modify individual pixels (in an efficient way), zoom the image (and scroll it), get the value RGB/grayscale of the pixel under the cursor, select areas (I guess knowing the cursor position and being able to modify pixels I could draw myself the square which represents the selected area)...
What is the best combination of WPF controls and classes to accomplish this?
I've been trying to do it loading a System.Windows.Media.Imaging.BitmapImage and putting it into a System.Windows.Controls.Image, but it's taking much longer than I expected.
Thank you very much
I once used this WPF Interactive Image Cropping Control. Go check it out, it should at the very least give you a good place to start. Oh, and welcome to Stackoverflow. :)

Categories

Resources