|
You're not overriding the functionality of the CollectionBase like you're supposed to. See the class documentation itself for an example at the bottom of the page.
-----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-----
|
|
|
|
|
Heath, I went over the CollectionBase documents, but I guess it's just not very clear to me.
I've included some of my code below and it would be great if you could help me out.
**************************************************
// Code for class WaveformSegment.
public class WaveformSegment
{
// First we need an object of class "WavFile" to // read the contents of the file.
// All data is accessed through
// objWaveToSegment.Data[]
public WaveFile objWaveToSegment;
// Now we obtain the filename of the file we chose
private string m_FileOpened;
public string FileOpened
{
set { m_FileOpened = value; }
get { return m_FileOpened; }
}
// This function performs the segmentation
public void ChopIntoSegments()
{
// Obtain access to the data in the .WAV file
objWaveToSegment = new WaveFile( m_FileOpened );
// Read() is a function in another file, that reads the data in a .WAV file
objWaveToSegment.Read( );
// Definition of multidimensional array
// WaveSegments
int[,] WaveSegments = new int[17,256];
for(int i = 0; i < 17; i++)
{
for(int j = 0; j < 256; j++)
{
WaveSegments[i,j] = objWaveToSegment.Data[(i*64) + j];
}
}
// End of ChopIntoSegments()
**************************************************
Now, I want to write a class SegmentCollection. Here is what I've written so far
**************************************************
public class SegmentCollection : System.Collections.CollectionBase
{
public SegmentCollection()
{}
public void Add( WaveformSegment WaveSegments )
{
this.List.Add( WaveSegments );
}
public int IndexOf( WaveformSegment WaveSegments )
{
return this.List.IndexOf( WaveSegments );
}
public virtual WaveformSegment this [int Index]
{
get
{
return (WaveformSegment)this.List[Index];
}
}
**************************************************
Is this right so far, and how do I access each individual segment?
Thank you.
|
|
|
|
|
I want to display and print excel and pdf in winform ,how to do ? thx.;)
Xpelive
|
|
|
|
|
For the simple drag-n-drop method which generates the RCWs (COM interop assemblies) is to custom your toolbox. Open your toolbox (contains the design objects like a Label or a Button), right-click and select "Customize Toolbox" or "Add/Remove Items" (depending on version of VS.NET). Find the "Adobe Acrobat Control for ActiveX" and "Microsoft Office Spreadsheet Version", where Version is 9.0 or higher (introduces the Office Web Components, or OWC).
If you want to host an actual Excel Spreadsheet like Excel does, you'll either have to dig deep in Active Document Containers and implement several redefined COM interfaces in a class to contain the Active Document (which describes Word docs, Excel sheets, and many other formats), or wait for .NET 2.0 which introduces the ActiveDocumentContainer which already does this, but you'll still have to worry about hosting the toolbar (at least for now in the alpha stages). This can be difficult as well. The OWC edition of Excel already has the toolbar built-in and contains custom design commands.
For the Acrobat control, you can specify a src for the PDF document, either at design-time or at runtime.
-----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-----
|
|
|
|
|
First,thank you for your help.
I wanna know how to use "Microsoft Office Spreadsheet" to open a exist excel file and print it. Is there code sample ?
thanks.
Xpelive
|
|
|
|
|
You actually don't need to embed the Excel control to do this: there's two very simple ways of doing. The easiest is to do something like this:
ProcessStartInfo psi = new ProcessStartInfo();
psi.UseShellExecute = true;
psi.FileName = "C:\path\to\spreadsheet.xls";
psi.Verb = "print";
Process.Start(psi); You can further hide the application window by setting psi.WindowStyle = ProcessWindowStyle.Hidden .
You can also reference the Microsoft.Office.Excel primary interop assembly (you can generate them yourself, but it's better to use the official ones from http://msdn.microsoft.com/library/en-us/dnoxpta/html/odc_oxppias.asp[^]) and print the spreadsheet. This uses an out-of-process automation server (Excel.Application) to load and print the document:
Microsoft.Office.Interop.Excel.Application excel =
new ApplicationClass();
Workbook wb = excel.Workbooks.Open(this.filename, 0, false, 5,
"", "", false, XlPlatform.xlWindows, "", true, false, 0, true,
false, false);
object missing = Missing.Value;
wb.PrintOut(missing, missing, missing, missing, missing, missing,
missing, missing);
excel.Quit();
-----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-----
|
|
|
|
|
I also want to PrintPreview the excel, I use Microsoft web browser control as a container.the code:
private AxSHDocVw.AxWebBrowser WB;
...
string strFileName = @"file:///E:/Sample.xls";
Object refmissing = System.Reflection.Missing.Value;
WB.Navigate(strFileName, ref refmissing , ref refmissing , ref refmissing , ref refmissing);
private void WB_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
{
Object o = e.pDisp;
Object oDocument = o.GetType().InvokeMember("Document",BindingFlags.GetProperty,null,o,null);
Object oApplication = o.GetType().InvokeMember("Application",BindingFlags.GetProperty,null,oDocument,null);
Excel.Application eApp =(Excel.Application)oApplication;
_Workbook workbook = eApp.Workbooks.get_Item( 1 );
object missing = Missing.Value;
workbook.PrintPreview( missing );
}
when running "workbook.PrintPreview( missing );" it raise an
error "HRESULT Error: 0x800A03EC"
What happen and how to solve it ?
Thanks for your help.
Xpelive
|
|
|
|
|
Microsoft developed an activex container. It's free, but there is no support for it. With the activex you can host any Office document inside a WinForm. Just install it and add it to the VS.NET toolbox.
MSDN[^]
Currently I'm using it and it works great.
Free your mind...
|
|
|
|
|
Hello how do you have a blue button in the property's page that links to a function in your component (eg: The blue button that says 'Generate Dataset' on the DataAdapter object)
TIA
Obe
------------------
I'm naked under my clothes...
|
|
|
|
|
There are no "functions" in .NET - only methods (procedures on an entity such as a class or struct).
The button can easily be blue by setting Button.BackColor (inheritted from Control ) to Color.Blue . In order to execute a method on another object elsewhere, you'll have to pass an instance of that object to the property page. You could also expose an instance of this object as a static property of another class, but this is not recommended. Mixing statics and instances is like mixing cats and dogs (maybe not as violent, but they just don't belong together).
For instance, lets say that this property page is bound to certain objects in a class that encapsulates the logic for generating your DataSet . Pass that entire object to the constructor for the property page (or a property or something). Bind the properties and when the button is clicked, you already have an instance of the aforementioned class so just call the instance method. Just try to encapsulate your logic into distinct units and passing references to them when possible.
-----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-----
|
|
|
|
|
Err...Heath...I think he was talking about the PropertyGrid control. When you have certain classes selected, there's this little section added to the bottom of it with links. His particular example was the DataAdapter class. If you drag one onto your form, and then click on it in the components tray, and view its properties, then you'll see links at the bottom like "Configure Data Adapter" or "Generate DataSet".
youd ebtter bnot be taki8ng agvantage o f my mental abilites!1
-David Wulff one night over MSN while totally plastered
|
|
|
|
|
In that case, derive from the appropriate ComponentDesigner and override the Verbs property to return a collection of DesignerVerb objects (see documentation in .NET Framework SDK for more information about these classes - it's really pretty straight-forward).
Finally, attribute your component with the DesignerAttribute attribute, passing the Type of your designer from above to the constructor of the attribute.
For more information, see Enhancing Design-Time Support[^] in the .NET Framework.
Sorry for the confusion - it's late.
-----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-----
|
|
|
|
|
I have a form with a few controls on it. The controls cover the whole area of the form.
I have a function that is executed when clicking on a treeview.
This function takes a few seconds to execute, where it talks to a database and does some painting in one of the controls.
At the top of that function I call
Cursor.Current = Cursors.WaitCursor;
and at the end iI call
Cursor.Current = Cursors.Default;
But... The cursor only blinks with the hourglass, then its back to normal, while the computer is working...
[edit]
Do I really have to loop through all the components in the form, setting the cursor on each one?
Naaa, I hope not...
[/edit]
Any ideas?
- Anders
Money talks, but all mine ever says is "Goodbye!"
My Photos[^]
|
|
|
|
|
If you execute the statement to fill the tree in a separate thread, the current cursor will be set to the default immediately since the method you called executes in another thread. If you call Application.DoEvents in your code before wanting the default cursor to be reset, if will be set to Cursors.Default , so don't call Application.DoEvents , either.
Finally, make sure you have something like the following: it's all too often that wait cursors are left showing when a process has finished in err:
Cursor current = Cursor.Current;
try
{
Cursor.Current = Cursors.WaitCursor;
}
finally
{
Cursor.Current = current;
} Optionally, you can forget about storing the current cursor (for instance, if you know your method is in the only thread of execution running, such as the main UI thread) and just use Cursors.Default .
But you don't have to set this on every control. Cursor.Current set the wait cursor and stops processing mouse events for the entire application. Only Control.Cursor sets the desired cursor for just that control.
-----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-----
|
|
|
|
|
I'm not filling the treeview, I'm using the treeview selection to fetch data from a database, and show a lot of photo thumbnails in another control using GDI+.
I tried something fun. At the top of the function I sat the treeview cursor to an hourglass, and never sat it back to normal, I also removed the calls to Cursor.Current.
When I move my mouse over the treeview i get an hourglass as expected (the function have executed when the app loaded), but when I change the selection, I get the arrow cursor when processing and the hourglass when finished working.
This really don't make any sense to me, and I really think it sucks that when I set cursor.current, the system just sets it back to default when the thread is going idle (like waiting for a database or the filesystem). At least it looks that way to me.
Mmmm, sometime I whish I had done this app in C++ and Win32 instead, at least I did not have those stupid problems there
It took somewhat more time to make GUI stuff, but not all those stupid problems...
- Anders
Money talks, but all mine ever says is "Goodbye!"
My Photos[^]
|
|
|
|
|
The application can't be idle if the UI thread is currently executing code, such as "waiting" for database results or reading a file. An idle state of an application indicates that the STA on which the application was started is not currently processing. So, something else is reseting your cursor. The only other way to process queued notification messages on the UI thread is to call Application.DoEvents as I mentioned above.
If you want the cursor to be the WaitCursor for the whole app, make sure you use Cursor.Current and not the Cursor property of the control. Since the control also contains a Cursor property, use System.Windows.Forms.Cursor to specify the class just to be sure.
As far as this vs. Win32, all this wraps the functions defined in the Win32 APIs. Much - it not most - of the Framework does encapsulate the Win32 APIs.
-----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-----
|
|
|
|
|
Heath Stewart wrote:
The application can't be idle if the UI thread is currently executing code, such as "waiting" for database results or reading a file.
A thread get idle when waiting for a database ot reading a file. It have always been that way, trust me
And... I don't call Application.DoEvents() anywhere what so ever in my application, but the cursur still automatically changes to an arrow.
Heath Stewart wrote:
If you want the cursor to be the WaitCursor for the whole app, make sure you use Cursor.Current and not the Cursor property of the control.
Yes, I do know that, I just dont think you know why I wrote as I did
It was just for testing, you know, and I found it funny that when the application was processing stuff, it changed the hurglass cursor to an arrow.
Thanks for your attempt to help but I guess you dont know whats happening, no more than I do...
It's probably just another quirck of the .NET framework.
Heath Stewart wrote:
As far as this vs. Win32, all this wraps the functions defined in the Win32 APIs. Much - it not most - of the Framework does encapsulate the Win32 APIs.
Yes, but have you ever used the Win32 API with C++?
So much more control.
- Anders
Money talks, but all mine ever says is "Goodbye!"
My Photos[^]
|
|
|
|
|
Our application makes an extraordinary amount of database calls, even through remoting and never goes idle, hence we never have a problem with the wait cursor resetting. These calls are typically made in the STA thread. The only time I have had problems with the wait cursor resetting is when I make asynchronous calls.
Anders Molin wrote:
Yes, but have you ever used the Win32 API with C++?
Since Windows 3.1. Still do, although most development is in a couple .NET languages, mostly C#.
-----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-----
|
|
|
|
|
A thread that waits for something is idle, and the cpu does other things in the mean time
Well, I think we think of "idle" as different things...
- Anders
Money talks, but all mine ever says is "Goodbye!"
My Photos[^]
|
|
|
|
|
Heath,
I'm sure you know this, but it's good to show everyone the preferred way to work with Wait Cursors in C#:
using (Cursor.Current = Cursors.WaitCursor)
{
}
Regards,
Alvaro
"I do" is both the shortest and the longest sentence in the English language.
|
|
|
|
|
Hello fellow code poets,
I am attempting to sign an assenbly with a strong name the VS.NET way using the KeyFileAttribute in the AssemblyInfo.cs file.
I have read over MS documentation in the Framework SDK, Knowledgebase and the commented instructions in the AssemblyInfo.cs.
And of course all three sources show you something a little different.
This is the basics of my error:
http://support.microsoft.com/default.aspx?scid=kb;en-us;328379&Product=sql2k
I have tried to use these three examples I was given and they have all failed.
[assembly: AssemblyKeyFile(@"..\\..\\tempKey.snk")]
[assembly:AssemblyKeyFileAttribute("tempKey.snk")]
[assembly: AssemblyKeyFile("..\\..\\tempKey.snk")]
I have placed the key in the project directory, Visual Studio Projects/Project directory and in the bin and I am still failing it seems to get the right location.
Can any one help?
Thanks.
Jarrad D.
|
|
|
|
|
Make sure you have generated a key and put it in the projects directory using
sn.exe -k KeyFile.snk Keep this file safe and do not share it.
Also, when using the literal specifier "@", do not escape your backslashes like you are in the first example. The location of the file is relative to the build path. VS.NET builds everything relative to bin\(Debug|Release) by default, so your first and third examples are correct (assuming the key pair file is generated correctly). The third will not work unless building your project from the project directory (possible using the csc.exe command-line compiler).
Just as a side note, it doesn't matter where you put assembly attributes, so long as they're part of a source file being compiled into your assembly.
-----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 help Heath.
The tempKey.snk is my key and I have tried all my examples having put my key in the bin\ it still will not compile without the errror.
Any other ideas?
Thanks.
Jarrad
|
|
|
|
|
The bigger question was about how it was generated. Did you use "sn.exe -k filename"? It has to contain at least the private key. "-k" will generate a key pair, which contains the public and private key.
Also, what exactly is the exception you're getting? Specifics are always more helpful.
-----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-----
|
|
|
|
|
In my first post I linked to a MS KB article that contains the compile error I am receiving.
"Cryptographic failure while signing assembly '...\WindowsApplication1.exe' -'Error reading key file 'key.snk' -- The system cannot find the file specified."
I did use the -k when creating my key.
Thanks again.
Jarrad
|
|
|
|
|