|
jrahma wrote: How?
HANDLE THE EVENT !!!
If you still don't understand then give up.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I have a combobox1 and I want to move to another combobox2 (in a different panel).
I tried to put the KeyCode Tab in the KeyDown but it didn't work and when I tried the same in KeyUp it will move immediately to combobox2 when combobox1 gets focused
What can I do if I just need a simple (move to combobox2) when user uses Tab on combobox1
|
|
|
|
|
I don't recall the details, the solution must be in one of the properties TabStop, TabIndex; and/or one of the methods IsInputChar(), IsInputKey().
|
|
|
|
|
Luc is right - it is the tab order you want.
Stop trying to handle the Tab key yourself - Windows handles it quite well for you. Assuming that the two comboboxes are on the same form: (If they aren't then you definitely want to change the whole design because that would be horrible and confusing for the user)
Make sure each combobox has it's TabStop property set to true - this is the default.
Since they are in different panels, set the TabOrder for each Panel so they are consecutive. I.e. panel with combobox 1 has taborder 0, panel with combobox 2 has taborder 1. Make sure that no other controls has those Tab Order values. (There is a toolbar button for view / set of taborder on the Layout toolbar - normally at the far right end.)
That's it. Windows now takes care of it.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
I have a method that takes a SendOrPostCallback delegate as a parameter.
public void Post(SendOrPostCallback sendOrPostCallback)
{
}
I want to overload this method and instead take a MethodInvoker delegate.
public void Post(MethodInvoker methodInvoker)
{
}
The problem is this second method needs to convert the MethodInvoker to a SendOrPostCallback using null for the state parameter so it can call the original method.
I can't figure out how to do this
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Do you mean something like this?
void Post(MethodInvoker methodInvoker)
{
Post(new SendOrPostCallback((object useless) => { methodInvoker(); }));
}
Ok it isn't really a conversion.. but afaik that isn't possible anyway
edit: nevermind, if this was what you meant you wouldn't have asked..
|
|
|
|
|
harold aptroot wrote: if this was what you meant you wouldn't have asked
Well it does what I asked so I guess it was! Not being a Linqy kind of guy I have nor really used lambda expressions so I'm off to work out how/why this works and to see if can be done without the lambda
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Well, you could easily do it with a normal anonymous method:
void Post(MethodInvoker methodInvoker)
{
Post(delegate (object useless) { methodInvoker(); });
}
Or you could go for Pain and do it the manual way:
class HolderThingy
{
public MethodInvoker methodInvoker;
public void Invoke(object useless)
{
methodInvoker();
}
}
void Post(MethodInvoker methodInvoker)
{
HolderThingy holder = new HolderThingy();
holder.methodInvoker = methodInvoker;
Post(new SendOrPostCallback(holder.Invoke));
}
|
|
|
|
|
Cool
Is there anyway to do it using the null keyword instead of
object useless ?
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Not that I know of.. it has to match the method signature of SendOrPostCallback , so you need an argument of type object .
Why do you want to use null ?
|
|
|
|
|
no particular reason, useless is null anyway so it's no overhead.
Many thanks, credits are in the code pointing here
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
You're welcome, and thanks
|
|
|
|
|
Hi Guys
I was working on a new class to simplify my code for multicore apps, but I stumbled on some difficulties...
I have already written code to exploit a dualcore and a quadcore, but only i a static fashion.
What I would like the class to do is, accept a method by means of a delegate and some arguments.
Then the class should check the number of cores and start the same number of threads, each with the subset of the arguments.
Let me clarify this... Suppose I have 20 images and I want to make all of them grayscale. I could assign every core a diiferent set of images to work on, since these operations do not interfere with eachother. As I said, I have already made a similar thing for dualcore, but I want to let the class sort this out by itself, so that in theory even a 99-core is supported.
The difficulties I'm having are more concerned with the delegates and arguments that need passing. This is what I have at the moment. Consider this pseudo-code because I think it's filled with errors
private static List<Thread> threads = new List<Thread> (0);
private static List<ThreadMethod> methods = new List<ThreadMethod>(0);
public delegate void xCO_Method(); delegate void CallBack(Thread T);
static private xCO_Method Method; static private CallBack CallBackMethod;
public static void Start(xCO_Method method, object[] args)
{
int cpu = System.Environment.ProcessorCount;
Method = method;
CallBackMethod = new CallBack(Completed);
for (int i = 0; i < cpu; i++)
{
methods.Add(new ThreadMethod());
threads.Add(new Thread(methods[i].Work));
threads[i].Name = i.ToString();
}
foreach (Thread T in threads)
T.Start(args[i]);
}
private class ThreadMethod
{
public object[] Result;
public void Work()
{
Method.Invoke(args);
CallBackMethod.Invoke(Thread.CurrentThread);
}
}
private static void Completed(Thread T)
{
Console.WriteLine("Thread " + T.Name + " ended");
}
Basically I want to prevent having to write a bunch of overloads and delegates for all kinds of methods.
But perhaps there is a better way.
Thanks
|
|
|
|
|
Why not just use the ThreadPool?
|
|
|
|
|
I have little to no experience with the ThreadPool. But after reading your reply, I did some googling and it really fits my needs at a first glance. I will give it a shot. Thank for the info. I'll let you know how it turns out. I just got so accustomed to using threads that I stopped looking for other solutions I guess...
edit:
I found this link
http://msdn.microsoft.com/en-us/library/3dasc8as%28VS.80%29.aspx[^]
Now the only one questions remains...
How can I give the class a list of methods which it should execute with the corresponding arguments.
But I want to do this in a generic way. Give a list of objects or classes and specify which method should be run, with which arguments it should use. I tried delegates and params, but this is getting me nowhere...
modified on Saturday, August 21, 2010 12:36 PM
|
|
|
|
|
Steven Solberg wrote: How can I give the class a list of methods which it should execute with the corresponding arguments.
But I want to do this in a generic way. Give a list of objects or classes and specify which method should be run, with which arguments it should use. I tried delegates and params, but this is getting me nowhere...
I'm not exactly sure what you mean..
|
|
|
|
|
Sorry about that
What I mean is the following;
The basic thing I want to accomplish is dividing a repetitive task into smaller fragments, so each core can work on it. Finishing the work faster than when only one core is used.
This 'work' can be about anything; Invoking a method on an image, a method on a self-defined class, ...
So what would be ideal for me would be something like this: DoWork(list<bitmap> bmps, method which_method, object argument_for_the_method)
This could be saving a list of bitmaps to disk, or resizing, anything... The list doesn't hve to be a list of bitmaps either.
I however can't figure out how to make a delegate or class which can support methods with and without return types and different lengths of parameters. And making a delegate for each different set of possibilities doesn't seem like an option either.
|
|
|
|
|
The best way I can think of now is using the semi-new type inference for generic method arguments and make overloads of the delegate only for the different numbers of arguments. Microsoft already did something like that in some newer .NET version, I'm not sure where exactly it was introduced, I'm guessing 3.5..
Does that help?
|
|
|
|
|
It certainly gives me a place to start. I will check out that type inference you mentioned.
Thanks
|
|
|
|
|
I was thinking about something like this:
public delegate TResult Func<TResult>();
public delegate TResult Func<T, TResult>(T arg);
public delegate TResult Func<T1, T2, TResult>(T1 arg1, T2 arg2);
public delegate TResult Func<T1, T2, T3, TResult>(T1 arg1, T2 arg2, T3 arg3);
public delegate TResult Func<T1, T2, T3, T4, TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4);
public delegate TResult Func<T1, T2, T3, T4, T5, TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
public delegate TResult Func<T1, T2, T3, T4, T5, T6, TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6);
When you use them, you won't have to say new Func<type1, type2, type3 .. >(args) , at least not since VS08 (this kind of type inference does not work yet in VS05)
|
|
|
|
|
That's exactly what I needed
I assume the keyword TResult is arbitrary?
|
|
|
|
|
Steven Solberg wrote: I assume the keyword TResult is arbitrary?
Yes (it's not even a keyword), as are T1 T2 etc and arg1 arg2 etc
|
|
|
|
|
Hmmm, I noticed that I still have to specify the type in design-time.
public static void Start(List<Foto> objects, Func<...> method)
Is there a way to leave the ... undefined and let the function sort it out in run-time?
|
|
|
|
|
Ah yes, that happens, well you could give the generic parameters to Start as well and then it should work again (it usually does)
And you'd have to overload Start for every different kind of Func you want to use, too..
It's not perfect..
|
|
|
|
|
Alright I figured it out. Fresh knowledge... mmmmm
This was all stuff we had to know for our exam C++ this year. Freakin syntax...
Thanks with the generic stuff, I think I'll be alright now.
|
|
|
|
|