|
Hi,
How can I cancel the current printing job from the printer spool using C#.
I tried to search but found unuseful information.
Could you please help me.
Thanks
|
|
|
|
|
I have a puzzle that would require some assistance by somebody who is knowledgeable about control arrays. If I had a control array of say 85 elements, and I would like to shuffle them so that they are randomized, is there an efficient approach that would work?
Initially, I would suppose that there would be a requirement to have two arrays, and that each element would be randomly "popped" off of the first array and placed (I forget the other term) onto the second array. Then, the first array would be re-dimensioned so that there would be one fewer elements. The procedure would continue until the first array contains zero elements.
Alternatively, as I recall there is some kind of Array.Randomize() routine. This would permit the randomization of one array without the need for a second array. Could one of you array gurus kindly provide some additional information and to fill in the blanks?
Say that I have an control array like so:
private Control[] controlName = new Control[85];
-- modified at 23:20 Friday 20th October, 2006
|
|
|
|
|
The following should do what you want.
Control[] controlName = new Control[85];
private void Shuffle()
{
ArrayList list = new ArrayList(this.controlName);
Random rand = new Random();
int j = 0;
for (int i = 0; i < this.controlName.Length; i++)
{
j = rand.Next(list.Count);
this.controlName[i] = (Control) list[j];
list.RemoveAt(j);
}
}
"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." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thank you, Stefan. Here is a little twist. The elements of the control array are dynamically instantiated at run time. Is it possible to randomize elements from the control array?
|
|
|
|
|
I'm sorry, but I don't understand your question. Could you rephrase it and/or explain in greater detail what you want to do.
"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." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hi,
I want to control the show/hide to another program. I use Process to start the program and make the initial window status Minimized. then I use Process to get the program main window handle and use windows API showwindow to hide the program i just started.
Everything looks fine but one thing. some of the control's visible property (or event, like viisble changed) in the started program are not correct. for example, the button is visible in the GUI, you can click and execute something, but you always get false when you check (get) the visible value . but I can use windows Api like iswindowvisible to get the right visible value.
I can use API to set/get the right value, but the related event fired are not correct!!
BTW, the program I started is created by C# (VS 2005).
Does anyone have some idea about this.
Thanks a lot in advance.
Alan Shen
MCAD for .NET Version
^~^~^~^~^~^~^~^~^~^~^
Great idea is the beginging of success!
|
|
|
|
|
Hi folks
Is there any way of manipulating mp3 files such as:
1) extracting a part of a file (the actual data) and saving it somewhere
or
2) concatenating say two files to produce a third file and saving that file?
Kind regards
Ross
|
|
|
|
|
Well, if you aren't looking to do it in code - or want an easier way - check out Audacity - it is open source and does this - you just need the LAME MP3 encoder for it.
If you needed to do it in code and were not doing a commercial release, I think you could paste their code into your app to do this.
David
|
|
|
|
|
Hi,
I have an array (which may change in length each time) of numbers (employeeid) and I want to create a random generator function to return one these numbers.
The only parameters I will be receiving are the array of numbers and the array length.
I'm new to C# so any sample code would be appreciated.
Thanks.
|
|
|
|
|
public int GetRandomInt(int[] array, int length)
{
return array[new Random.Next(0, length)];
}
|
|
|
|
|
Thanks for your reply.
I'm getting the follwoing error..
Error 2 'System.Random.Next()' is a 'method' but is used like a 'type'
All I require is just one number returned from the array.
Does return array not return a list of arrays or does the Next method refine it to one number?
Pardon my ignorance.
|
|
|
|
|
Belfast Child wrote: Does return array not return a list of arrays or does the Next method refine it to one number?
array is your variable that was passed to the method. Using the square brackets is indexing the array to retrieve one of the members of the array. Since it is an array of int, you will return an int, which is what the method signature specified.
|
|
|
|
|
Cheers Guys.
Figured it out.
Here's a test on a click button for anyone else interested
public int GetRandomInt(int[] array, int length) <br />
{<br />
Random ranNum = new Random();<br />
return array[ranNum.Next(0, length)]; <br />
}<br />
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
int [] intArray;<br />
intArray = new int[3] {123, 321, 666};<br />
int randumNum = GetRandomInt(intArray, 3);<br />
randomLabel.Text = (randumNum.ToString());<br />
}
|
|
|
|
|
You should use ranNum.Next(length) instead of ranNum.Next(0, length) as it produces random numbers within the same range and is almost 2 times faster.
Also I would suggest to retrieve the array length dynamically instead of using a fix value. Either do it when you call the GetRandomInt method or even remove the length parameter and do it inside the method.
int randumNum = GetRandomInt(intArray, intArray.Length);
"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." - Rick Cook www.troschuetz.de
|
|
|
|
|
Belfast Child wrote: Error 2 'System.Random.Next()' is a 'method' but is used like a 'type'
Random r = new Random();
r.Next(...)
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
You have to put parantheses on the constructor, i.e. use "new Random()" instead of just "new Random".
It's better to create the Random object once, and use that throughout the program, than to create a new one for every random number. When you create a new object, it will be seeded from the system clock, so if you create them too closely in time, the randomness will be poor. Also it's a waste of resources to create more than one Random object.
---
b { font-weight: normal; }
|
|
|
|
|
hi
i want to copy large file and show progressbar to show operation.
what is your suggest for this subject ?
please give me an example for progressbar and copy file.
thanks
|
|
|
|
|
|
hi ..
Bekjong don't said me how to use Stream.BeginRead() and Stream.Beginwrite and show percantage of operation in progressbar .
and please give me an example how to use these methods.
thanks
|
|
|
|
|
Realistically, this is going to slow down your copy operation, by quite a bit. He's saying you can read how big a file is, then read and write it a bit at a time, giving you access to a progress bar in your own code.
The better answer IMO is, you can't do it. Why give a progress bar at the cost of doubling the time the operation takes ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
|
Could any one help me understand this?.
I am reading an array of bytes and one of the fields is a long for the amount and I get this big number: 800000000 when it should be 80000.
Do I still have to do format the value to something else?
Regards,
|
|
|
|
|
It sounds like this could be a byte-ordering issue. See http://en.wikipedia.org/wiki/Endianness[^] for more information.
Of course, I could be completely wrong here. If you could provide a snippet of the code that was giving you problems, perhaps we could troubleshoot it.
|
|
|
|
|
I am trying to learn how to connect with a USB scale. This scale requires no special drivers and uses the HID POS class. I have a copy of all the available reports. Also, when I hook up the scale, I hear the nifty sound meaning the PC found the device. So, if I want to write a C# app to display the weight and to say "zero the scale" and so on, how do I get started? I've done serial stuff forever, but not USB and need to do it now.
Please point out some helpful places to look. I have started combing through this website and SurgeForce and Microsoft, so maybe I'll get lucky. It's just that we have never written USB pc apps from scratch before and we're sort of lost. Ideas?
Thanks.
Kenny O'Dell
Prinicpal R&D Software Eng
Mettler-Toledo Inc.
Worthington, OH
|
|
|
|
|
Hi,
Since it's a USB HID device, things are already much easier -- not that they were hard in the first place. The method of communicating with a HID device (redundant) in windows is this:
(Note: this is just a brief summary from my mind, detailed instructions can be found from this page, http://www.lvr.com/hidpage.htm[^])
1. Get the HID GUID for the system w/ the win api function HidD_GetHidGuid
2. Call the SetupDiGetClassDevs function which returns an array of active HID devices
3. Now, loop through each device and match against a product and vendor id of the device you want, using the SetupDiGetDeviceInterfaceDetail function
(this should be unique to each device and can be found via msinfo32.exe)
4. Now get the handle to the device with the CreateFile function an the device pathname from the previous step
5. Get the capabilities for the device, ie input/output report length (HID terminology)
6. SO now, you finally have the device and you can start communications with it
7. You can write to the USB HID when it has a handle to the HID
interface and knows the number of bytes it allows you to write. To write data, the
application copies the data to send to a buffer and calls win api function WriteFile . The
buffer size should equal the size reported in the OutputReportByteLength
property of the HIDP_CAPS structure returned by HidP_GetCaps . This
size equals the report size in bytes plus one byte for the Report ID, which is
the first byte in the buffer. (this is all obtained from step 5)
8. To read input from the device you use WriteFile's compliment, ReadFile a win api function.
... and that's about it! Just as long as you know the API of your device so you can make sense out of it's input you'll be fine. There's lots of work already done for .net HID interaction, all of which can be found from the HID page linked above.
/\ |_ E X E GG
|
|
|
|