How to create an number line control? - c#

I'm planning to create a number-line control similar to the image below (only one of them):
I'm creating a program where the children can detect where's the position's number. I mean, instruct them to write the number 4 (and the boy writes a vertical line).
The idea is when the cursor is on the control, it shows a vertical line. And when the user presses OK, returns with an event the X position and hold it the line.
Do you know if there's a similar control on the web?

Just use a Slider with a new template.
How to Create/Apply a Slider Template

Related

Replace Text in Label With Inline Image In C#

My program has several Label controls that are updated to have different text every so often. I have a few icons that I want to reference within the text. I figured that instead of just displaying "(E)" in the Label, there should be a way to replace that with the corresponding image that I have that looks like: . I figure that I need to override the Label.Paint event, but I'm not too sure how to do that properly. Every occurrence of "(E)" needs to be replaced with the image inline.
Example
Look for the (E) icon on the top. → Look for the icon on the top.
This is not a trivial exercise.
You'd have to provide a property on your derived label class to attach the image(s) to the text.
Embed some sort of token(s) in the text to represent the image(s).
In the OnPaint you have to parse the text for the token(s)
Do a graphics.MeasureString() for each bit of text between the tokens. And then render it with graphics.DrawString() move to the right by the width of the text, render the image based on the token using one of the many graphics.DrawImage() overrides - move to the right by the width of the image and repeat.

Xamarin.Forms keeping text in the middle of a scrollview enlarged?

I have a pretty vague description of something I'd like to do, but not entirely sure if it's possible. Well, more accurately not entirely sure of the best way to go about it.
Say I have a single ScrollView and my device is in landscape mode. I have 15 Label objects each on their own line so most of them are off the screen. The user can scroll up and down as you would expect. That's all fine.
For talking sake let's assume that we can only fit 5 Label objects on the screen at any one time. How would I go about ensuring that the middle item of text (the third) on screen at all times has a larger font size? I.e. if the user continues to scroll down the fourth item would become the new centre item and thus be enlarged. Even better, the first and fifth items would be even smaller.
Does that make any sense?
It's kind of like on an iPhone when you're selecting a Month, it's a spinner effect where the middle item (the one that is selected) is always highlighted.
This isn't something you're going to get out of the box. You can either create a custom control and relative custom renderer and build it all out manually, or you could tap into the ScrollView.Scrolled event, then look at the ScrollView.ScrollY value, and then iterate your Labels manually adjusting the FontSize property based on some calculations of how close they are to the scroll position.

Clicking grid view with drag and drop? [duplicate]

This question already exists:
Closed 10 years ago.
Possible Duplicate:
Click and drag image to image grid?
I have a few image boxes in my form and I was wondering how can I would place a grid across the form that have a bunch of lines so the whole grid is a bunch of 64 x 64 squares. I need it so I can select an image and place it onto a specific square using the mouse and be able to go through the whole grid and check for example how many of one specific image is on the grid. To give you a better idea of what I'm doing is that I have a few image boxs which contain different 64 x 64 images. There is another image box that shows the image I clicked on last, which is like a brush because whenever you left click a box in the grid it pastes it into that specific box in the grid. I also need it so I can right click the box and delete the image in the box the mouse is over. Finally I need to be able to read all the images in the box and output it into a file that I can later open. I'm using it to create land in a game, which the program will output the needed texture and and where ground level is for the boxs which make up the whole terrain. What I need to know is what kind of thing should I do to be able to do this? I've been trying the past few hours on how I make the boxs and how to know where the mouse is and stuff and I'm completely stuck. A simple idea would be helpful. I actually don't know what control(s) I should use for this so an idea that doesn't involve any grid controls is still very helpful.
I don't know if it's the best possible idea, but you could use FlowLayoutPanel with WrapContent set to true and FlowDirection = LeftToRight. I dont know about Drag&Drop operation though (never done it with FlowLayoutPanel, buth there are some nice tutorials out there).
You can track your mouse position using mouse events. If you don't want to do that:
You can get absolute position at any time using:
Point currentPos = System.Windows.Forms.Cursor.Position;
Then, to get relative position on your (current) control:
Point relativeLoc = this.PointToClient(currentPos)
... and then, to get control over which your mouse is on FlowLaoutPanel:
Control c = flowLayoutPanel1.GetChildAtPoint(relativeLoc);

object is not clickable

I'm using adorner to draw line on canvas which works but the issue I'm facing is that it is not clickable so I have to keep clicking ten times to select it using mouse.
Is there any property setting that I have missed here?
thanks.
amit
If you use the pixels (default hittest) to determine whether or not the user clicked a line, the user has to click the line exactly. When a line is very thin this is very hard.
Another way of handling this is by calculation. When the users clicks calculate the distance between the mouse location and the lines and select the line that is closest.
You could even make an ordered list of the lines that are within a specified radius and select the next line from this list when the user clicks again.

DrawString over a TextBox [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Watermarked Textbox for Compact Framework
Using Visual Studio 2008 SP1, the latest Compact framework and Windows Mobile 5.
I need to use DrawString to put a string over a TextBox. But as soon as I draw the string the TextBox Control just over writes it. (I Know because I drew slightly off the edge of the control and my text is half visible (where is is off the control) and half gone (where it is on the control.)
Is there anyway I can get the TextBox to not refresh so I can keep my text there?
NOTE: I have looked into subclassing TextBox and just having it paint my text. However, Paint events for the TextBox class are not catchable in the CompactFramework. If you know a way to be able to paint on the TextBox without the Paint events then I would love to subclass the TextBox class.
--End of Question--
Just in case you are wondering why I need to do this, here is what I am working on: I need to have a text box where a numeric value must be entered twice. I need some sort of clear clue that they have to enter the number again. I would like to have a slightly grayed out text appear over the text box telling the user to re-enter.
I have tried using a label, a hyperlink label and another text box, but they obscure the text below (which has a default value that has to be partially visible).
If anyone knows a different way cue for re-entry that would be great too!
Vacano
You can solve this problem in a different fashion. It sounds like you want to silhouette their previous input so they must type it again.
I don't know what strides the CF has made recently but if there is a RichTextBox then this method will work. If not you would have to write your own implementation starting with a base control.
Set the text of the RichTextBox to the silhouette value but make the text color gray for all the characters.
Capture the keypress events and as they press the correct key, change the text color for that character pressed from gray to black and discard that key press, and discard all other key presses.
This solution won't work if you want to allow them to go off the reservation, such as freeform text. Instead of discarding what they typed if they mistype or enter a different character you would not discard the keypress, but blank out the current and remaining gray characters thus allowing them to type with no silhouette.
As I answered in the closed dupe of this:
Where are you doing the DrawText? On the TextBox parent? If so, then that would be expected behavior. Why not create a custom TextBox control that paints (by overriding OnPaint) the value the first time, maybe in something like a light grey, then the second time paints it again in Black?

Categories