|
You could try using:
<br />
this.Invalidate();<br />
Call this after everything else has been drawn. The invalidate method causes the control to repaint itself. You may need to remove the handler that you gave in your post. I think this should work, but I can't be sure.
Later,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
Hello everyone,
I have been sifting through code project to find an answer to my question and I came up with with an article about how to make calls to the windows API with C# but it didn't quite answer my problem. How would I make a call to the Window API to change the screen resolution? What would be the call to play sound files (From what I've seen .NET doesnt have any functions to play sound files)?
|
|
|
|
|
You would use a call to ChangeDisplaySettings.
This might help:
class Win
{
internal const int ENUM_CURRENT_SETTINGS = -1;
internal const uint DM_BITSPERPEL = 0x00040000;
internal const uint DM_PELSWIDTH = 0x00080000;
internal const uint DM_PELSHEIGHT = 0x00100000;
internal const uint DM_DISPLAYFREQUENCY = 0x00400000;
internal const int CDS_UPDATEREGISTRY = 0x00000001;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
internal class DEVMODE
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
internal string dmDeviceName;
internal ushort dmSpecVersion;
internal ushort dmDriverVersion;
internal ushort dmSize;
internal ushort dmDriverExtra;
internal uint dmFields;
internal short dmOrientation;
internal short dmPaperSize;
internal short dmPaperLength;
internal short dmPaperWidth;
internal short dmScale;
internal short dmCopies;
internal short dmDefaultSource;
internal short dmPrintQuality;
internal short dmColor;
internal short dmDuplex;
internal short dmYResolution;
internal short dmTTOption;
internal short dmCollate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
internal string dmFormName;
internal ushort dmLogPixels;
internal uint dmBitsPerPel;
internal uint dmPelsWidth;
internal uint dmPelsHeight;
internal uint dmDisplayFlags;
internal uint dmDisplayFrequency;
internal uint dmICMMethod;
internal uint dmICMIntent;
internal uint dmMediaType;
internal uint dmDitherType;
internal uint dmReserved1;
internal uint dmReserved2;
internal uint dmPanningWidth;
internal uint dmPanningHeight;
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern int EnumDisplaySettings(string lpszDeviceName, int iModeNum, [In, Out] DEVMODE lpDevMode);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern int ChangeDisplaySettings(DEVMODE lpDevMode, int dwFlags);
}
|
|
|
|
|
Thank you
|
|
|
|
|
Defeats the portability of the application?
Normski. - the next bit of code is self modifying ... jmp 0xCODE
|
|
|
|
|
I have 10 different assembilies, I want to put it in One Library file or one assembly, cause I don't want to add references upto 10 times everytime for my different screen. Is anybody know how to do that.
Thanks in advance
|
|
|
|
|
Try putting them all in one project.
|
|
|
|
|
I have to use xml transformation.
The simplest way is
<br />
XslTransform xsltransform = new XslTransform();<br />
xsltransform.Load("favorite.xsl");<br />
xsltransform.Transform("MyDocument.xml", "TransformResult.xml");<br />
But it is necessery for me to put output of transformation not to file but to string... (all of overloaded members of Transform has file or stream)
Do you have any idea?
|
|
|
|
|
tomiga wrote:
(all of overloaded members of Transform has file or stream)
You could create a memory stream to house the output of the transformation; then once the transformation is done convert the underlying byte array to a string.
System.Text.(Encoding).GetString(myByteArray) if the XML file uses ASCII then (Encoding) should be ASCIIEncoding; if it uses UTF8 then it should be UTF8Encoding; etc...
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Thx. I have found stream witch writes output to string. StringWriter class. It helps me to solve problem.
|
|
|
|
|
Is there any way I can pass something back from a function so that it can be a string, or a number, or some other value, like a variant in COM ? I don't want to pass an object, because it's too much work for my client to try and figure out what it is. Is that my only option, apart from GetNodeInt/GetNodeString/etc. ?
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
One option other than an object that I can think of is to use very inspecific variables. So if you know that you're going to pass either a byte, an int, or a long, use the long.
You could also try converting everything to and from a string, but that might be more work than the object.
A third option is to pass a type variable. That way you can create a switch for all of the types that might be returned.
Hope this helps
|
|
|
|
|
SHaroz wrote:
A third option is to pass a type variable. That way you can create a switch for all of the types that might be returned.
That sounds very promising - could you tell me more ?
Thanks
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
I'm not entirely sure if this is more efficient than just passing an object or if I'm even implementing this correctly. You should try timing how long it takes this to be done 1000 times vs. just passing the object. Anyway, I hope this helps:
private object ASDF(ref System.Type T)
{
Boolean myVar;
T = myVar.GetType();
return myVar;
}
private void myTestFunction()
{
System.Type X;
Object temp = ASDF(X);
switch (X)
{
case Int:
Int myInt = (Int)X;
break;
case Boolean:
Boolean myBool = (Boolean)X;
break;
//...
case Object:
//it is an object
break;
}
}
|
|
|
|
|
C# .NET question
My first and main question is: Can C# produce native executables, that would run on any Windows
platoform without the .NET binaries? Just like C++? Or it only compiles to bytecode like Java?
(it doesn't matter how MS calls it?)
Do you think that C# is good for Graphics Applications? (I mean is it fast enough)
I would like to try .NET SDK and online documentation before I move to VS .NET. Do you know
about any online books on C# (beside C# Language Specification and Thinking in C#)?
I think a FAQ on C# would answer this question but so far I couldn't find any with the anwsers I
want.
Any help is appreciated. Thank you,
Z.
|
|
|
|
|
Zimbar wrote:
My first and main question is: Can C# produce native executables, that would run on any Windows
platoform without the .NET binaries? Just like C++? Or it only compiles to bytecode like Java?
no, c# does not compile to a win32 executable.
Zimbar wrote:
Do you think that C# is good for Graphics Applications? (I mean is it fast enough)
except for very extreme examples ( like maybe a game engine or something ), c# will be fast enough.
|
|
|
|
|
Zimbar wrote:
My first and main question is: Can C# produce native executables, that would run on any Windows platoform without the .NET binaries?
No, the C# compiler only compiles down to MSIL bytecode.
Zimbar wrote:
Do you think that C# is good for Graphics Applications? (I mean is it fast enough)
Probably not; but you could always try it to see.
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Zimbar wrote:
++? Or it only compiles to bytecode like Java?
That is sort of right. But yes, you need the runtime.
Zimbar wrote:
Do you think that C# is good for Graphics Applications? (I mean is it fast enough)
No. My graphics filters were benchmarked by Chris L. and the same code in C++ was 25 times the speed. I wrote mine in C# only because I needed to, to differentiate them from some I wrote in C++ for a former employer.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
25x?
That seems surprising. Care to share a bit of code (both in C++ and in C#)?
|
|
|
|
|
My C# code is here on the site - I did not think the speed was too bad ( but I maintain C# is the wrong tool, mostly because Microsoft in their wisdom have made pixel access 'unsafe' ), but Chris Losinger has posted the question based on conversion to C++ that he did.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Two questions:
1) Was the code written using GetPixel and SetPixel()?
2) What other option was there besides making pixel access unsafe? I don't like it either, but I can't see how you can be fast without being pointer-based.
|
|
|
|
|
Anonymous wrote:
Was the code written using GetPixel and SetPixel()?
Mine was not, that would not be unsafe. I assume Chris' was not either - he writes an imaging library, you know.
Anonymous wrote:
What other option was there besides making pixel access unsafe? I don't like it either, but I can't see how you can be fast without being pointer-based.
The obvious option is a function that returns the bitmap as a 2D array. How do you think every array in memory is laid out ? There is no reason to regard it as unsafe to access the member data of the Bitmap class.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Sorry that the last one came across as anonymous. Not sure why...
Christian Graus wrote:
The obvious option is a function that returns the bitmap as a 2D array. How do you think every array in memory is laid out ? There is no reason to regard it as unsafe to access the member data of the Bitmap class.
Hmm. Did the C++ version use pointer arithmetic, or did it use array indexing? I agree that you can return a 2D array, but I don't that would help much in this case because:
1) multidimensional access in C# is a bit slower than single dimensional
2) Array indexing is slower than pointer arithmetic
3) The .NET classes are a thin layer on top of the unmanaged GDI+ functions. If you can't change that, then you'd have to copy from the unmanaged world to the managed world and back, which would be really slow.
#3 is a design decision which I hope can be addressed in the future. I'm not sure what we'd do to address the others.
Thanks for the info; I'll take a look at the code.
|
|
|
|
|
Eric Gunnerson (msft) wrote:
Did the C++ version use pointer arithmetic, or did it use array indexing?
Pointers, for speed. I appreciate all that you are saying, my point is more that C# should be able to access the bitmap data in one call, instead of using get/setpixel which is notoriously slow, and without having to write code that will be marked 'unsafe'. Ideally, I guess that means GDI+ should provide another call, or C# should sandbox the GetData call and return the data. This will be slower, of course, but I would not mind that if I had the option to go unsafe, but could do pixel access in some way that was as optimised as I could hope for without marking my code as unsafe.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
I looked at the code, and it pretty much looks like my code.
Is there anyplace I can look at the equivalent C++ code that Chris timed?
|
|
|
|