I know someone can help me.
I'm busy developing a select the word game but I'm not sure how to highlight the selected letters.
I'm currently creating a grid of blocks.
Then when the user clicks and moves the mouse from on block to another I use the Rect to check if they intersect when they do I mark that block as selected but I need to ignore the block number 2 when block number 3 is selected same thing should happen when block number 4 is selected. So that pattern is: 1,3,5,7 blocks number 2,4,6 should not be selected.
Kind regards,
Johan
I am assuming it to be a standard word-guessing game where word letters always fall in the boxes which are on a standing-line, sleeping-line or line at angle of 45 degrees. In which case you just need a start box and end box of user's input and you can select/mark all the boxes from starting box by adding +1 till you reach last box.
Say user stared at startBox(rowStart,colStart) till lastBox(rowLast,colLast)
So all you need to do is
rowPos = startBox.rowStart;
colPos = startBox.colStart;
do{
mark startBox(rowPos, colPos)
rowPos++;
colPos++;
} while(rowPos<=rowLast && colPos<=colLast)
Note: You will have to evaluate startBox and lastBox to figure out whether user is going bottom-right, bottom-left, top-right or top-left and accordingly add/subtract 1 to row and/or column.
Related
So, I have some simple figure (circle, ellipse, rectangle of closed polygon) and I need to fill only part of it.
I mean, I have GraphicsPath or similar object (set of points) and now I can simply fill the whole figure with, for example, orange color.
What I need: user enters 25% and I fill only 25% of the figure, starting from some side (top/bottom).
Maybe, it will be nessesary to find some sub-figure or (bad idea, I know) check all the points in on the field and fill them (only those which inside figure) one by one untill their amount will be 1/4 from the area of the figure. But it won't be so fast especially when image is about 5-6000 pixels from one side.
Here's sample what I have now and what I need for 25%. Important: instead of 25% can be any value.
Project: C# .net 3.5 WinForms
UPD:
Basic usecase.
User draws a figure (circle, ellipse, rectangle, polygon)
User enters value from 0 to 100 (percents)
I fill figure from bottom to the top until I filled amount of area (!), which is equal to user's value
I'm open for any ideas even without code.
Need help with automating vertical scrolling. I'm a teacher and my 15 year old son is learning C# to help with making online worksheets. We are currently making a computer based worksheet that teaches 3 phonics sounds using 3 letter words (cat, dog, fox, etc). The form is constructed of four rows with 5 pictures in each row. The actual worksheet used as a template can be seen at http://www.tampareads.com/phonics/phondesk/cvc/cvc-1.htm - Because of size limitations I am displaying only 2 rows at a time. When the student clicks on the correct letter for the last problem in row 2 we want the form to scroll down to view rows 3 and 4. Is there a way to get have the form to scroll down to view these last 2 rows automatically, so the student does not have to scroll manually? We've been reading and trying for days but no luck. We tried using "ScrollControlIntoView" but it would appear to work, but then when clicking the answer of the first problem in row 3, it jumps back up to row 1. We are pulling our hair out!! Any help would be appreciated.
IF your using jQuery or could add it to your page, you could do something like this.
var position = $(window).scrollTop() + 100
$('.correctLetter').click(function () {
$('html, body').animate({ position }, 'slow');
});
Position = the amount already scrolled down the page + 100. You may need to adjust the 100 to however many pixels you need to scroll.
$(.correctLetter) refers to a class on whatever element you want to trigger the scroll.
Am Using Visual studio 2010 and coding by C#. Now i want to do a star rating control ie I have some values within 5, not more than that and i want to show the value rated by start based on the rating. Below is the clear scenario.
If I get a value 5 then i have to to show all 5 star filled up with some colour.
If i get a value 3 then i have to show 3 star which is filled up with some colour and rest stars as empty.
If i get the value 3.5 theh i have to show 3 start which is filled up with colour and next 4th star with HALF FILLED and another HALF and one star as empty ie without colour.
If i get the value some 4.2 means i have to show 4 starts which is filled with colour completely and the last only 0.2 % should be filled with colour and rest part as empty.
How can i achieve this?? Am using ajax control and i don't want to use jquery please note.
Can any one help me in this??
Thanks
I guess this is exactly what you want
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/Rating/Rating.aspx
I think what you need is this......
CLICK ME
Only AJAX and No Jquery used just as you want.
I am custom drawing a text box and now I am implementing the part where the user can click on a line and have the cursor move to where he clicked.
I know how to get the row of text he clicked on because the character height is constant across all fonts, but not the column, because I'm not sure how to say "get me all the text that can be drawn before this amount of pixels," and because character width is not consistent unless you're using a fixed-width font, which is not a guarantee.
So I have the point from which I'm drawing the string (0) then I have the point that the user clicked. How do I get the string index of the character they clicked on?
Extra info: I am drawing the text by storing the lines in a List then iterating the list and using Graphics.DrawString on each line.
There is no simple method to find the character at a pixel.
However you can find the pixels that a string will fill. Use the Graphics.MeasureCharacterRanges method. You can perform a binary search on your string until you find the string where MeasureCharacterRanges returns your cursor position.
Note: You might see the Graphics.MeasureString method and be tempted to use that. DON'T! That method doesn't return accurate measurements. I can't remember why, but you will do your head in if you try!
So I'm building a custom control in C# (not WPF), and I basically want to implement text highlighting with the mouse.
How do I efficiently find the character at a given Point (say where the mouse is clicked) in a string? I have the layout rectangle of the string as it was drawn and I could calculate the length of the string up to every character until I find the one closest to where the mouse is clicked... but there has to be a better way. Any suggestions?
If I had to do this, I would look at it backward.
I'd keep the text entered as a string member in the control, so at all times I know what is actually entered in the control (like the Text property in a TextBox).
Then I would use the TextRenderer.MeasureText() method (http://msdn.microsoft.com/en-us/library/7sy6awsb.aspx) and I would keep measuring the length of the string repeatedly until I pass the X coordinate of the mouse within the control, right then I know how many characters are chosen.
For example, assume the user has the text Hello written in the control.
And the X coordinate hit right between the l and the o, which could be of value 20.
Then I would repeatedly calling MeasureText() on the following strings:
H: width of 5 pixels.
He: width of 10 pixels.
Hel: width of 14 pixels.
Hell: width of 17 pixels.
Hello: width of 22 pixels.
Then I know the mouse was hit between the l and the o, so I would then highlight the text Hell.
Sorry for the distasteful example =)
UPDATE:
You can optimize this a bit by calculating the lengths in a binary-search-tree-like fashion.
Just like you would look up a name in the phonebook, you don't look page by page, but rather split in half as you go along, getting closer and closer until it's definitely between these two pages.
Similarly, especially for long string values of the control, calculate the width of the entire string, then half its length, and split there. I think that would be O(n log n) at that point.
Of course it would be O(1) if the text is of fixed width =)
Another thing you can do to build upon BeemerGuy's great suggestion is to precalculate an array of offsets. As the string is changed (the user types or the property is set in code) you can recalculate the offset array. That will save you the call to MeasureFont on the mouse clicks and will make finding the character trivial. You basically iterate the array until you find the nearest character. Since the offsets are implicitly sorted by value you can even use a binary search to make it more effective.