|
Dont't worry, it's not a big think.
- Create a TextBox with Multilne=true and Scrollbar eg.: called it log
- tahan when you want something to write to the textbox just write:
log.Text+="something";
- if you want to write a newline
log.Text+="\r\n";
If ou want to write the log to file (eg.: from the textbox):
<br />
System.IO.StreamWriter sw=new System.IO.StreamWriter("c:\\logfile.txt");<br />
foreach(string line in log.Text.Split("\r\n".ToCharArray()))<br />
{<br />
if(line.Trim().Length>0)<br />
{<br />
sw.WriteLine(line);<br />
}<br />
}<br />
sw.Close();<br />
|
|
|
|
|
I thought it would be easy, and that's great, thanks!
|
|
|
|
|
Hi,
I've written a windows service to parse files.It uses the FileSystemWatcher class in C# to sniff a folder for particular type of files. But when the files were being processed, i repeatedly get the error "The process cannot access the file "AAA" because it is being used by another process". To overcome this problem, i added the following. lines of code
public bool ParseEnvFile(string strFilePath)
{
try
{
using(FileStream fs = new FileStream(strFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
fs.Close();
m_nReadAttempts = 0;
}
}
catch(IOException ex)
{
if(m_nReadAttempts < 3)
{
Thread.Sleep(2000);
m_nReadAttempts++;
return ParseEnvFile(strFilePath);
}
else
{
throw ex;
}
}
.....
}
But even this did not solve the problem. The exception still kept coming, though less frequently.
So I was forced to add a Timer event(runs every 5 mins) that would pick up all the files that were left over because of the exception.
Now, my problem is this:
When a file gets created in the folder, sometimes both the OnFileCreated event and the timer event try to access the file at the same time. Within my
service, I'm required to open the file in write mode and update some contents. I find that at times the file that gets created ends up as a 0KB file (Note: when it initially got created the file had some content in it)!!!!
Any ideas on how to solve it?
Thanks for any help in resolving this problem.
|
|
|
|
|
Hi!
Perhaps you should check _which_ other program is accessing your files.
I've had a similar problem and it turned out that a virus scanner was the culprid.
One other thing: Do you really want to have recursion in your code? I'd say a do/while loop would be clearer, but that's just my opinion...
Regards,
mav
|
|
|
|
|
Hi mav..
Thanks for your reply. When i tried to debug the program when i first faced this problem I found that the FileSystemWatcher was only holding the file So when i tried google it, many others had also said the same. That is why the wait logic was introduced.
Yes i can do away with the recursion logic.
Regards,
G3
|
|
|
|
|
Example read the valure from first colmun, and build a conditional query with it.
|
|
|
|
|
I have no problem writing a winforms application and running it inside Internet Explorer using the <object> tag.
But how do I make the same app run inside Firefox?
// Per
|
|
|
|
|
Hi all
On my Windows application form I have a TreeView on the left and a number of textboxes on the right. The Treeview shows a list of users and the textboxes are for editing or adding new users. When I click on a user in the TreeView, the textbox fields are populated with the selected user's details. After I click the save button the TreeView is being reloaded to reflect the changed details of the user. How can I select that specific node in the TreeView programmatically so that it still shows that user as being selected?
Help on this or any suggestions on a better method would be appreciated.
Thank you.
kobus
|
|
|
|
|
set the SelectedNode property of your treeview
|
|
|
|
|
You could save treeView.SelectedNode before reloading the tree and then set it back after reloading is done.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi
Is it possible to disable selection of text inside a Textbox when the textbox is in enabled mode. All comments welcome......
Regards
Deepak.S
|
|
|
|
|
|
Nope i want to do that in windows forms....
|
|
|
|
|
Sample code - Would be to trap mouseup and Keydown events and check for selectedText property
private void textBox1_MouseUp(object sender, MouseEventArgs e)
{
//this.Text = textBox1.SelectedText.ToString();
if (textBox1.SelectedText.Trim().Length != 0)
{
textBox1.SelectionLength = 0;
}
}
Dont forget to add in code for Keydown and copy+Paste in Textbox stuff.
|
|
|
|
|
I changed registry [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\WinLogon\Shell] and let it point to my App in order to show a authority dialog ,if IDCheck finished,i should run Explorer.exe to show user the desktop and taskbar...
BUT when i called explorer.exe in the app, it only show "My Document" Windows ,not the desktop and the taskbar?what is wrong??
private On_AppExit()
{
Process tmpExplorerProcess=new Process();
tmpExplorerProcess.StartInfo.FileName="c:\\WINNT\\Explorer.exe";
tmpExplorerProcess.Start();
Application.Exit();
}
|
|
|
|
|
What exactly are you trying to do?
|
|
|
|
|
hi Nick:
When windows start, after the windows Authority,I want to run an App before run Explorer.exe ,so I should run Explorer.exe in my own App ,but it doesn't work correctly, how to do?
Sequence: Windows start--->Windows logon Dialog--->MyApp-->Explorer.exe
Nomral: Windows start--->Windows logon Dialog--->Explorer.exe
can you give me an example?
thanx lot!!
|
|
|
|
|
If you run regedit, and searc explorer.exe you can see, explorer exe wait paraeters example:
explorer.exe %1
so you can find out, what is the start parameter as I think
|
|
|
|
|
hi friends:
thanx for give me this advise
can u tell me the Regpath point to "Explorer.exe"
because I only find it on [HKEY_LOCAL_MACHINE\...\WINLONON]="Explorer.exe"
I can not find the parameter,where is the Key?
|
|
|
|
|
run regedit, on the left select MyComputer, than Ctrl + F
You can se the first result, if you want to see the next result press F3
You must find a lot of resoult.
But I try it on Windows XP SP2 I don't know mutch about longhorn.
|
|
|
|
|
Help me!!
I am do a project about after start windows ,it should run my own authentication dialog,this app tend to read a usb disk to get a SN,if the SN is the same as the one stored in Windows,than will run Explorer.exe to show the desktop and taskbar and let user to use windows,or it will showdown the computer.
how to do this with c#?
can any one help me??
thanks god!!!!
|
|
|
|
|
To get the USB drive SN is not a hard think, you can find articles in CP about USB and Hardware information, and perhapes on Google
The privet authentication is mutch harder. As I know the explorer starts befor the applications stroed in then registry/Run start. So I thik there is no way to strat an application before explorer starts. But if you find out how to the windows logon screen work, you can paste yor verification to this screen.
|
|
|
|
|
hi nemopeti:
thanks for ur help...
I will try some other way...
My boss is so stern
|
|
|
|
|
My debugger says that it can't find WindowsSolution9.exe when I attempt to debug. It happened yesterday and a friend fixed it. How do I fix this, and can I make it stop?
|
|
|
|
|
Hey
I'm really trying to serialize a listbox in my form, but I just keep getting an exception that tells me that it is not serializable
I'm writing down the code of the Main form.
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
<br />
using System.Runtime.Serialization;<br />
using System.Runtime.Serialization.Formatters.Binary;<br />
<br />
namespace Serialize_ListBox<br />
{<br />
<br />
[Serializable()]<br />
public class MainForm : System.Windows.Forms.Form, ISerializable<br />
{<br />
private System.Windows.Forms.ListBox lbText;<br />
private System.Windows.Forms.Button btnSave;<br />
private System.Windows.Forms.Button btnAdd;<br />
private Form ThisForm;<br />
private System.ComponentModel.Container components = null;<br />
<br />
<br />
<br />
public MainForm()<br />
{<br />
InitializeComponent();<br />
<br />
<br />
}<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{<br />
if (components != null) <br />
{<br />
components.Dispose();<br />
}<br />
}<br />
base.Dispose( disposing );<br />
}<br />
<br />
#region Windows Form Designer generated code<br />
private void InitializeComponent()<br />
{<br />
}<br />
#endregion<br />
<br />
[STAThread]<br />
static void Main() <br />
{<br />
Application.Run(new MainForm());<br />
}<br />
<br />
private void btnAdd_Click(object sender, System.EventArgs e)<br />
{<br />
AddDialog dlgAddText = new AddDialog();<br />
<br />
if(dlgAddText.ShowDialog() == DialogResult.OK)<br />
{<br />
lbText.BeginUpdate();<br />
lbText.Items.Add(dlgAddText.txtAdd.Text);<br />
lbText.EndUpdate();<br />
}<br />
}<br />
<br />
private void btnSave_Click(object sender, System.EventArgs e)<br />
{<br />
System.IO.Stream stream = System.IO.File.Open("listbox.bla", System.IO.FileMode.OpenOrCreate);<br />
BinaryFormatter BF = new BinaryFormatter();<br />
<br />
BF.Serialize(stream, lbText);<br />
stream.Close();<br />
MessageBox.Show("ListBox Saved");<br />
}<br />
<br />
<br />
public MainForm(SerializationInfo info, StreamingContext ctxt)<br />
{<br />
lbText = (ListBox)info.GetValue("List", typeof(ListBox));<br />
}<br />
<br />
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)<br />
{<br />
info.AddValue("List", lbText);<br />
}<br />
<br />
<br />
}<br />
<br />
}<br />
<br />
till now I serialized strings with no problems, and I don't know why its not working now.
help anyone???
Thanks ALot!
|
|
|
|