|
Why no use AddRange for adding the buttons, then you don't need a loop at all.
And of course, make sure that defaultSelectedButton is actually one of the buttons in the array, rather than a copy of.
I've just done a test and dynamically added a button to a form, then called myButton.Focus() and the newly added button does indeed get focus, so check up on the defaultSelectedButton, because it should be working.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
I just wanted to add that
- foreach loops the same way as you would probably yourself with a for loop (nothing strange about it, really) --> keep the foreach, because it is better readable
- Focus should work, to debug the problem, try to have a look at the ActiveControl property of your form or user control to see, which control has currently the focus and whether that control has a validate method that prevents setting of the focus to the button.
Urs
-^-^-^-^-^-^-^-
no risk no funk
|
|
|
|
|
Good Day,
Say I have a single dimension array as such:
int MyArray[] = {1,2,3,4,5,6,7,8,9,10};
And I want to randomly shuffle the contents of that array. I did a google search but the results were crappy.
Can anyone guide me on how to accomplish my this task?
Thanks!
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
apstring ShuffleAns(apstring ans1,apstring ans2,apstring ans3,apstring ans4)
{
apstring set[4]={"","","",""};
set[0]=ans1;
set[1]=ans2;
set[2]=ans3;
set[3]=ans4;
apstring rval[4]={"","","",""};
bool used[4];
for(int k=0;k<4;k++)
used[k]=false;
Random* rnd=new Random();
int icount=0,inum=0;
while(icount<4)
{
inum=rnd->Next(0,4);
if(used[inum]==false)
{
rval[icount]=set[inum];
used[inum]=true;
icount++;
}
}
apstring rvalr=rval[0];
rvalr+='~';
rvalr+=rval[1];
rvalr+='~';
rvalr+=rval[2];
rvalr+='~';
rvalr+=rval[3];
return rvalr;
}
This is some code that I reuse/translate for all of my projects. I took this particular piece of code from my who wants to be a millionaire program so this randomizes the answers. (This is in C++ by the way, but if you have problems understanding it just post back)
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Thank you Mr. Stockwell, I'll just convert this to C#.
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
I do it differently. Instead of shuffling the whole array (or collection), I randomly select one item from it at a time as needed.
|
|
|
|
|
Why so complicated? Why not something simple like this? 'Hope I'm not missing something obvious.
int MyArray[] = {1,2,3,4,5,6,7,8,9,10};
// Shuffle array by stepping through each element and swapping each number with another random position.
Random RandomIndex = new Random();
for (int i = 0; i < MyArray.Length; i++)
{
int randomIndex = RandomIndex.Next(MyArray.Length);
int temp = MyArray[i];
MyArray[i] = MyArray[randomIndex];
MyArray[randomIndex] = temp;
}
|
|
|
|
|
Hi My Friends,
In the Microsoft Visual Studio .Net sometimes when you change your source code and run your project the changes not effect.
In this cases you should from the Build menu select Clean Solution and run again.
My question is :
1. Why ?
2. How can prevent from this action ?
Best Regards,
Reza Shojaee
|
|
|
|
|
1 - I've never seen this happen to a C# solution, but the main reason is that the compiler tries to be intelligent and only build what has changed. If it gets confused, it may not build your code, saw this in VC6 all the time
2 - you can't, if you could, then why would you need the option in the first place.
Christian Graus
Please read this if you don't understand the answer I've given you
"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 )
|
|
|
|
|
Thank you
I use C# 2005 and sometimes haven't this problem but sometimes have problem, I think perhaps one option exists that prevent intelligent compiling, and I search for this option.
Best Regards,
Reza Shojaee
|
|
|
|
|
Do you use project or file references for your projects in your solution to reference each other?
Project references are preferable.
Just a guess though
-^-^-^-^-^-^-^-
no risk no funk
|
|
|
|
|
how to use crystal report
|
|
|
|
|
I don't personaly know, but the search box is an amazing tool.
Try typing crystal reports into it. I think the second reult seems promising.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
I hope you're joking.
Try reading the forum guidelines, and the article I link to in my sig. Also, consider that a book, or even an online article, will provide more indepth help that is more suited to a base line question like that one.
Christian Graus
Please read this if you don't understand the answer I've given you
"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 )
|
|
|
|
|
hi dude.
This question proves that you are a beginner . try searching google for your question....here you can get only suggestions.. like read books , ' what is google ' ........... its better to have a search on google before asking a question...
Happy programming
Dont Get Paid for the Hours you worked, Get Paid for the Work You Have Done in an Hour.
|
|
|
|
|
Figure out that one first.
|
|
|
|
|
Hi,
Got some problem with a set of buttons i've positioned in workspace area in my MDI-form. Not really GUI-standard but client wants it this way. The trouble is they "float" over every child form opened within my MDI (click event opens child form). Been looking in button class as well as form class for a property solving my problem. Thinking of something like "always on top"...
Kind of a newbie problem but any input most welcome!
Best Regards
Anders
|
|
|
|
|
Why dont you use a tool bar or menu bar for this ?
Dont Get Paid for the Hours you worked, Get Paid for the Work You Have Done in an Hour.
|
|
|
|
|
I must use the functions in an unmanaged DLL. The function prototype is as follows:
extern "C" double __stdcall AvgEntryPrice(LPSTR instrument, LPSTR account)
My best effort is below but it's not working, can I get some help on this please, thanks.
using System;<br />
using System.Runtime.InteropServices;<br />
<br />
class PlatformInvokeTest<br />
{<br />
[DllImport("NtDirect.dll")]<br />
public static extern double AvgEntryPrice(string c, string c);<br />
<br />
[DllImport("NtDirect.dll")]<br />
internal static extern int _flushall();<br />
<br />
public static void Main()<br />
{<br />
AvgEntryPrice("ES08", "Sim101");<br />
_flushall();<br />
}<br />
}
modified on Saturday, April 26, 2008 5:25 PM
|
|
|
|
|
How do you know it's not working, if the dll never returns anything to you ?
I assume this is not a Windows dll. www.pinvoke.net has lots of signatures for windows dlls. They have some info too, it may still help. But, this looks OK to me.
Christian Graus
Please read this if you don't understand the answer I've given you
"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 )
|
|
|
|
|
Hi, thanks for your response.
1-I get the "The parameter name 'c' is a duplicate'
which is from the line where it says ....AvgEntryPrice(string c, string c);....
p.s. edited
OK,I took care of this problem! it now reads the following am going to chec it agais now.
AvgEntryPrice(string instrument, string account);
|
|
|
|
|
Oh - that self explanatory then. You can't have two parameters with the same name. Sorry, that's just so obvious that I missed it, I was looking for a p/invoke problem, not a general coding one.
Christian Graus
Please read this if you don't understand the answer I've given you
"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 )
|
|
|
|
|
I don't get any build error after correcting the above problem but when running the .exe I get the following error:
Failed to initialize COM library (0x80010106).
|
|
|
|
|
OK, now your code works, but you have a problem with this dll. If it's a COM dll, you should import it into your project, not use p/invoke. Otherwise, read the docs for the dll, to work out why you're calling it incorrectly.
Christian Graus
Please read this if you don't understand the answer I've given you
"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 )
|
|
|
|
|
in the DOS win, it gives the following message. BTW line 15 is ..AvgEntryPrice("ES08", "Sim101");
I also put the DLL in the same dir as the .exe
AvgEntryPrice("ES08", "Sim101");
Unhandled Exception: System.AccessViolationException: Attempted to read or write
protected memory. This is often an indication that other memory is corrupt.
at PlatformInvokeTest.AvgEntryPrice(String instrument, String account)
at PlatformInvokeTest.Main() in C:\Documents and Settings\k\My Documents\C# C
odes\DLL Methods\ConsoleApplication2\ConsoleApplication2\Program.cs:line 15
|
|
|
|