|
Hi i have come across a problem using combo box events
private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (Control.ModifierKeys == Keys.Delete)
{
imageViewer1.DeleteSelectedShape();
}
}
private void comboBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
comboBox1.Text = "hello";
}
For some reason the above code is not fired, it is probably a simple constraint i do not know about but can anyone see why this is would not fire.
Thanx in advance
|
|
|
|
|
I suggest you read the documentation on Control.ModifierKeys , your code is not OK.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Ah thanx that was a silly mistake.
Modifier keys (SHIFT, CTRL, and ALT) not Del
The problem is that when run it doesn't make it that far as the events are never fired
|
|
|
|
|
Just found a solution so thought i would post it :
Most controls don,t fire delete on key press so override command key pressed and check value in keypress
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Delete)
OnKeyPress(new KeyPressEventArgs((Char)Keys.Delete));
return base.ProcessCmdKey(ref msg, keyData);
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (Char)Keys.Delete)
{
imageViewer1.DeleteSelectedShape();
}
}
Thanx for the help
George
|
|
|
|
|
sounds fair. Some keys are used to support editing, unless you tell the control otherwise.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
try this:
private void textBoxSize_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar > 47 && e.KeyChar < 58) || e.KeyChar == 8 || e.KeyChar == 13)
{
/*do something*/
}
}
modified 27-May-14 5:12am.
|
|
|
|
|
Hi,
I have a FOR loop in my code which is used to scan through a excel sheet. something like this
for(int i = 250 ; i< count -1 ; i++)
Basically I want to create some kind of a provision(like a text box and a save button) on the windows forms to allow the user to the set the value of "i" dynamically using the GUI and save this value, so that the excel sheet is read from that index. How do I set such a user parameter?
Kindly let me know how to go about achieving this task,,,, or if you have better ideas.
Thanks ,
|
|
|
|
|
spankyleo123 wrote: Basically I want to create some kind of a provision
This is covered in nearly all introductory tutorials and books on C# I have ever seen.
Add a text box and a button to your form.
Add code in your button_click event to get the text value, convert it to an int and store it in some useful location for your loop to use.
|
|
|
|
|
But I want to save the input value so that the sheet is read from that index unless updated later by the user.
|
|
|
|
|
spankyleo123 wrote: But I want to save the input value so that the sheet is read from that index unless updated later by the user.
OK, save it somewhere else. How difficult can this be?
|
|
|
|
|
OK sir, I have managed to solve it. I save the content into a text file user streamwriter and on form load used the stream reader.
Thanks,
|
|
|
|
|
Hey guys,
I want (just for fun) to create a poker (texas hold'em) server which allows up to 12 clients to connect and play a game of poker. I want to know what's the best approach to create a server - client application like this?
I was thinking of creating a TCP Listener (server) and let clients (TcpClient) connect to the listener (server). Is this solution going to solve my puzzle or do I need to think in a different way?
For your info : My goal is to get the poker server to work on my LAN.
Thanks guys!
|
|
|
|
|
Hi,
maybe you should check out .NET Remoting via TCP or HTTP-channel. It would be the easiest and fastest way to build up a distributed application like the one you're about to create.
modified on Tuesday, November 24, 2009 9:19 AM
|
|
|
|
|
Erhm, I don't want the application or parts of the application to run distributed. I want one server application, and multiple client applications. The clients connect to the server.
And for example, when a new client joins, the server sends a message to all clients that a new client joined and all clients seperately handle that message.
|
|
|
|
|
That is exactly what you can do with .NET Remoting. Check out the articles as regards this subject on the codeproject and you'll find what you're looking for. There're are a lot of examples there.
|
|
|
|
|
Hi all
I want to use volatile var in my multithreaded program.
Reading Writing operations are guaranteed to be thread safe.
What about comparing against other values?
Do you know if it is thread safe doing something like
<br />
static volatile long myValue = 10;<br />
if( myValue == 30 )
{<br />
} <br />
or if it is better to use Interlocked class approach?
Thanks in advance
CS
|
|
|
|
|
manustone wrote: if it is thread safe...
yes it is.
reading means: any way to obtain the value
writing means: any way to set a new (or same) value
therefore a conditional test is a read, and myValue++; is a read and a write.
manustone wrote: it is better to use Interlocked class approach?
depends on circumstances; with a simple value type, that can be entirely read in one CPU instruction, and when only one writer/producer is present, it is sufficient and Interlock is slower. In most if not all other cases, volatile is insufficient.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Hi Luc!
Thanks for your reply!
When you say "most if not all other cases volatile is insufficient" do you mean that when I use volatile keyword with NOT VALUE types i.e. REF TYPE thread safety is not guaranteed and that it is better to use other approach? (lock, interlock, etc.. ).
I starting digging about volatile stuff and it seems that a lot of people are really careful while using it.
|
|
|
|
|
Sharing a reference type amongst threads isn't straightforward; a simple volatile won't cut it. The object itself, or the code using it, must be organized to be "thread-safe" as an object typically has a state that encompasses all its data members.
And when in doubt, play it safe.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
OK! It is clear!
Thank you very much and have a nice day!
CS
|
|
|
|
|
Luc Pattyn wrote: yes it is.
So... did you see he wrote volatile long ?
Reading a long is normally 2 reads (in 32bit mode) - volatile might have fixed that, but you can't apply volatile to longs
|
|
|
|
|
so it is extremely safe, it won't even compile.
you're right of course, I should have noticed long and volatile don't work together well when building for "anyCPU".
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
I didn't even notice. I read "integer" in the title of the post and after that my brain switched off and the reference to long never registered.
|
|
|
|
|
manustone wrote: Reading Writing operations are guaranteed to be thread safe.
I think the answer here is "Yes, but...". The following code example is not thread-safe and can produce two UniqueIdentifiers with the same value, despite the fact that _currentIndex is declared as volatile:
public class UniqueIdentifier {
private static volatile int _currentIndex = 0;
public int NewIndex {
get {
return _currentIndex++;
}
}
}
In this case, you would probably want to use Interlocked.
|
|
|
|
|
Hi DaviD, thank for your reply!~
Auch!!!
let me guess!
since _currentIndex++ are 1 read+ 1 write operations ( _currentIndex = _currentIndex +1 ) and since volatile guarantees thread safety on separate operation ( either read or write ), if another thread accesses between the read and the write the application will have a very bad issue.
Is correct what I am guessing?
|
|
|
|