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
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.