private void btnCancel_Click(object sender, EventArgs e)
{
//setDirty();
this.Close();
}
private void btnOk_Click(object sender, EventArgs e)
{
setDirty();
//openFileDialog1.ShowDialog();
saveFileDialog1.ShowDialog();
}
private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = @"";
openFileDialog1.Title = "Select a File";
if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
txtFilePath.Text = openFileDialog1.FileName;
else
txtFilePath.Text = "";
}
private void saveFileDialog1_FileOk(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
StringBuilder sb = new StringBuilder();
sb.AppendLine(string.Format("chkLoggin{0}\r\n", chkLoggin.Checked));
sb.AppendLine(string.Format("txtFilePath{0}\r\n", txtFilePath.Text));
sb.AppendLine(string.Format("txtNumOfThreads{0}\r\n", txtNumOfThreads.Text));
//string name = saveFileDialog1.FileName
string name = sb.ToString();
saveFileDialog1.Title ="";
saveFileDialog1.OverwritePrompt = true;
if (saveFileDialog1.ShowDialog() != DialogResult.Cancel)
txtFilePath.Text = saveFileDialog1.FileName;
//File.WriteAllText(name, txtFilePath + Environment.NewLine + txtNumOfThreads.Text);
File.WriteAllText(txtFilePath.Text, sb.ToString());
// WriteLine(sb.ToString());
}
private void chkLoggin_CheckedChanged(object sender, EventArgs e)
{
setDirty();
//btnOk.Enabled = chkLoggin.Checked;
}
private void txtNumOfThreads_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar)
&& !char.IsDigit(e.KeyChar)
&& e.KeyChar != '.')
{
e.Handled = true;
}
}
private void setDirty()
{
btnOk.Enabled = chkLoggin.Checked;
btnOk.Enabled = chkLoggin.Checked && txtFilePath.Text.Length > 0;
btnOk.Enabled = chkLoggin.Checked && txtNumOfThreads.Text.Length > 0;
}
}
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SettingsFile
{
public partial class LogForm : Form
{
public LogForm()
{
InitializeComponent();
}
private void btnCancel_Click(object sender, EventArgs e)
{
//setDirty();
this.Close();
}
private void btnOk_Click(object sender, EventArgs e)
{
setDirty();
//openFileDialog1.ShowDialog();
saveFileDialog1.ShowDialog();
}
private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = @"";
openFileDialog1.Title = "Select a File";
if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
txtFilePath.Text = openFileDialog1.FileName;
else
txtFilePath.Text = "";
}
private void saveFileDialog1_FileOk(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
StringBuilder sb = new StringBuilder();
sb.AppendLine(string.Format("chkLoggin{0}\r\n", chkLoggin.Checked));
sb.AppendLine(string.Format("txtFilePath{0}\r\n", txtFilePath.Text));
sb.AppendLine(string.Format("txtNumOfThreads{0}\r\n", txtNumOfThreads.Text));
//string name = saveFileDialog1.FileName
string name = sb.ToString();
saveFileDialog1.Title ="";
saveFileDialog1.OverwritePrompt = true;
if (saveFileDialog1.ShowDialog() != DialogResult.Cancel)
txtFilePath.Text = saveFileDialog1.FileName;
//File.WriteAllText(name, txtFilePath + Environment.NewLine + txtNumOfThreads.Text);
File.WriteAllText(txtFilePath.Text, sb.ToString());
// WriteLine(sb.ToString());
}
private void chkLoggin_CheckedChanged(object sender, EventArgs e)
{
setDirty();
//btnOk.Enabled = chkLoggin.Checked;
}
private void txtNumOfThreads_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar)
&& !char.IsDigit(e.KeyChar)
&& e.KeyChar != '.')
{
e.Handled = true;
}
}
private void setDirty()
{
btnOk.Enabled = chkLoggin.Checked;
btnOk.Enabled = chkLoggin.Checked && txtFilePath.Text.Length > 0;
btnOk.Enabled = chkLoggin.Checked && txtNumOfThreads.Text.Length > 0;
}
}
}
lilita
0
Newbie Poster
Recommended Answers
Jump to PostSo..it's a code snippet?
Jump to PostIs there some problem with the code? Or is it merely for imformative purposes?
Jump to PostSo where exactly are you have problems? are you getting exception? Or is the data not displaying in your file? Are you limited to a certain type of file?
Sorry for all the question but it makes it alot easier to help you.
All 10 Replies
oussama_1
39
Posting Whiz in Training
lilita
0
Newbie Poster
Fenrir()
52
Newbie Poster
lilita
0
Newbie Poster
Fenrir()
52
Newbie Poster
lilita
0
Newbie Poster
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
lilita
0
Newbie Poster
lilita
0
Newbie Poster
cgeier
187
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.