|
Hi Vasudevan,
The link only said that RichTextBox supports unicode. Does it mean that it ONLY support unicode characters? Any work-around so I can load a text file using utf-8 encoding?
Thanks,
Rafferty
|
|
|
|
|
hehe I just realized that unicode is what U in UTF stands for. But I think it still loads the characters in ANSI encoding by default. Do you know how to make it load a text file in UTF-8 programmatically? (I can't use the copy paste method)
Thanks again
|
|
|
|
|
Could someone explain how to use 2 keys at once (arrow keys; up / right) without stopping each other. Say you have pictureBox1 . You want to move it to the right with the right arrow. Up, move it up. What is the code that allows the user to hold the right key down and move to the right without stopping that motion if the up key is pressed. If you have an answer thanks, anything else, I don't care to hear, after all the crap I get (no comments on the crap I get or why).
- "Achieving all knowledge does not mean achieving all wisdom." some wise dude
- I love D-flat!
|
|
|
|
|
You could keep track of keys currently pressed by catching the keydown and keyup events (not recomended because your form could lose focus while the key is down, so it keeps scrolling although not focused), or you can get keydown events, add that key to some list, and have a timer that polls the list of keys anytime you want to move in that direction. Once you see a key is no longer down (or a keyup event occurs), you can remove that key from the list. Hope this helps,
Jeff
|
|
|
|
|
For the keydown, how would you know which keys are down and when released? Switch, if?
- "Achieving all knowledge does not mean achieving all wisdom." some wise dude
- I love D-flat!
|
|
|
|
|
I think I just got it. I think I did the opposite of what you said, but I think it did what I wanted! In the keydown event, I set 2 bools to false (right above keydown). Then, in Keydown, i set if (e.KeyCode == Keys.Right)
{
movingR = true;
}
ditto for up and I think it worked!
- "Achieving all knowledge does not mean achieving all wisdom." some wise dude
- I love D-flat!
|
|
|
|
|
Just be careful doing that, because if another window pops up (like an internet add, or an instant message window), then you will NOT get the keyup message, so your application will continue to scroll even though it doesn't have focus (depending on how you implemented it), which can be really annoying for the user. In addition, after regaining the focus, it will still try to scroll down even if the key is not depressed. You will have to repress the down button to get it to stop (again, depending on how it is implemented).
Jeff
|
|
|
|
|
Actually I didn't get it. It's all glitchy. Jeff, your code has one error, with the "Contructor" part. Isn't there some simple code with a switch or anything that allows more than 1 button to be pressed simultaneously? If there are any more suggestions, think Mario-ish. Thanks for anyone who tried to help, though, I mean that.
- "Achieving all knowledge does not mean achieving all wisdom." some wise dude
- I love D-flat!
|
|
|
|
|
Do the following...
IList<Keys> m_keys = new List<Keys>();
object m_lock = new object();
Timer m_timer = new Timer(1000); // Move once per second
public Constructor() {
m_timer.Elapsed += new ElapsedEventHandler(m_Elapsed);
}
private void m_KeyDown(object sender, KeyEventArgs e) {
e.SuppressKeyPress = true;
e.Handled = true;
lock(m_lock) {
if (!keys.Contains(e.Key))
keys.Add(e.Key);
if (!m_timer.Enabled)
m_timer.Start();
}
}
private void m_KeyUp(object sender, KeyEventArgs e) {
e.Handled = true;
lock(m_lock) {
keys.Remove(e.Key);
if (keys.Count == 0)
m_timer.Stop();
}
}
private void m_Elapsed(object sender, ElapsedEventArgs e) {
lock(m_lock) {
for (int i = m_keys.Count - 1; i >= 0; --i) {
if (m_keys[i] is depressed) // this is pseudocode.
perform action based on key being pressed
else
m_keys.RemoveAt(i);
}
}
}
Hope this helps!
Jeff
|
|
|
|
|
Hi Jeff,
I believe the basic idea is fine, but there probably is one problem, the single timer can not
possibly sync with multiple keys, so the second key pressed might autorepeat immediately;
IMO one really needs a timer for each entry in the keys collection.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Do you have any ideas, Luc? I'm sorry I bug you and the other vets, but... I just need this to make the game polished. I've got (actually, REALLY) good collision checking, 5 levels so far, menus, and I plan more things. I just want the controls to not suck. Thanks for any ideas.
- "Achieving all knowledge does not mean achieving all wisdom."
- I love D-flat!
|
|
|
|
|
Okay: The final say from it not working is, that it works for right and left, but you would have to hold the SpaceBar to make the pictureBox go right without stopping. Help?
- "Achieving all knowledge does not mean achieving all wisdom." some wise dude
- I love D-flat!
|
|
|
|
|
I would do something along these lines:
- use a Windows.Forms.Timer, it ticks on the GUI thread
- no lock is needed, all key/timer actions run on GUI thread, without
interrupting each other.
- timer ticks all the time, at 10 times the autorepeat frequency (overclocking)
- each key is synchronized to the overclocked timer. with the const values shown
it would start repeating after 900 to 1000 msec.
- you can easily choose different start repeat and repeat times...
Dictionary<Keys,int>m_keys = new Dictionary<Keys,int>();
Windows.Forms.Timer m_timer = new Windows.Forms.Timer();
const int initialWait = 10;
const int repeatWait = 10;
const int overPeriod = 100;
public Constructor() {
m_timer.Interval=initialWait;
m_timer.Start();
m_timer.Tick += new EventHandler(autoRepeatTick);
}
private void m_KeyDown(object sender, KeyEventArgs e) {
Keys key=e.KeyCode;
handleKey(key);
if (keys.ContainsKey(key)) {
m_keys[key]=overClocking;
} else {
m_keys.Add(key, overClocking);
}
}
private void m_KeyUp(object sender, KeyEventArgs e) {
keys.Remove(e.KeyCode);
}
private void autoRepeatTick(object sender, ElapsedEventArgs e) {
foreach (Keys key in m_keys.Keys) {
int wait=m_keys[key]-1;
if (wait<=0) {
handleKey(key);
wait=repeatWait;
}
m_keys[key]=wait;
}
}
private void handleKey(Keys key) {
... game code
}
Above code is indicative, but has not been tested!
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
I kind of like this idea, but I feel like combining both keys into one action will improve performance, especially if making a game. Giving each key "it's own timer" as indicated in this post will give the "expected" result, but you will have to render your scene up to twice as much as if you handled the keys together at once. This could result in your game hanging if it is a realtime sort of game with lots of detailed shapes. The alternative may make the buttons lag or double press in a short time (depending on implementation), but it will prevent rendering up and right separately. Just a suggestion.
Jeff
|
|
|
|
|
It all depends on the numbers I guess: with a 1-second autorepeat, I would type much faster
than that, making your render argument moot.
If the repeatWait delay were much less than indicated earlier, you might indeed want
to synchronize them. But by all means, while holding down a first key, a short hit of a
second key should never fire twice. So its autorepeat should only start when more than an
entire timer period has elapsed. (In my code, you could adjust the initial wait to achieve
this).
And if the repeatWait becomes less than say 20 msec (that's the repeatWait, not the
initialWait!) it would not matter any more since the player would be unable to notice...
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Direct Input
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Why not use the Shift or Control keys for a different state?...you can have both of those simultaneously...that's what they are for, to modify the state of a keypress.
|
|
|
|
|
Hi,I need a Sample code for setting for example ReportViewer1.BorderStyle in my source file.when i run my project in C#,there is a error message for this code: ReportViewer1.BorderStyle="solid".How can i write code like this without using ReportViewer Toolbar before running the project to define my Report Page setup as like as BorderStyle seting ,page setup setting for example my papaer size to be A4 and margin setting and other properties of my Report without defining this properties at running time or design time only with writing code in source file in my report from ?
thanks
D.riazi
|
|
|
|
|
I know this message isn't too C# oriented, but how would I program my own computer, as in what tools would I need to start from scratch, but also for modifying Windows. (Is that even legal?) I know this is WAY, WAY, WAY, WAY, WAY, WAY, WAY above my head, I'm just curious in case I lose my stupidity. Thanks for any suggestions/comments. (unless they're mean!)
- "Achieving all knowledge does not mean achieving all wisdom." some wise dude
- I love D-flat!
|
|
|
|
|
|
Haha. Funny, aren't we?
- "Achieving all knowledge does not mean achieving all wisdom." some wise dude
- I love D-flat!
|
|
|
|
|
Starting from scratch, as in bypassing windows, is a major, major task. I'd say forget it.
You can't modify windows, you don't have the source code.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Okay; thanks for a simple quick answer.
- "Achieving all knowledge does not mean achieving all wisdom." some wise dude
- I love D-flat!
|
|
|
|
|
MasterSharp wrote: but how would I program my own computer, as in what tools would I need to start from scratch
A compiler in the language of your choice.
MasterSharp wrote: but also for modifying Windows.
In what way would you like to modify windows?
MasterSharp wrote: Is that even legal?
That depends on what you regard as modify. I suppose there is nothing stopping you modifying any part of windows, but is it wise. Windows has sophisticated systems in place that allow you to hook into the OS without modifying it.
Upcoming FREE developer events:
* Developer! Developer! Developer! 6
* Developer Day Scotland
My website
|
|
|
|
|
What kind of compilers? Any known. Thank you for your answers so far!
- "Achieving all knowledge does not mean achieving all wisdom." some wise dude
- I love D-flat!
|
|
|
|