|
I think it is safer to start a new thread in that event and do lock and unluck for that string that you process it,cause even each handler run on seprate thread if you have some public variable that changed there it will cause problem or uncorrect data. I hope I was clear.
Mazy
No sig. available now.
|
|
|
|
|
No, I'm sorry, I really didn't get what you meant. May you please illustrate with code?
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
uhmm,let me explain . Imagine you have a public variable named a. You have two thread than wants to change this value, then what will happend? I'm not sure in the situation that you register one method as an event handler for two control this will happend too.It is called Thread Synchronization . You can see this article to understand more and search CP for other information about threading for more info and samples:
http://www.codeproject.com/csharp/eventsthreadsync.asp[^]
Mazy
No sig. available now.
|
|
|
|
|
Mazdak's idea may work, but another way is to use the lock keyword (or handle synchronization yourself) against an instantiate object (nothing special, you could even lock against the Type):
private void InternetExplorer_DocumentComplete(...)
{
lock (this.GetType())
{
}
} And, yes, Navigate2 is an asynchronous call, hence the need for a DownloadComplete event (as well as other similar events for each element and the document while being parsed).
-----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 Mazdak.
Heath Stewart wrote:
lock (this.GetType())
Why the .GetType()? Shouldn't I obtain a lock against the event sender (of type InternetExplorer)?
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
You have to lock against the same object (for example, the Type of the current object will always be the same) otherwise the lock doesn't make a difference. Take a look at the System.Threading namespace, specifically the Monitor class (which the lock keyword compiles down to like the following):
Monitor.Enter(syncRoot);
try
{
}
finally
{
Monitor.Exit(syncRoot);
} If the object called syncRoot is different for every call, the monitor will lock against different objects and will not block pending requests to enter the synchronized section.
There are two things you should take into consideration when choosing an object to lock. If you want a method (especially a static method) to be synchronized, lock against a static object (such as the Type, which is recommended, but you can use a static object reference as well). If you want methods to be synchronized only for a given instance, lock against an object member of the instance of your class.
-----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-----
|
|
|
|
|
This might take a few words to explain, so please bear with me if you will:
I'm chopping the data of a .WAV file into segments each of length 256 samples. After this segmentation is done, let's say I have N segments. My N by M multidimensional array is called WaveSegments[N,M].
Now, I want to display each of these segments in a UserControl I've made, and want to cycle through the segments by means of an up/down control.
So, for example, clicking once on the up control would change the number from 1 to 2, and the display would change from the samples of WaveSegment[1] to WaveSegment[2].
It seems that using collections would ease coding tremendously, but I seem to be running into any number of syntactical problems.
Could somebody please demonstrate to me how I could do this?
Thank you.
|
|
|
|
|
Actually, using any kind of IEnumerable or IListSource would be great. You can data-bind the collection to the up/down control and use the CurrencyManager.Position property to adjust the position. For more information about data-binding properties and data sources, see Control.BindingContext and CurrencyManager . This would save you from the mess of handling all this yourself. When used correctly, other controls bound to the data source are updated when the position of the current element in the data source is changed.
At any rate, what are the "syntactical" problems? For ease, extend CollectionBase and override the methods (or implement new methods with strongly-typed params that call the CollectionBase 's methods) and most of the rest of the work is already done (which uses an ArrayList to back the elements).
-----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, thanks a lot for your post.
I'm new to programming, and started with C# as that's the language of choice at my company.
Could you give me a code snippet showing how to implement this?
Thanks!
|
|
|
|
|
No need - see the documentation for the CollectionBase class in the .NET Framework SDK (just type "CollectionBase" (without quotes) in the Index) and you'll see an example. Be sure to read the documentation - if not skim it over to see what's available in the base class library - especially when starting out.
-----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 Heath,
Will get back to you if I run into problems.
|
|
|
|
|
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; }
}
// We now formulate a method to extract the information we need
public void ChopIntoSegments()
{
// Obtain access to the data in the .WAV file
objWaveToSegment = new WaveFile( m_FileOpened );
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()
|
|
|
|
|
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[^]
|
|
|
|
|