|
I did the WindowState equal to Maximized and its working. Thanks! I just figured since it wasn't in the code editor that it wouldn't work.
Blake
|
|
|
|
|
Heath is right. The WindowState property from Form is still there but hidden by the override. In this case you don't operate on the PrintPreviewDialog but on the base Form . This code seems to do what you want.
<br />
PrintPreviewDialog ppd = null;<br />
try<br />
{<br />
ppd = new PrintPreviewDialog();<br />
Form wind = ppd as Form;<br />
wind.WindowState = FormWindowState.Maximized;<br />
ppd.ShowDialog();<br />
}<br />
finally<br />
{<br />
if(ppd != null)<br />
ppd.Dispose();<br />
}<br />
|
|
|
|
|
What is the quickest way to determine the maximum value in an array. I have a two dimensional array, let's say, SampleArray[17, 127].
For each of the 17 sub-arrays I want to find the maximum of the 127 samples.
Thanks for your help.
|
|
|
|
|
Either use Array.Sort with the 2nd dimension of each 1st dimension and grab the last element, or enumerate (or iterate) through each one, compare values. If the next value is higher than the current, store the the next value. Either way, continue. Both are O(n) operations but unless your array is already sorted, there is no faster algorithm.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hello again, Heath!
I used the following code...is this acceptable?
for (int i = 0; i < 17; i++)
{
for (ka = PosCtr; ka < 125; ka++)
{
MaxVal = 0;
MaxVal = Math.Max(MaxVal, AutocorrArray[i, ka]);
}
PeakValueArray[i] = MaxVal;
}
|
|
|
|
|
Shouldn't 125 be 127? I'm not sure what PosCtr is either, but you could probably just hardcode 0 to start at the beginning of the sub-array. You also shouldn't reset MaxVal each time. Just do something like this:
for (int i=0; i < 17; i++)
{
int max = 0;
for (int j=0; j < 127; j++)
max = Math.Max(max, arr[i, j]);
peekValues[i] = max;
} If you reset MaxVal (or max in my example), then the value will always be the max because it's greater than 0. This means that AutocorrArray[i, 126] will be the max value whether or not it is.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
PosCtr is just a counter variable that starts at 31. It starts at 31 and not 0 because I'm not looking at the first eighth of an initial record of length 256.
When I tried your approach I had the following problem:
The max values detected are wrong, and the position is either 122, 123 or 124.
When I used my code:
Whenever there was a sequence of negative numbers followed by a series of positive numbers, the max value recorded is 0
What am I doing wrong?
|
|
|
|
|
The whole point of using Math.Max is to compare the current array value with the previous max value. Whichever one is greater gets stored as the max value and compared to the next value, and so on. My code works under normal circumstances, but it might not work for the constraints you have (like your starting indexes, etc.). You must not reset the max each time, though, otherwise you're comparing the current array value with 0, so the last positive number in your array (or subset - whatever you're comparing) will be stored as the max value. You must remember it as I did in my example so you only store the max. If you want to take negative numbers into account, set the max value initially to Int32.MinValue .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i have an app that defines an abstract base class. i have a dll that has a class which inherits from the base class. the app and the dll reside on the same machine. i want to be able to consume the derived class in the dll from my app by class name. so, my app has function that takes an assembly name and class name. i create the derived class and cast it to the base class. how would i do this?
|
|
|
|
|
See Type.GetType and Activator.CreateInstance for one way. There are many ways to do this. Lets say you have something like this:
App.exe:
public abstract BaseClass {...}
Lib.dll
public MyClass1 : BaseClass {...} In App.exe, you can do something like this:
Type t = Type.GetType("MyClass1, lib.dll");
BaseClass bc = (BaseClass)Activator.CreateInstance(t); If the first statement can't find the assembly (i.e., it's not in the same directory, in the GAC, or configured with a private path or binding path in your App.exe.config file), a TypeLoadException is thrown. If the instance can't be created, a number of exceptions might be thrown depending on what the problem is (see the documentation for the Activator.CreateInstance overloaded method in the .NET Framework SDK for more information).
The only problem is that VS.NET won't let you reference a .exe assembly so you will have to compile this on the command line, which isn't hard. Since MyClass1 derives from BaseClass , which is in a .exe assembly, you can't reference it. The compiler doesn't care, it's just that VS.NET won't let you.
Further, you might consider using a configuration file (.config) so that you can change the types or have a plug-in type system. There are many articles here on CP that cover this, and discuss other ways to load and instantiate a Type by name. Try this search: http://www.codeproject.com/info/search.asp?cats=3&cats=5&searchkw=plugins[^].
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for the reply, however, that didn't work. The call to Type t = Type.GetType("MyClass1, lib.dll"); t is null. I had to do this,
Assembly componentAsssembly = Assembly.LoadFrom( "lib.dll" );<br />
Type t = componentAsssembly.GetType( "MyClass1" ); . Then, the call to BaseClass bc = (BaseClass)Activator.CreateInstance(t); throws a ClassCastException saying the specified cast is not allowed. Any ideas?
BTW, how do you get your code samples in those nice yellow boxes??
|
|
|
|
|
Trust me, Type.GetType works so long as the assembly can be resolved. The last bit is important. I've been doing this since 1.0 betas and it is used heavily in our application. Fusion - the assembly binder for the CLR - loads the assembly for a Type if it isn't loaded already because the assembly name is part of the Type.
See How the Runtime Locations Assemblies[^] for more information.
As far as the "yellow" sections, just put your code between <pre></pre> tags.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
godzooky wrote:
Thanks for the reply, however, that didn't work. The call to Type t = Type.GetType("MyClass1, lib.dll"); t is null.
This is because you need to include the namespace within your string value; it is required to resolve the specified class. The following should work:
Type t = Type.GetType("YourNamespace.YourClass, AssemblyName.dll");
if(t != null)
{
}
- Nick Parker My Blog
|
|
|
|
|
I appreciate all this info. However, I still can't get it to work. Is there a setting somewhere that needs to be set to a non-default value? I have test projects that do just the above and do not work. The app and the dll are in the same directory. I can't get Type.GetType() to work correctly, but I can get Assembly.GetType() to work. And, CreateInstance() always throws an invalid cast exception. I must be missing something obvious.
|
|
|
|
|
I have a question. I have created a C# exe project and installed it as a windows service. In the code at runtime I would like to find the path to the service's executable. Does anyone know a property or method that would do this? Your help is greatly appreciated!
Todd
|
|
|
|
|
This will get the path to the currently running executable:
System.Reflection.Assembly.GetAssembly(this.GetType()).Location;
-Tosi
|
|
|
|
|
Thanks alot David, I appreciated it!
Todd
|
|
|
|
|
I want to give design-time support to a property which is a type of custom class. I guess I have to use some design-time attributes, but I couldn't find the correct one. Below is a sample coding.
public class MyClass
{
public int MyInt {...}
public string MyString {...}
}
public class MyComponent : System.ComponentModel.Component
{
public MyClass MyClassProperty
{
get {...}
set {...}
}
}
I'll really appreciate it if someone can help me with this.
Thanks.
UB
You may stop this individual, but you can't stop us all... after all, we're all alike. +++Mentor+++
|
|
|
|
|
What do you want to happen? Like a Size is for a Control.Size property? You should first make MyClass a struct (you're using this more as a seldomly-used value type that is allocated on the stack). You should also add the CatagoryAttribute and DescriptionAttribute . If you want it expandable like the Size property of a Control , you'll need to implement a TypeConverter and use the TypeConverterAttribute . Optionally, use the ImmutableAttribute , although you can emulate the behavior in your derived TypeConverter . All this is documented in the System.ComponentModel namespace, as well as Design-time Attributes for Components[^] and Enhancing Design-time Support[^], both good sections in the .NET Framework SDK.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thank you very much for your help. I thought there's an easier way to do this without using a TypeConverter . I'll look in those sections in the .NET Framework SDK. Thanks for your time
UB
You may stop this individual, but you can't stop us all... after all, we're all alike. +++Mentor+++
|
|
|
|
|
If you create a C# .NET control, will it work with all its functionalities in a Windows 2000 environment or any other environment without the .NET runtime library installed on the system? Is there a way to make it work by adding lines of code?
|
|
|
|
|
If you write something to be used on the .Net runtime, then the .Net runtime must be installed for it to use. Is that a tautology?
Maybe you are asking the wrong question. Why would you want to have a .Net binary run without the .Net runtime environment?
|
|
|
|
|
Well the thing is, I want to build a control that is going to be used in ActiveX containers... I was hoping I could build one using C# instead of writing an ActiveX control... Any thoughts about that particular problem?
|
|
|
|
|
ActiveX is a technology, not a language. You can write one in C++, C#, VB, VB.NET, and many more that are COM compatible. If you write this in .NET, it will require the .NET runtime to be installed, just like Java requires the JRE, C/C++ requires the C/C++ runtime, VB the VB Virtual Machine, etc.
If you don't want to have to install the .NET Framework, then write it in C/C++ and VB, but make sure you include their runtimes (albeit much smaller).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Tom Larsen wrote:
Is that a tautology?
Good word Tom!
- Nick Parker My Blog
|
|
|
|