|
You can't change when the events fire. What you can do is try and open the file that your working with as exclusive, FileShare.None. If the file is already open by another process, such as in your case the file is still being written, the open attempt will fail until the copy process closes the file. You must repeatedly try and open the file until it works. When that happens, you'll know that the file copy is done and you can then do whatever your want with it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi! I´ve been trying to use a flash animation in my windows forms application. So far I have managed to show the animation and play it, but I can't find a way to know when the animation finishes. I have looked everywhere but it seems that there is no "OnStop" or "OnFinish" event. Can anyone help me? I would really appreciate it.
Thanks in advance,
Matias
|
|
|
|
|
Your question actually has nothing to do with C# or even .NET. When you include an ActiveX control on your Windows Forms the VS.NET designer actually creates two interoperability assemblies - one for the ActiveX control(s) and one for their type library (typelib). Whatever interfaces, coclasses, enums, etc. that are exposed to automation get exposed to .NET through an RCW, or Runtime Callable Wrapper.
Basically what I'm saying is that what is exposed to managed code is what is defined for the object. In this case, that object is the Flash player. You'd be better off looking in the developer documentation for Flash or asking in a Flash developer forum. You may find some at http://www.macromedia.com/flash[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
No event of the sort you are looking for is raised by the flash player itself, your best bet is to use an fscommand on the final frame to communicate back to the container (your form) when the animation is complete.
|
|
|
|
|
Hello,
i have 2 tables "products" and "suppliers"
the table products and suppliers has the following columns:
Table "products":
product_id, name, price, product_code, supplier (id of the table suppliers column supplier_id)
data:
product_id name price product_code supplier
151432 Summer Tire 56,33 tire00111 3
151476 Winter Tire 31,63 tire00421 4
Table "suppliers"
supplier_id, name
data:
supplier_id name
3 Michelin
4 Bridgestone
Well my problem is how do i solve this problem: Products is the main table when insert a new product from a new supplier, i need first insert the new supplier into the table suppliers after that i need to retrieve the id from the new supplier for the insertion of the new product in the products table. Can somebody give me a example for this?
thanx!
greetings
Sander
|
|
|
|
|
Use DataTable.NewRow on your Suppliers DataTabe to create a new DataRow . Add the right data to the DataRow 's columns like so:
DataRow row = dataSet1.Tables["Suppliers"].NewRow();
row["supplier_id"] = 1;
row["name"] = "Goodyear";
dataSet1.Tables["Suppliers"].Rows.Add(row); You now already have your supplier ID from above, so repeat the process in a similar fashion to add a record to your "Products" DataTable .
Note that the DataSet is not a replacement for a database, however. If this data is data you need to store, you should keep it in a database and use that database to fill a DataSet using a DataAdapter derivative like the SqlDataAdapter (for SQL Server 2000) via DataAdapter.Fill , and update your database using the DataAdapter.Update method, which contains documentation and examples about how to configure a DataAdapter and use the method in the .NET Framework SDK that is installed with VS.NET by default, can be installed stand-alone, and is available online at http://msdn.microsoft.com/library[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
The supplier_id is auto increment so that is a problem how can i solve this problem?
greetings
Sander
|
|
|
|
|
Don't assign it, then. Once you've added the DataRow to dataSet1.Tables["Suppliers"].Rows then access the row["supplier_id"] and you have your auto-generated number.
You really should read the documentation for the ADO.NET classes. A good place to start and get a high-level overview is Accessing Data with ADO.NET[^] in the .NET Framework SDK. This is installed by default with VS.NET and is available online at http://msdn.microsoft.com/library/[^]. It has many examples and discusses all the classes, methods, properties, and events you need to create your solution.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
i understand but you need also to update the database right? because maybe the id that is generated (by the database) is not corresponding with the ID that the dataset created, because between the insertion and updating the database a new record was inserted by the another application.
And how does the Adapter look like because you can have only one InsertCommand per OleDbDataAdapter
greetings
Sander
|
|
|
|
|
Yes, but you never mentioned you were updating a database as well.
If you use the designer to set up a DataAdapter derivative in VS.NET (or any design designer) or use a command builder (like SqlCommandBuilder you'll notice that the InsertCommand property is comprised of an INSERT statement followed by a SELECT statement. This is to make sure that any auto-generated fields are selected into the DataTable correctly. This is not necessary for UPDATEs because the fields already existed.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I would like the click/doubleclick events in my code to ony be performed when the LEFT mouse button is clicked once and twice respectively.
The event handler for the double click event, for some reason, requires that the RIGHT mouse button to be clicked AFTER the left mouse button is double clicked. What could possibly be the reason?
Also, the EventArgs parameters for the Click/DoubleClick event handlers do not have (e.KeyState = 1) method attached to it or the (e.Button = MouseButton.Left) like the MouseDown event does.
How could I get the Click and DoubleClick events to respond to the LEFT mouse button only in C# code?
|
|
|
|
|
A double-click is defined as the left (or right, on a left-handed mouse configuration) click times 2 within a certain configurable threshold. In order to handle double-clicks you'll need to implement a Timer and use the Click event to determine if there was a double-click. To fire the event, simply call OnDoubleClick form your base class (the default implementation fires the DoubleClick event).
To only fire the Click event for left clicks, you need to override OnMouseDown and then determine which mouse button is down. Store that as a field. In an override to OnClick , only call base.OnClick if the left mouse button was pressed. A click occurs after a mouse button is pressed and released, so at the time the event is fired no mouse is pressed:
private bool leftMouse;
protected override void OnMouseDown(MouseEventArgs e)
{
leftMouse = e.Button == MouseButtons.Left;
base.OnMouseDown(e);
}
protected override void OnClick(EventArgs e)
{
if (leftMouse)
base.OnClick(e);
} There is no need to check the current mouse configuration for the user since Windows will translate right-clicks to left-clicks if the mouse is re-orientied for left-handed users.
Why doesn't the Click event use the MouseEventHandler (which would dictate that the event pass a MouseEventArgs parameter)? Because it's in response to a mouse press and release as I mentioned above. To store this state data when not necessary is very wasteful. Only in rare cases like yours would it be necessary, so the Framework gives you the means to define such state variables.
If ever you need the position of the mouse or the buttons being pressed anywhere in your code, you can use the static Control.MousePosition and Control.MouseButtons properties. Keep in mind that the Control.MousePosition returns screen coordinate (relative to the upper-right of the screen), so you need to convert them to client-coordinates to typically be of any use. To do this, call the instance method Control.PointToClient on whichever Control requires the client-coordinates in regard to its extents.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have a custom control I'm creating that mainly consists of a tab control. When a certain method is called by the main program the control creates a new TabPage and sets it as the active page. The TabPage itself is actually a class that inherits from TabPage rather than the base TabPage and what it is *supposed* to do is automatically create a DataGrid control on the page and bind the grid to a DataTable. The way I've tried to do this is by have a private member in the inherited TabPage class and creating the new DataGrid in the overridden InitLayout method and setting it up there (I set docking to fill). This works fine up to this point. The problem is if I set the databinding in the InitLayout method (I tried OnCreateControl as well) the grid appears and is correctly bound to the correct DataTable but I find a horizontal scroll bar appears halfway up the control that is about half as long as the control itself. If I horizontally resize the containing window or change any of the column widths the scroll bar disappears.
Now the even stranger thing is that if I create a second TabPage it doesn't have this phantom scrollbar, but if I select the first TabPage and create a third page, the scroll bar reappears.
I can avoid the problem by having the main program call another method in the TabPage to bind the data *after* the control has been created, but that rather ruins my encapsulation.
Is this some weird bug?
|
|
|
|
|
Hi
How con I scan a network and list all Computers to a Windows Form??
|
|
|
|
|
Please click "Search comments" at the top of the forum (not the page) and search for something like "list computers". This has been asked and answered more times than I care to count. Knowing how to research problems is an important part of development and the CodeProject site gives you effective tools if you'd just use them.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have been writing a windows app in c# using vs2003. It uses the HansBlomme code for displaying the app in the notification area.
The problem is that when I try to shut down windows (only tested on xp sp2) whilst the app is still running, windows shuts all other applications down but hangs when it gets to mine. Doesnt even bring up a end now dialog, just kind of sits wallowing in its own self-pitty.
Any ideas, anyone else had this problem. Not even sure if it has anything to do with the hansblomme code or not.
Cheers
Mike
|
|
|
|
|
I am not familiar with HansBlomme code but, I would assume you are trapping the WM_QUIT (OnClose..) message and canceling the close. This is how windows shuts down apps. You probably trap this to hide your main window instead of killing the app when the [X] close button is pressed.
I handle this by making my main window hidden. This invisible window is the one that owns the notify icon. On double click (or open), I fire off the main UI window. When the main UI window closes, the hidden window keeps the app alive in the system tray. When windows says to shutdown, the hidden window shuts down.
|
|
|
|
|
I have a .NET DLL, whose class has a Main() method.
I want to create a new process from my application and put the DLL on that process.
I expect the Main() in the class to be treated as the entry point resulting in execution of the DLL.
The intention being that if the DLL crashes or hangs, the parent application is not affected.
Is this feasible? If so, how?
.kausthubh.
|
|
|
|
|
If I understand your question correctly then I don't think it is possible. You want to define your application entry point in a separate assembly. I know the IDE won't let you do it and I believe the command-line compiler will not let you do it either. The problem is that .NET uses delay-load on assemblies so the dll containing the entry point won't be loaded until it is needed (after the application starts). The entry point has to be defined before the application starts. I may be wrong here but I don't see a way of doing it directly. You could possibly do it through MSIL.
In regard to your intentions I don't think it'll give you what you want anyway. You can't "put" a DLL into another process directly. Due to the way dlls are loaded into Windows you can't simply load a dll into a process and then move it to another process. It would be a security hole. Debuggers and profilers get around it by debugging the app. This gives them direct access to the process'es memory. There is also an API to access a process'es memory directly but you have to basically be an admin before it'll work.
Irrelevant of all this if a method throws an exception, inside a dll or otherwise, then the parent application will be affected unless the method or one of its callers catches the exception. Having your entry point in a dll does nothing toward exception handling.
A way to get some of the functionality you want, putting the entry point into a dll, would be to call the entry point within the dll directly in the application main.
For the exception handling you should hook into the unhandled exception framework defined by .NET. For Windows Forms handle Application.ThreadException event. For all apps you can also handle the AppDomain.UnhandledException event. In both cases though you'll have no idea what happened and your program state should be considered to be corrupted.
|
|
|
|
|
Hi experts,
I am going to write a class which protocols error messages into a bug-file.
To identify the files/classes/memberfunctions which fails, I am searching for a (Pre)compiler directive
somthing like #file_name, #class_name, #member_fuction, #row which inserts automaticly the names at it's position.
Is there something like that available ?
Thank you in advance
Frank
fracalifa
|
|
|
|
|
C++'s __FILE__ and other pre-processor directives are handy and fast (since they are executed at compile-time), but you don't have anything like that in C#.You can have some comparable information with the StackTrace class and/or with stack trace information on exceptions.
Be aware that the StackTrace class is not a high-performance class, and can impact your performance seriously if you start logging using it.
Besides, the StackTrace class will only give you line numbers if you send a .PDB file with the file (even on Release builds, you can generate/send a .PDB file).
Yes, even I am blogging now!
|
|
|
|
|
|
whenever i use
setstyle( ... ) ;
and in my paint function i do something like
void paintMethod( .., .. )
{
using( Graphics g = e.Graphics )
{
g.doesSomeDrawing();
}
}
the ... statements replace the actual code wich is corect
i am getting an error message saying "Additional information: Invalid parameter used."
and if i don't use the using statement everything works fine .. no error message !
Lazar Mihai
Elev clasa XI C
Grup Scolar Sanitar
|
|
|
|
|
I suspect it is the using
you are copying an existing Graphics object, not assigning a new one.
Gary
In Scotland, there is no such thing as bad weather - only the wrong clothes. - Billy Connolly
|
|
|
|
|
You can either not use the using statement, safely, or you can try something like this:
Graphics g = e.Graphics;
using ( g )
{
g.doesSomeDrawing();
}
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|