|
1- Get current mouse position using Form.MousePosition property
2- Copy the area of the screen you desire using Graphics.CopyFromScreen()
3- scale it using Graphics.Scale() method.
3- Draw it into a Bitmap
4- View the bitmap in the other form inside a PictureBox for example.
Regards
|
|
|
|
|
I have a unique situation. I need to selectively play some mpeg videos in different sequences depending on the state of my main App. I have been able to add WMP to my form and play videos by setting URL = @"C:\path\filename.mpg". However, in the release version I cannot store the videos on the customers drive, so they must be embedded in the resources of the app. That's not the problem though.
I would like to be able to create a MemoryStream and dynamically build the "file" which will reside in memory. However, there is no way to tell the WMP control to play my System.IO.MemoryStream. I would have to save to disk and set URL = the new temporary file, and that isn't allowed.
Is there a way to point the URL at a resource in an assembly ?
If not, can I tell WMP to play a System.IO.Stream ?
|
|
|
|
|
Both are possible, I'm quite sure. But telling WMP to play a Stream would involve writing a shell extension that pretends your stream is a file.
An easier option might be the embedded resource route. Does this article[^] help you?
|
|
|
|
|
I have a windows form that inherits numerous controls from a parent form. Whenever I open the child form in the designer, I immediately get an asterisk that the file has unsaved changes, before I have changed anything. When I look at the .designer.cs file, numerous lines have been added, such as below:
Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance();
this.ultraGridValidator.DisplayLayout.Appearance = appearance1;
...
And numerous lines have changed throughout the designer file (mostly locations and sizes):
this.configTab.Size = new System.Drawing.Size(766, 295);
When I open the base form in the designer, I get the asterisk, but usually nothing has changed. Sometimes locations / sizes have changed, even though I haven't moved anything. Obviously we're using Infragistics, but I don't know if that's the cause of the problem. I only suspect it because most of the lines added are related to the grid. I am also suspicous of the toolbar we recently added, just because of the timing. I have read msdn articles regarding problems with editing complex controls on inherited forms, but we're not trying to edit anything. We're just trying to keep things from randomly changing!
Has anyone seen anything like this? And any suggestions on how to fix it? It's killing productivity on our gui.
This is .NET 2.0 with Infragistics 6.1. I tried the latest VS service pack, but no luck.
Any help would be appreciated.
Thanks in advance.
|
|
|
|
|
I've noticed this when I'm working with files via sourcesafe, and I switch to design mode or html mode.
|
|
|
|
|
Thanks for the reply. I do remember this happening when I've used sourcesafe in the past, but we are using svn.
And just to clarify, this is a windows form.
Thanks.
|
|
|
|
|
I'm programming for a Symbol CE device (WT4070) with reduced key board, no mouse, and no touch screen. As such, I have to tab from button to button on the form to get the focus on the button i want. Then to invoke the button with focus i have to hit two keys on the key board (blue and backspace) to send a space in order to "click" the button. I want to just hit one key, the enter key, instead.
So, how do i trap the enter and turn it into a space?
I tried putting the following code in my form class, but it failed to compile saying "no suitable method found to override. Note I have "using System.Windows.Forms at the top and the object browser shows the ProcessDialogKeys is in there.
Any Ideas?
Here is the code that doesn't work:
protected override bool ProcessDialogKey(Keys keyData)
{
switch (keyData)
{
case Keys.Enter:
case Keys.Space:
return base.ProcessDialogKey(Keys.Space);
}
return base.ProcessDialogKey(keyData);
}
|
|
|
|
|
Hi coders
I'm doing some advanced calculations mostly on sound, but I'm relative new to C#...so
I was wondering if anyone has some advice on how I can (if possible) speed up the more primitive part of my code...e.g when I want to multply to arrays colmnwise. In Matlab this would look like Z=X.*Y but I cannot figure out a smart way to do this without using a for-loop in C# like
for (int i = 0; i < length; i++)
{
Z[i]=x[i]*Y[i];
}
As you can see, this takes a long time if the array consist of a sound segment of e.g 3 seconds which is 132300 samples. Do you know of any better way how this can be done...
Best regards
AL
|
|
|
|
|
|
Behind the scenes, Matlab is creating a for loop for you. If you want a faster implementation that avoids the .net bounds checking, you could try writing the innermost layer of your code in c++ (with optional processor specific asm optimizations to use MMX/SSE instructions) and then using pinvoke to call it from the main c# portion of your app.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
Unsafe C# can get around bounds checking as well, and would be a lot easier that having to code up a separate C++ lib and invoke that from C#.
|
|
|
|
|
True, but IIRC native code is still faster than unsafe.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
I'd be surprised at that. And given the P/Invoke overhead that would be required with a C++ lib on the side, unsafe C# may quite well out-perform.
|
|
|
|
|
I'm not sure if this counts or not, there'e //unsafe comments in the C# source, but I thought you needed an unsafe keyword as well which I didn't see. It does have c++ scoring better in most math related benchmarks.
Bencharks[^]
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
Yeah, it looks like he commented the unsafe portions, meaning he's back to normal array bounds checking and all that. I wonder why?
|
|
|
|
|
There always will be a loop either in your code, or in code you call.
100K samples will not be processed by a linear sequence of instructions !
You can improve performance by using pointers; this is possible in C# too,
it is considered unsafe, and requires the "unsafe" keyword (and a compiler switch
to enable it).
Look in Visual Studio's help for "unsafe code, sample [C#]"
Luc Pattyn
|
|
|
|
|
One way to speed up things like this on multi-processor or multi-core machines is to use multiple threads to do the processing. Say you have one of those new Intel Quad Core processors, you've got 4 hardware threads available. Split the array into 4 segments, then spawn 3 new threads, each the processes a segment of its own. Then have the current thread process a segment of its own (4 threads total). You've essentially increased performance 4x.
Of course, this solution only works for processors that are hyperthreaded (i.e. 2 hardware threads per physical processor core) or for machines that have multiple processors or multiple cores.
p.s. one should always question optimizing code like this unless you're absolutely, positively certain that there is a performance bottleneck here and the current performance is not acceptable.
|
|
|
|
|
For a job as simple as an inner product, I expect bus bandwidth limitations will
be dominant over CPU limitations, so no much help from multi-threading...
I do fully agree with the p.s. though
Luc Pattyn
|
|
|
|
|
The job is simple, but the bottleneck is the linear time it takes to compute one operation, move onto the next, until finished. Meanwhile, potentially 1 or more cores are idle and could be doing these operations in the meantime. I'm quite certain you'd see a good speed up here.
The MS Robotics team that built the CCR (concurrency and coordination runtime, a .NET library for threading and coordination among threads) found big speedups, often near a multiple of the number of cores in a machine, by utilizing multiple threads to do this kind of thing. Given, they are doing lots of IO, however.
Joe Duffy, a CLR architect, is busy working on the PLinq (Parallel Language Integrated Query) project that will allow devs to easily parallelize queries and transformations on data. This is essentially the technique I described above: using 1 thread per hardware thread to parallelize queries and transformations on data. Eric Sink has an article[^] on his blog showing how C# can do Map, which utilizes this idea.
|
|
|
|
|
Sure, I believe multithreading can be great for any single job that is compute bound
(including Map, the CCR stuff, and much more), as well as for most situations where a multitude of jobs come together.
But my point is multiplying two arrays isnt much more than a data mover.
And I expect the loop overhead will mostly be dealt with by the CPU's out-of-order
capabilities. So lets wait and see.
Luc Pattyn
|
|
|
|
|
There is a library at Microsoft Research called Accelerator that might be worth investigating.
Accelerator provides a high-level data-parallel programming model as a library that is available for all .Net programming languages. The library translates the data-parallel operations on-the-fly to optimized GPU pixel shader code and API calls. Future versions will target multi-core cpus.
Download, Channel9 Video
|
|
|
|
|
Bet you didn't know you would get all this 'feed back' did you
Just remember that no matter what you will still have the loop. So, think of it like this do I have a loop here with a little code or do I have a loop somewhere else with extra code to get there?
Your call, but these guys are giving some real good knowledge that you should diffently try to learn.
Good Luck,
Jason
Programmer: A biological machine designed to convert caffeine into code. * Developer: A person who develops working systems by writing and using software.
[ ^]
|
|
|
|
|
You can multithread the multiplication if the arrays are large enough. Another option is to drop into unsafe code and use pointer arithmetic.
Antoher option is to use 64 bit multiplication but you might need a bitwise transform on the result. (Check out the the assembly for strlen for a non-application example)
I don't know about intel chips but some processors provide op codes for array based operations. Check the MMX instruction set and you may be able to multiply the entire set in two or three op codes.
http://web.cs.wpi.edu/~matt/courses/cs563/talks/powwie/p3/mmx.htm
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
|
|
|
|
|
Hi coders
Just wanted to say thanks for all your many inputs - As expected there seems to be no magic answer to this quistion, but I will take a closer look at using pointers - I did not know this was possible in C# so thanks alot...
AL
|
|
|
|
|
hello every one,
well I was just making a windows form here and it has a column that displays a currency column. SO I know I can change the style of the column to represent a currency but by default it's showing the $ sign while I want it to display the Ruppee symbol like Rs. or something. So can any one of u tell me how to do it. It'd really be v nice u know.
thanks in advance,
Rocky
|
|
|
|