erm i just noticed you set the labels text to "foo" EVERY time. you should change this to e.X.ToString() to set the labels text to the X position of the mouse.
mikone
Posts
-
MDI parent child interaction -
My application stays alive in the process list after closing T-Twhich IDE are you using? vc# 2005 express does start a ApplicationName.vhost.exe when opening the solution and restarts the process if you kill it manually - try to kill it manually and check if it is started again :P
-
MDI parent child interactionsometimes (especially when you have a high cpu load) the controls do not invalidate (redraw, whatever ;)) though you change some of their values. In this case, you will have to use "System.Windows.Forms.Application.DoEvents()" - this static method allows you to let your application do all of the stuff in the queue. I guess this won't be a solution for your problem because the interval between popping up a messagebox and clicking its "ok" button is enough time to get its events done... try to add this statement first - if it does not work add a label1.Invalidate() which causes the label to redraw itself and all its child controls. (you also could invalidate the whole form to make sure everythings updated). I guess this will help but i'm not sure at all. Good luck, mik
-
Populate Table from excel sheet ?You're on the right way ;) With this range you may fill a multidimensional array and put it into a table. Just use the .get_Value() method of the range object to retrieve this array.
string [,] mydata = PrintQuoteRange.get_Value(System.Type.Missing);
Now you have the whole Data in the array. A simple for loop will do the rest ;) Tell me if you keep having trouble with getting the data into a table. I had to do something similar just 2 weeks ago and found this article very useful: How to automate Excel by using Visual C# to fill or to obtain data in a range by using arrays ATTENTION: if you want to set a value of a cell to more than 911 characters, you will get a com exception. To work around this issue just use the querytable instead (have a look at the COM forumpost i made recently) However, good luck with automating Excel ;) (Let me know if you are not able to kill the excel process properly - i just found a nice article to get rid of this too ;)) -
please HELLPPPP...Hi, add this using statement to your code:
using System.Runtime.Serialization.Formatters.Binary;
use this code to read the file:MyClass MyObject = null; BinaryFormatter binReader = new BinaryFormatter(); System.IO.Stream readStream = File.Open("c:\blah.dat", FileMode.Open); MyObject = (MyClass)binReader.Deserialize(readStream); readStream.Close();
and this one to write it:MyClass MyObject = new MyClass(); BinaryFormatter binWriter = new BinaryFormatter(); System.IO.Stream writeStream = File.Open("c:\blah.dat", FileMode.Create); binWriter.Serialize(writeStream, MyObject); writeStream.Close();
and this is the class (or struct) you want to write to a file...[Serializable] public class MyClass { string SomeString = null; int SomeInteger = 0; string AnotherString = null; }
-
executing a PHP file on the webserver [modified]i read the reply and you wrote "i will search for.." but 10 minutes later you already posted the same question again that's why i thought you weren't really searching ;) next time try to search for terms like: - "system.net.webclient msdn" (first and third hit) - "system.net.webclient tutorial" (second hit) if you get no results when searching for these terms you could search for "webclient msdn/tutorial" or whatever. In generally the .net classes are well documented and they often provide examples. if you cant find anything in google search for articles or posts in the messageboard - often people asked the same question and there already exists an answer right next to you ;) keep on learning (as everyone should ;)) - all this stuff will become less complicated!! Good luck, mik
-
executing a PHP file on the webserver [modified]ok you did not google for it as i suggested you to do :) WebClient myclient = new WebClient(); FileStream mystream = myclient.OpenRead("http://yourwebpage.net"); while (mystream.Peek() > -1) { string line = mystream.ReadLine(); } i guess/hope this code retrieves the data of the specified page and reads it line by line until end of file. please try to google for it the next time because there are so many existing pages and explanations about it... i know you even did not try to find something useful about it and thats kinda annoying and makes me not respond to posts like this - thats why if you expect anyone to answer you should follow their advises (or at least try to and tell them why you failed..)
-
question about port scanningHi! I'm not sure about this but you could try to do it like this:
System.Net.Sockets.TcpClient myclient = new System.Net.Sockets.TcpClient(); for (int i = 0; i < 65535; i++) { try { myclient.Connect("localhost", i); // Client was able to connect, hence the specified port 'i' is open... } catch { // An Exception was thrown, hence there was a problem while connecting.. port 'i' closed? } }
This method is obviously not the best because it uses a try..catch statement and it will also throw an exception if a particular port is blocked by another application. To get around this issue you will have to extend the exceptionhandling massively. That's how i would do it but as already mentioned i'm pretty unexperienced... Good luck, mik -
Passive/Active listening serverhehe this is where it gets complicated. i haven't done much with threads at all but i also came across this problem when writing a "popup" class. as you may have noticed you were starting another thread for the listening method. the thread where all the controls remain to is the one where you started the second thread from. sounds complicated but it isn't. now you have to communicate from one thread to another. you can do this by using the invoke procedure of the control. i just will give you the sourcecode and you will see what will happen :) instead of using the regular add method of the listbox you have to use the listboxs "invoke" method. Put this code somewhere inside your class:
private delegate void AddTextInvoker(string textToAdd);
Now replace the line of code where you want to add an item to the listbox with these lines:object [] invokeParams = {"TextOrItemToAdd"}; lbReceived.Invoke(new AddTextInvoker(AddTextToListbox), invokeParams);
finally add the "AddTextToListbox" method to your class and make it add an item to the listbox:private void AddTextToListbox(string textToAdd) { lbReceived.Add(textToAdd); }
but be careful with invoking anything. it happened to me that one thread disposed a control and another one tried to change on of its properties - that will result in an exception. you should try to make yourself more familiar with threads since my knowledge ends here too. maybe someone else could tell you WHY its not possible to do a cross-thread operation and stuff - for now you should be able to solve your problem :P // edit: sorry code snippet did not work because it just was wrong - now it should work :P -- modified at 9:00 Tuesday 10th October, 2006 -
Passive/Active listening serverokay, lets create a simple listening function and the eventhandlers for those buttons :)
// This variable indicates whether the listen method should keep listening or not ;) bool KeepListening = false; // This is the eventhandler for the "Start Listening" button. public void button_StartListen_click(object sender, EventArgs e) { KeepListening = true; System.Threading.Thread myListenThread = new System.Threading.Tread(new System.Threading.ThreadStart(Listen)); myListenThread.Start(); } // This is the eventhandler for the "Stop Listening" button. public void button_StopListen_click(object sender, EventArgs e) { KeepListening = false; } // This is the Listen method. private void Listen() { while (KeepListening) { // Put your "receiving code" in here... System.Threading.Thread.Sleep(10); } }
Okay, thats how it could look like now lets see what exactly happens here. If you click on the "Start Listening" Button, the method button_StartListen_Click is called and: - Sets KeepListening to 'true' - Initiates a new object of the Thread Class and pass one argument in its constructor. - Starts the new Thread. Now the thread is running in the background. The threads task is to call the method "Listen" with no arguments. When doing so the method won't exit until you click the "Stop Listening" button because of the loop. If you click the "Stop Listening" button now the button_StopListen_Click method will: - Sets KeepListening to 'false' Setting the KeepListening variable to false will cause the loop condition (while (KeepListening)) to be not forfilled. This makes the method exit and the thread will do so too! This is no explanation about threading since this is a very complex subject. You should start playing around with them because multithreading is what you want your application to do ;D However, hope you understood what i was talking about - if the code example does not work i will start my ide and create a working example ;) -
TabPage Events do not fire w/ .Net1.1Hi, i don't know when those events are fired (they are not the same as MouseLeave and MouseEnter) but if you want to fire an event when switching/selecting another tabpage you could use the TabControls "TabIndexChanged" event. Make sure you REALLY fire the events. (maybe try mouseenter and mouseleave instead just to make sure that it works at all!)
-
Passive/Active listening serverIn generally you solve this problem by using loops. Make a button "Start listening" which sets a bool variable, lets call it KeepListening, to true and call the listenfunction which contains a loop like while (KeepListening) { // Put Receive-Code in here... System.Threading.Thread.Sleep(10); } Now the second button sets the variable KeepListening to false. If you click it, the application will leave the loop. If you want to make your application listen to incoming traffic and also being available for user inputs, you will have to use threads (create a listening thread). There are nice threading-tutorials out there if you aren't familiar with threading at all. I'm too lazy/busy to search for a nice explanation but i will do if you are not successful. Lets sum it up: - You will have to use a Loop to listen all the time. - You will have to make use of the multithreading if your application should be available for other tasks while listening. Good luck, mik :)
-
How to check version info of an application programatically?I've been googling for retrieving the "standard" product version info of a exe/dll and found a forum post pointing to this article. The third example describes how to retrieve the version info by using the windows api (unsafe code). It's a bit complex but pretty self-explanatory. let me know if you don't get it and good luck so far :) MSDN - C# Unsafe Code Tutorial
-
TextBox Focusthen you should use the keypressed value ;) if there already are 3 characters in the textbox set e.Handled to true and set focus to the next textbox otherwise allow it to write the value :)
-
isnumeric in c#you could youse double.TryParse or int.TryParse - those methods take two arguments. The first one is the value to parse. The second one is the variable to write to (i guess its always passed as 'out' - look at the method header for further information) The method will return true if the value could be parsed successfully.
-
executing an PHP file on the webserver [modified]Hi, i haven't done anything similiar before but i'm sure you can do this with the System.Net.WebClient class. It provides methods like DownloadFile and ReadFile if i remember right. Executing a PHP file isn't anything else than doing a webrequest. You will never see the php script code on a page (unless php does not work properly) - those scripts will be preprocessed. that means it generates an output which will be send to the one who did the request. Hence you just have to "behave" like an internet browser and ask for the files. Since i don't know how to use the webclient class i would suggest you to use google and learn something about it - i'm sure it's the solution for your problem :) Good luck, mik
-
How to check version info of an application programatically?Hi, this depends on the kind of application you want to check. I dont know any other standard than file versioning (for executables and dlls) which would allow to retrieve such information. If you want to check applications installed by windows installer there is a way to retrieve the information by using wmi if i remember right. All together there is no "in-built" class for such things and as far as i know you will have to create your own classes to retrieve these information.
-
TextBox FocusHi, you could do this by binding the textboxes KeyUp-Event. The first argument passed to the eventhandler is the triggering object (in this case the textbox where the user has written in). the code for the eventhandler could look like: TextBox mytxtbox = (TextBox) sender; if (mytxtbox.Text.Length == 3) theNextTextBox.Focus(); if you need further assistance feel free to ask :)
-
Convert VBA to C#hi, just start reading some c# tutorials - you'll be able to convert it very soon but dont expect anyone in here to do the work for you ;D there are several free ebooks available and you also have access to a lot of articles here on codeproject. Good luck, mik
-
Excel.Range.set_Value string length limitation [modified] - solved (kind of...)Hey guys :) My situation: I started playing around with the excel object library in c# and became a bit confused when an error occured while trying to set the value of a specific range. First I wanted to use a 2-dimensional array to fill the sheet with data in one step. But I had to break it down to more little parts (inserting row for row) in order to track down the source of this strange error. When inserting row for row, i noticed some of them being inserted well and others were not. The difference between the rows which were inserted without any error and those who weren't is the length of some strings which consist of more than 911 characters. I already found out that inserting the single value into the cell works fine but as soon as i use an array to fill the sheet, it does not work anymore. Now (and finally ;)) my question: Is there any way to fill a excel sheet with a 2-dimensional array which contains strings longer than 911 chars with the set_Value method of a range object? And if not - do you know any kind of workaround except for truncating the string to 911 chars? Google wasn't very helpful (or i did not search for the right subject) and i just found some fellows having the same problem without any solution... Thanks in advance, mik //edit: I spent some more time in searching for a solution and found the following knowledge base article: You may receive a "Run-time error 1004" error message when you programmatically set a large array string to a range in Excel 2003 I really don't want to believe that this actually is THE workaround - i even think its not a workaround at all. I would be glad to see a real workaround for this problem... //second edit: After googling like i never did before i found a google group post where a nice guy describes how to read a adodb recordset and fill the excel sheet with its data by using a QueryTable object. You also can use this to parse (tab-seperated) textfiles. Here's the link - just check out the MSDN documentation for the different classes if you dont understand something (though QueryTable Class is barely documented...) - Fill a Excelsheet with a QueryTable to work around the 911 character limitation -- modified at 10:44 Monday 9th October, 2006