|
Hello,
I wrote some code for using some buttons in my application which depending on the state can be one of the 3 images:
- image_button_mouse_over.png (mouse is over my button)
- image_button_mouse_norma.png (mouse left my button)
- image_button_mouse_clicked.png (button clicked or mouse down)
I used the events (mouse_enter/mouse_leave/mouse_up/mouse_down/mouse_clicked) and depding on that and appropiate image is set to the button. IT WORKS FINE untill.. I click a button which display any window/dialog/whatever, when I do this the button stays after the click in the normal state (LIKE IT SHOULD BE), but when I close the window/dialog it remains in the image_button_mouse_over state even when I put into my code
<br />
button_clicked(object sender,eventargs e)<br />
{<br />
button1.Image=image_button_mouse_norma_handler;<br />
dialog.ShowDialog();<br />
button1.Image=image_button_mouse_norma_handler;<br />
}<br />
I checked and the mouse_leave event is fired, right after the showdialog() is lunched, but It doesnt change anything... Any Ideas ?
|
|
|
|
|
First of all, you really should encapsulate this behaviour, so you can set the bitmaps on button1 ( please tell me it's not called that ), and it will draw itself properly.
Second, perhaps your form needs to redraw itself, what if you call Invalidate() ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I'm guessing here, but could it be that at some point in closing the window/dialog (which was opened by clicking the button) a mouse_enter message is getting set to the button, but since the mouse is not *actually* over the button, it never gets a mouse_leave message?
Have you tried working the GotFocus and LostFocus events into your overall logic?
-- modified at 16:06 Wednesday 4th October, 2006
|
|
|
|
|
i have done a handler for the file system watcher event.
ok, inside it, i wanna move a file (which generated the event) to another location, but when this event is fired the windows system is still copyng (which is worse) or moving the file in question and i can`t perform such task because the file is being used by another process (the windows system).
i have put a Thread.Sleep() in my code to wait for the copy, but it isn`t a cool way to solve this (it`s unpredictable). if i remove the Thread.Sleep() i`ll end up with an exception.
is there another way to solve this?
thanks
here`s the code snippet:
<br />
private void fileSystemWatcher_Created(object sender, System.IO.FileSystemEventArgs e)<br />
{<br />
try<br />
{<br />
if (pedido.CarregarArquivo(e.FullPath))<br />
{<br />
System.Threading.Thread.Sleep(60000);<br />
if (File.Exists(Path.Combine(caminhoDestinoSucesso, e.Name)))<br />
File.Delete(Path.Combine(caminhoDestinoSucesso, e.Name));<br />
File.Move(e.FullPath, Path.Combine(caminhoDestinoSucesso, e.Name));<br />
<br />
}<br />
else<br />
{<br />
System.Threading.Thread.Sleep(60000);<br />
<br />
if (File.Exists(Path.Combine(caminhoDestinoErro, e.Name)))<br />
File.Delete(Path.Combine(caminhoDestinoErro, e.Name));<br />
<br />
File.Move(e.FullPath, Path.Combine(caminhoDestinoErro, e.Name)); <br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
MostrarMensagem(ex.Message, true);<br />
}<br />
}<br />
|
|
|
|
|
I've encountered this problem as well. FileSystemWatchers have some inherent issues with them. This is the probably one of the more annoying ones. The events that fire off of the watcher are not necessarily after the file system has finished with the file. Furthermore, it can send multiple events for a single file copy/etc.
Now, to overcome this issue myself, I've done two things.
1) Wrote a generic class with an internal timer that buffers events. It captures an event and stores off the time of the event, updating duplicate events where necessary. At a set interval, the timer fires on the events that have elapsed a set time to an external body.
2) When accessing the files, I have a while loop that tries to access the file a set number of times. It catches any exceptions that might occur and then sleeps. Rinse and repeat.
I found that most of the issues that would cause exceptions are avoided via the first part of the solution, while the second just handles the lag time between completing the last writes to the file and releasing it. It seems to work out pretty good, if you need the generic class I can pass that on.
As a side tip, I would watchout for FileSystemWatchers because they seem to break down when any two FileSystemWatchers end up watching the same directory (which can easily occur if you include sub-directories).
Good luck.
|
|
|
|
|
hey andrew, thanks for your response...
in the meanwhile i have found a CP article about this issue (check it out at: http://web6.codeproject.com/cs/files/rrfilewatch.asp?df=100&forumid=31158&exp=0&fr=26[^])
but, unfortunally, it didn't sound so simple.
i'll try to master this code, and, if i don't succeed, try your second workaround. BTW, what have you done to access the file and catch the exception?
i think there's not anyway to solve this without using time elapses, after all.
also, if i have caught, your first idea has the same effecta as a Thread.Sleep() statement, doesn't it?
and any code would be appreciated! :]
|
|
|
|
|
That is essentially equivalent to the first part of the solution I was talking about. And yes, they do achieve the same result, but you end up throwing exceptions (which are costly for performance), if you just used Thread.Sleep.
I would add that if you were to have more than one file that you're specifically watching for, it looks like his implementation would produce a timer for each. The code I have derives from the FileSystemWatcher and uses the buffer I was talking about earlier to produce the desired result. But, that code should suffice for the most part. Email me if you would want to see the code I have.
|
|
|
|
|
hey andrew... i have done the following:
bool ok = false;<br />
do<br />
{<br />
try<br />
{<br />
File.Move(e.FullPath, e.FullPath);<br />
ok = true;<br />
}<br />
catch<br />
{<br />
Thread.Sleep(1000); }<br />
} while(!ok);
it`s working, but the program sleeps more than expected.
i can`t figure out exactly why. i have put the code in the event file system watcher event handler, so `e` refers to System.IO.FileSystemEventArgs.
any improvements?
|
|
|
|
|
Well, its because you're moving the file back into its same location and firing the event again I assume from the FileSystemWatcher. Then, because you're doing that within the event handler, it causes it to repeat the process forever.
I would first ask you this:
1) Are you attempting to monitor only one file at most?
2) Will the file be modified across a network potentially?
If the file is being updated across a network, you can quickly get numerous events called due to the fact that the file is written in chunks and each chunk fires off an event.
3) Are you attempting to move the file into another location, which will not produce an event?
The FileSystemWatcher has an internal buffer, which if too many events occur within a set amount of time, it will be overrun. Meaning, you'll lose events that you should have received. The best way to avoid this is to fire off another thread (ThreadPool works great here) to handle the job. If what you're doing is pretty minimal within the event handler or you're not handling too many files at a time, this should not be an issue. But I just wanted to make you aware of that problem.
|
|
|
|
|
I am having a strange problem that I have been unable to solve.
Basically, I am doing a DllImport on an unmanaged DLL that I have written, called "config.dll". This DLL is a bunch of C code compiled under a project in VS2005. This is all in a seperate solution.
When I place the DllImport into my C# project, it works fine as long as the config.dll is located in a different folder than the one the C# project is running from (and the DLLImport statement points to the other folder). I have also tried hardcoding the path of the DllImport statement to the directory of the C# project, either through "c:\\test\\config.dll" or ".\\config.dll", and these both give the same result as just "config.dll".
My failing DllImport:
[DllImport("config.dll", CallingConvention=CallingConvention.Cdecl)]
My working DllImport:
[DllImport("c:\\otherdir\\config.dll", CallingConvention=CallingConvention.Cdecl)]
The exception I get is (xxx.dll is the c# project):
An unhandled exception of type 'System.BadImageFormatException' occurred in xxx.dll
Additional information: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
Any help or things for me to check would be appreciated!
Thanks,
David
|
|
|
|
|
I would guess that the dll has been corrupted, i.e. the hashes of the dll don't match up.
|
|
|
|
|
I found the issue - it wasn't a corrupted DLL - rather the DLL I am importing is dependent on other DLLs and one of those DLLs had the same name as one of the DLLs in my application. When I changed my DLL's name, lo and behold, the problem went away.
Thanks for the idea.
|
|
|
|
|
I'm currently porting an application that I wrote over to GTK#. However I'm having a slight issue in deploying it. I chose GTK# because it is licensed under the LGPL ( http://gtk-sharp.sourceforge.net/ ). However the runtime installer shows both the GPL and the LGPL when I install it. It also installs (but doesn't display at install time) a file containing the MIT license.
Because of this I was wondering if there was a way I can include GTK# with my application in it's own subdirectory. I believe I can do that without violating the LGPL license, but I'm not sure how to go about doing that. If anyone can point me in the right direction I would appreciate it.
|
|
|
|
|
Given an array of objects what would be the C# equivalent of the SQL statement:
"select A,B,C from someTable order by B,C"?
Specifically I have a list of objects and I need to group them by more then 1 property, is there a generic solution to this problem that I can reuse in the future?
Thank You
|
|
|
|
|
Put them into a SortedList<> and make the key the properties you want sorted by.
|
|
|
|
|
Can you please elaborate on this? As far as I know SortedList is key/value(s) only. See example below. The grouped list id like returned by B,C would return obj 0, obj 2, obj 1
obj[] objs
obj[0].A = 1
obj[0].B = 2
obj[0].C = 2
obj[1].A = 3
obj[1].B = 3
obj[1].C = 5
obj[3].A = 3
obj[3].B = 2
obj[3].C = 1
|
|
|
|
|
You can also set the IComparer for a SortedList - so you can write whatever comparer you like.
----------------------------
Be excellent to each other
EasiReports[ ^] My free reporting component for WinForms.
|
|
|
|
|
Thing[] things = manager.GetThings();
private SortedList<string, object> list = new SortedList<string, object>();
foreach ( Thing item in things )
{
list.Add( item.B.ToString()+item.C.ToString(), item);
}
Now when you do your populate, you will end up with the list sorted by the values of B+C as you requested.
Sometimes you just have to think outside the square to see the rectangle.
|
|
|
|
|
I have a Function that returns searched criteria into an array. Every 6 elements of that array is one record for that customer. I am wanting to parse this data into a listView for better reading. So every 6 elements should be one row for that listView. Below i have this and it gets the first element for each record.
string[] dataArray;
dataArray = uni.ReadList();
length = dataArray.Length;
if (length > 0 && length % 6 == 0)
{
for (i = 0; i < length; i += 6)
{
listView1.Items.Add(dataArray[i]);
}
}
What i am having problems with is adding the other 5 elements to the listview in the other 5 colums.
Could someone help me out please?
Thanks in Advance
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
You need following code.
ListViewItem item = listView1.Items.Add(dataArray[i]);
item.SubItems.Add(dataArray[i+1]);
item.SubItems.Add(dataArray[i+2]);
|
|
|
|
|
for (int i = 0; i < length; i += 6)
{
<code>ListViewItem itm = listView1.Items.Add(dataArray[i]);
for (int i2 = i+1; i2 < i+6; i2 ++)
{
itm.SubItems.Add(dataArray[i2]);
}</code>
}
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
I have 4 classes (Class 1-4). Classes 2 and 3 are children of class 1. I need both class 2 and 3 to call on methods from class 4. I've looked at the base method but I can't seem to make it do what I want it to.
I could just make an instance of class 4 in both classes 1 and 2, however I'm trying to avoid it.
Any ideas, or should I just call the two instances of class 4?
Oh, and Class 1 is a static class.
Dave
|
|
|
|
|
Make the instance of class 4 a member of class 1, with protected access, so that class 2 and 3 can access it.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
Muntyness wrote: or should I just call the two instances of class 4?
Not possible to answer definitively without more context, but that is a reasonable approach. Another might be a class 1.2 that encapsulates the use of class 4 and then class 2 and 3 derive from class 1.2 rather than from class 1.
led mike
|
|
|
|
|
Can you put class outline, it will make easy to understand what exactly you want....
|
|
|
|