New Editor
-
Hi, When i use Main(string[] args) or Environment.GetCommandLineArgs; it shows me the following error. Error 1 'string' does not contain a definition for 'rtbFile' (Richtextbox instance)
show us the code.
-
show us the code.
The error is ok now. and i have done main(string[] args) or Environment.GetCommandLineargs..... But still when i double click the created file(file with .gun extension),, it still doesn't contain the content.
-
The error is ok now. and i have done main(string[] args) or Environment.GetCommandLineargs..... But still when i double click the created file(file with .gun extension),, it still doesn't contain the content.
-
Just for example :
static void Main(string[] args)
{
string fileToOpen = args[0]; // it is the same like openFileDialog.FileName// Now you MUST open the file "fileToOpen"
}I dont get what u try to say. This is my code. Can u suggest with this code....(ofdFile=Openfiledialog,rtbFile=richtextbox) void btnOpen_Click(object sender, EventArgs e) { ofdFile = new OpenFileDialog(); ofdFile.DefaultExt = @"*.gun"; ofdFile.Filter = @"Gun Files|*.gun"; if (ofdFile.ShowDialog() == System.Windows.Forms.DialogResult.OK && ofdFile.FileName.Length > 0) { //ofdFile.FileName. rtbFile.LoadFile(ofdFile.FileName, RichTextBoxStreamType.PlainText); } }
-
I dont get what u try to say. This is my code. Can u suggest with this code....(ofdFile=Openfiledialog,rtbFile=richtextbox) void btnOpen_Click(object sender, EventArgs e) { ofdFile = new OpenFileDialog(); ofdFile.DefaultExt = @"*.gun"; ofdFile.Filter = @"Gun Files|*.gun"; if (ofdFile.ShowDialog() == System.Windows.Forms.DialogResult.OK && ofdFile.FileName.Length > 0) { //ofdFile.FileName. rtbFile.LoadFile(ofdFile.FileName, RichTextBoxStreamType.PlainText); } }
And my main function is in Program.cs file
-
I dont get what u try to say. This is my code. Can u suggest with this code....(ofdFile=Openfiledialog,rtbFile=richtextbox) void btnOpen_Click(object sender, EventArgs e) { ofdFile = new OpenFileDialog(); ofdFile.DefaultExt = @"*.gun"; ofdFile.Filter = @"Gun Files|*.gun"; if (ofdFile.ShowDialog() == System.Windows.Forms.DialogResult.OK && ofdFile.FileName.Length > 0) { //ofdFile.FileName. rtbFile.LoadFile(ofdFile.FileName, RichTextBoxStreamType.PlainText); } }
pass the args[0] to your form class.
static void Main(string[] args)
{
Application.Run(new Form1(args[0]));
}For example your form class is Form1. Then change the constructor to
public Form1(string fileToBeOpened)
{
if(fileToBeOpened != string.Empty)
{
// rtbFile.LoadFile(fileToBeOpened , RichTextBoxStreamType.PlainText);
}
} -
pass the args[0] to your form class.
static void Main(string[] args)
{
Application.Run(new Form1(args[0]));
}For example your form class is Form1. Then change the constructor to
public Form1(string fileToBeOpened)
{
if(fileToBeOpened != string.Empty)
{
// rtbFile.LoadFile(fileToBeOpened , RichTextBoxStreamType.PlainText);
}
}It shows me 'IndexOutOfRangeException Unhandled' in program.cs Application.Run(new Form1(args[0]));
-
It shows me 'IndexOutOfRangeException Unhandled' in program.cs Application.Run(new Form1(args[0]));
-
I think you just COPY and PASTE the code. You must AWARE OF ERRORS. You MUST check if args.Length > 0 // you get the file directly args.Length == 0 // without file
Yes it works. Thanks a lot.
-
Yes it works. Thanks a lot.
Will get u back if i get more doubts.