blah blah blah is here! blah blah » Close

up0down
link

hi friends
i am trying to add a help button to my program. i have added a button like this

private void button9_Click(object sender, EventArgs e)
{

System.IO.FileInfo finfo = new System.IO.FileInfo("Help.txt");

finfo.Attributes = System.IO.FileAttributes.ReadOnly;

System.Diagnostics.Process.Start("Help.txt");
}
but here i am getting problem that text file is opening but if we edit any thing that file is updating.
here i need only in the form of readonly please give me an idea for this problem.

last answered one year ago

1 answers

up2down
link

I don't think that approach will work because AFAIK it's not possible to open Notepad (which will be the default text editor on most machines) in read-only mode.

What you could do instead is to add a form to your project (HelpForm say) and cover it with a TextBox (textBox1 say) whose properties are set in the Properties Box as follows:

BackColor - Info
ForeColor - InfoText
MultiLine - True
ReadOnly - true
ScrollBars - Both

You could also use a RichTextBox instead and/or add a Close Button if you don't want the user to have to rely on the 'X' button.

Then in your HelpButton click eventhandler, add the following code:

private void helpButton_Click(object sender, EventArgs e)
{
if (Application.OpenForms["HelpForm"] == null) // don't show again if already open
{
string filePath = "help.txt"; // or whatever
HelpForm help = new HelpForm();
TextBox tb = (TextBox)help.Controls["textBox1"]; // get a reference to the textbox
tb.Text = System.IO.File.ReadAllText(filePath);
help.Show();
tb.SelectionLength = 0;
}
}

Feedback