kopia lustrzana https://github.com/njcrawford/EmbroideryReader
Fixed bugs 13,16 and 17.
Added settings dialog, added background color to settings file and settings dialog, made drawing bitmap bigger to account for bigger pen sizes.Branch_1.5.0
rodzic
1329dbb402
commit
5cd48b8d4e
|
@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
|||
//
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.0.101")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.101")]
|
||||
[assembly: AssemblyVersion("1.0.0.147")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.147")]
|
||||
|
|
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
|
@ -1,61 +0,0 @@
|
|||
namespace embroideryReader
|
||||
{
|
||||
partial class Form2
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.Location = new System.Drawing.Point(0, 0);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(289, 272);
|
||||
this.panel1.TabIndex = 0;
|
||||
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
|
||||
//
|
||||
// Form2
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.AutoScroll = true;
|
||||
this.ClientSize = new System.Drawing.Size(292, 273);
|
||||
this.Controls.Add(this.panel1);
|
||||
this.DoubleBuffered = true;
|
||||
this.Name = "Form2";
|
||||
this.Text = "Form2";
|
||||
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form2_Paint);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Panel panel1;
|
||||
}
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace embroideryReader
|
||||
{
|
||||
public partial class Form2 : Form
|
||||
{
|
||||
//public List<Point> pointList = new List<Point>();
|
||||
//public Point[] points = new Point[0];
|
||||
//public Color drawColor = System.Drawing.Color.Black;
|
||||
public Pen drawPen = Pens.Black;
|
||||
public Bitmap DrawArea;
|
||||
//public Point prevPoint = new Point(-1, -1);
|
||||
public PesFile.PesFile design;
|
||||
//private int blockNum = -1;
|
||||
//private int stitchNum = -1;
|
||||
|
||||
public Form2()
|
||||
{
|
||||
InitializeComponent();
|
||||
//DrawArea = new Bitmap(1000, 1000);
|
||||
}
|
||||
|
||||
private void Form2_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
//Point[] points = new Point[pointList.Count];
|
||||
//pointList.CopyTo(points);
|
||||
//if (points.Length >= 2)
|
||||
//{
|
||||
// e.Graphics.DrawLines(new System.Drawing.Pen(drawColor), points);
|
||||
//}
|
||||
//e.Graphics.DrawImage(DrawArea, 0, 0);
|
||||
}
|
||||
|
||||
//public void addPoint(Point p)
|
||||
//{
|
||||
// //Point[] tmp = new Point[points.Length + 1];
|
||||
// //points.CopyTo(tmp,0);
|
||||
// //tmp[tmp.Length - 1] = p;
|
||||
// //points = tmp;
|
||||
|
||||
// if (prevPoint != null && prevPoint.X != -1 && prevPoint.Y != -1)
|
||||
// {
|
||||
// Graphics xGraph;
|
||||
// xGraph = Graphics.FromImage(DrawArea);
|
||||
// xGraph.DrawLine(drawPen, prevPoint, p);
|
||||
// xGraph.Dispose();
|
||||
// }
|
||||
// prevPoint = p;
|
||||
|
||||
//}
|
||||
|
||||
private void panel1_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
e.Graphics.DrawImage(DrawArea, 0, 0);
|
||||
}
|
||||
|
||||
public void setPanelSize(int x, int y)
|
||||
{
|
||||
panel1.Width = x;
|
||||
panel1.Height = y;
|
||||
}
|
||||
|
||||
//public void nextStitch()
|
||||
//{
|
||||
// Graphics xGraph;
|
||||
// xGraph = Graphics.FromImage(DrawArea);
|
||||
// if (stitchNum < design.blocks[blockNum].stitches.Length)
|
||||
// {
|
||||
// if (stitchNum >= 0)
|
||||
// {
|
||||
// xGraph.DrawLine(drawPen, design.blocks[blockNum].stitches[stitchNum], design.blocks[blockNum].stitches[stitchNum]);
|
||||
// }
|
||||
// stitchNum++;
|
||||
// }
|
||||
// xGraph.Dispose();
|
||||
// panel1.Invalidate();
|
||||
//}
|
||||
|
||||
public void finishDesign()
|
||||
{
|
||||
Graphics xGraph;
|
||||
xGraph = Graphics.FromImage(DrawArea);
|
||||
for (int i = 0; i < design.blocks.Count; i++)
|
||||
{
|
||||
xGraph.DrawLines(new Pen(design.blocks[i].color,2.5f), design.blocks[i].stitches);
|
||||
}
|
||||
xGraph.Dispose();
|
||||
this.panel1.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ namespace embroideryReader
|
|||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new Form1());
|
||||
Application.Run(new frmMain());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
|||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("1.1.0.324")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.324")]
|
||||
[assembly: AssemblyVersion("1.1.0.363")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.363")]
|
||||
|
|
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
|
@ -41,28 +41,28 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Form1.cs">
|
||||
<Compile Include="frmMain.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Form1.Designer.cs">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
<Compile Include="frmMain.Designer.cs">
|
||||
<DependentUpon>frmMain.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Form2.cs">
|
||||
<Compile Include="frmSettingsDialog.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Form2.Designer.cs">
|
||||
<DependentUpon>Form2.cs</DependentUpon>
|
||||
<Compile Include="frmSettingsDialog.Designer.cs">
|
||||
<DependentUpon>frmSettingsDialog.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="nc_Update.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<EmbeddedResource Include="frmMain.resx">
|
||||
<SubType>Designer</SubType>
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
<DependentUpon>frmMain.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Form2.resx">
|
||||
<EmbeddedResource Include="frmSettingsDialog.resx">
|
||||
<SubType>Designer</SubType>
|
||||
<DependentUpon>Form2.cs</DependentUpon>
|
||||
<DependentUpon>frmSettingsDialog.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<PublishUrlHistory>publish\</PublishUrlHistory>
|
||||
<InstallUrlHistory>
|
||||
</InstallUrlHistory>
|
||||
<SupportUrlHistory>
|
||||
</SupportUrlHistory>
|
||||
<UpdateUrlHistory>
|
||||
</UpdateUrlHistory>
|
||||
<BootstrapperUrlHistory>
|
||||
</BootstrapperUrlHistory>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<FallbackCulture>en-US</FallbackCulture>
|
||||
<VerifyUploadedFiles>false</VerifyUploadedFiles>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -1,6 +1,6 @@
|
|||
namespace embroideryReader
|
||||
{
|
||||
partial class Form1
|
||||
partial class frmMain
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
|
@ -43,6 +43,8 @@ namespace embroideryReader
|
|||
this.panel2 = new System.Windows.Forms.Panel();
|
||||
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
|
||||
this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.preferencesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.panel2.SuspendLayout();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
|
@ -64,6 +66,7 @@ namespace embroideryReader
|
|||
//
|
||||
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.fileToolStripMenuItem,
|
||||
this.editToolStripMenuItem,
|
||||
this.helpToolStripMenuItem});
|
||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip1.Name = "menuStrip1";
|
||||
|
@ -84,19 +87,19 @@ namespace embroideryReader
|
|||
// openToolStripMenuItem
|
||||
//
|
||||
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
|
||||
this.openToolStripMenuItem.Size = new System.Drawing.Size(111, 22);
|
||||
this.openToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.openToolStripMenuItem.Text = "Open";
|
||||
this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
|
||||
//
|
||||
// toolStripSeparator2
|
||||
//
|
||||
this.toolStripSeparator2.Name = "toolStripSeparator2";
|
||||
this.toolStripSeparator2.Size = new System.Drawing.Size(108, 6);
|
||||
this.toolStripSeparator2.Size = new System.Drawing.Size(149, 6);
|
||||
//
|
||||
// exitToolStripMenuItem
|
||||
//
|
||||
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
|
||||
this.exitToolStripMenuItem.Size = new System.Drawing.Size(111, 22);
|
||||
this.exitToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.exitToolStripMenuItem.Text = "Exit";
|
||||
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
|
||||
//
|
||||
|
@ -161,7 +164,22 @@ namespace embroideryReader
|
|||
this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
|
||||
this.toolStripStatusLabel1.Size = new System.Drawing.Size(0, 17);
|
||||
//
|
||||
// Form1
|
||||
// editToolStripMenuItem
|
||||
//
|
||||
this.editToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.preferencesToolStripMenuItem});
|
||||
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
|
||||
this.editToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
|
||||
this.editToolStripMenuItem.Text = "Edit";
|
||||
//
|
||||
// preferencesToolStripMenuItem
|
||||
//
|
||||
this.preferencesToolStripMenuItem.Name = "preferencesToolStripMenuItem";
|
||||
this.preferencesToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.preferencesToolStripMenuItem.Text = "Preferences";
|
||||
this.preferencesToolStripMenuItem.Click += new System.EventHandler(this.preferencesToolStripMenuItem_Click);
|
||||
//
|
||||
// frmMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
|
@ -170,7 +188,7 @@ namespace embroideryReader
|
|||
this.Controls.Add(this.menuStrip1);
|
||||
this.Controls.Add(this.panel2);
|
||||
this.MainMenuStrip = this.menuStrip1;
|
||||
this.Name = "Form1";
|
||||
this.Name = "frmMain";
|
||||
this.Text = "Form1";
|
||||
this.Resize += new System.EventHandler(this.Form1_Resize);
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
|
||||
|
@ -203,6 +221,8 @@ namespace embroideryReader
|
|||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
|
||||
private System.Windows.Forms.StatusStrip statusStrip1;
|
||||
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
|
||||
private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem preferencesToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
|
|
@ -10,16 +10,16 @@ using System.Runtime.InteropServices;
|
|||
|
||||
namespace embroideryReader
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
public partial class frmMain : Form
|
||||
{
|
||||
private string[] args;
|
||||
public Pen drawPen = Pens.Black;
|
||||
public Bitmap DrawArea;
|
||||
public PesFile.PesFile design;
|
||||
private Pen drawPen = Pens.Black;
|
||||
private Bitmap DrawArea;
|
||||
private PesFile.PesFile design;
|
||||
private nc_settings.IniFile settings = new nc_settings.IniFile("embroideryreader.ini");
|
||||
|
||||
|
||||
public Form1()
|
||||
public frmMain()
|
||||
{
|
||||
InitializeComponent();
|
||||
args = Environment.GetCommandLineArgs();
|
||||
|
@ -40,21 +40,91 @@ namespace embroideryReader
|
|||
// }
|
||||
//}
|
||||
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
private void loadSettings()
|
||||
{
|
||||
string updateLoc;
|
||||
updateLoc = settings.getValue("update location");
|
||||
if (updateLoc == null || updateLoc == "")
|
||||
if (updateLoc == null || updateLoc.Length == 0)
|
||||
{
|
||||
settings.setValue("update location", "http://www.njcrawford.com/embreader/");
|
||||
}
|
||||
if (settings.getValue("background color", "enabled") == "yes")
|
||||
{
|
||||
if (checkColorFromStrings(settings.getValue("background color", "red"),
|
||||
settings.getValue("background color", "green"),
|
||||
settings.getValue("background color", "blue")))
|
||||
{
|
||||
this.BackColor = makeColorFromStrings(settings.getValue("background color", "red"),
|
||||
settings.getValue("background color", "green"),
|
||||
settings.getValue("background color", "blue"));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.BackColor = Color.FromKnownColor(KnownColor.Control);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.BackColor = Color.FromKnownColor(KnownColor.Control);
|
||||
}
|
||||
}
|
||||
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
loadSettings();
|
||||
this.Text = "Embroidery Reader";
|
||||
if (args.Length > 1)
|
||||
{
|
||||
openFile(args[1]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static bool checkColorFromStrings(string red, string green, string blue)
|
||||
{
|
||||
//string redString;
|
||||
//string greenString;
|
||||
//string blueString;
|
||||
byte redByte;
|
||||
byte greenByte;
|
||||
byte blueByte;
|
||||
//red = settings.getValue("background color", "red");
|
||||
//greenString = settings.getValue("background color", "green");
|
||||
//blueString = settings.getValue("background color", "blue");
|
||||
bool retval = false;
|
||||
if (String.IsNullOrEmpty(red) || String.IsNullOrEmpty(green) || String.IsNullOrEmpty(blue))
|
||||
{
|
||||
retval = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
redByte = Convert.ToByte(red);
|
||||
greenByte = Convert.ToByte(green);
|
||||
blueByte = Convert.ToByte(blue);
|
||||
//this.BackColor = Color.FromArgb(redByte, greenByte, blueByte);
|
||||
retval = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
retval = false;
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
public static Color makeColorFromStrings(string red, string green, string blue)
|
||||
{
|
||||
if (checkColorFromStrings(red, green, blue))
|
||||
{
|
||||
return Color.FromArgb(Convert.ToByte(red), Convert.ToByte(green), Convert.ToByte(blue));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Color.Red;
|
||||
}
|
||||
}
|
||||
|
||||
private void openFile(string filename)
|
||||
{
|
||||
if (!System.IO.File.Exists(filename))
|
||||
|
@ -65,9 +135,7 @@ namespace embroideryReader
|
|||
if (design.getStatus() == PesFile.statusEnum.Ready)
|
||||
{
|
||||
this.Text = System.IO.Path.GetFileName(filename) + " - Embroidery Reader";
|
||||
DrawArea = new Bitmap(design.GetWidth(), design.GetHeight());
|
||||
sizePanel2();
|
||||
setPanelSize(design.GetWidth(), design.GetHeight());
|
||||
|
||||
designToBitmap();
|
||||
|
||||
|
@ -91,15 +159,17 @@ namespace embroideryReader
|
|||
string filename;
|
||||
openFileDialog1.FileName = "";
|
||||
openFileDialog1.Filter = "Embroidery Files (*.pes)|*.pes|All Files (*.*)|*.*";
|
||||
openFileDialog1.ShowDialog();
|
||||
filename = openFileDialog1.FileName;
|
||||
if (!System.IO.File.Exists(filename))
|
||||
if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
openFile(filename);
|
||||
filename = openFileDialog1.FileName;
|
||||
if (!System.IO.File.Exists(filename))
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
openFile(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,12 +186,6 @@ namespace embroideryReader
|
|||
}
|
||||
}
|
||||
|
||||
public void setPanelSize(int x, int y)
|
||||
{
|
||||
panel1.Width = x;
|
||||
panel1.Height = y;
|
||||
}
|
||||
|
||||
public void designToBitmap()
|
||||
{
|
||||
Graphics xGraph;
|
||||
|
@ -136,7 +200,11 @@ namespace embroideryReader
|
|||
{
|
||||
}
|
||||
}
|
||||
DrawArea = new Bitmap(design.GetWidth() + (int)(threadThickness * 2), design.GetHeight() + (int)(threadThickness * 2));
|
||||
panel1.Width = design.GetWidth() + (int)(threadThickness * 2);
|
||||
panel1.Height = design.GetHeight() + (int)(threadThickness * 2);
|
||||
xGraph = Graphics.FromImage(DrawArea);
|
||||
xGraph.TranslateTransform(threadThickness, threadThickness);
|
||||
for (int i = 0; i < design.blocks.Count; i++)
|
||||
{
|
||||
if (design.blocks[i].stitches.Length > 1)//must have 2 points to make a line
|
||||
|
@ -260,8 +328,6 @@ namespace embroideryReader
|
|||
{
|
||||
if (design != null)
|
||||
{
|
||||
//if (design.isReadyToUse())
|
||||
//{
|
||||
try
|
||||
{
|
||||
design.saveDebugInfo();
|
||||
|
@ -270,11 +336,6 @@ namespace embroideryReader
|
|||
{
|
||||
MessageBox.Show("There was an error while saving debug info:" + Environment.NewLine + ex.ToString());
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// MessageBox.Show("The design could not be read successfully.");
|
||||
//}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -299,8 +360,19 @@ namespace embroideryReader
|
|||
|
||||
private void sizePanel2()
|
||||
{
|
||||
panel2.Height = this.Height - 75;
|
||||
panel2.Height = this.Height - 73;
|
||||
panel2.Width = this.Width - 8;
|
||||
}
|
||||
|
||||
private void preferencesToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
frmSettingsDialog tempForm = new frmSettingsDialog();
|
||||
tempForm.settings = settings;
|
||||
if (tempForm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
settings = tempForm.settings;
|
||||
loadSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
namespace embroideryReader
|
||||
{
|
||||
partial class frmSettingsDialog
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.colorDialog1 = new System.Windows.Forms.ColorDialog();
|
||||
this.btnColor = new System.Windows.Forms.Button();
|
||||
this.lblColor = new System.Windows.Forms.Label();
|
||||
this.btnResetColor = new System.Windows.Forms.Button();
|
||||
this.btnOK = new System.Windows.Forms.Button();
|
||||
this.btnCancel = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// btnColor
|
||||
//
|
||||
this.btnColor.Location = new System.Drawing.Point(148, 9);
|
||||
this.btnColor.Name = "btnColor";
|
||||
this.btnColor.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnColor.TabIndex = 0;
|
||||
this.btnColor.Text = "Pick Color...";
|
||||
this.btnColor.UseVisualStyleBackColor = true;
|
||||
this.btnColor.Click += new System.EventHandler(this.btnColor_Click);
|
||||
//
|
||||
// lblColor
|
||||
//
|
||||
this.lblColor.Location = new System.Drawing.Point(12, 9);
|
||||
this.lblColor.Name = "lblColor";
|
||||
this.lblColor.Size = new System.Drawing.Size(130, 52);
|
||||
this.lblColor.TabIndex = 1;
|
||||
this.lblColor.Text = "Background Color";
|
||||
this.lblColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// btnResetColor
|
||||
//
|
||||
this.btnResetColor.Location = new System.Drawing.Point(148, 38);
|
||||
this.btnResetColor.Name = "btnResetColor";
|
||||
this.btnResetColor.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnResetColor.TabIndex = 2;
|
||||
this.btnResetColor.Text = "Reset Color";
|
||||
this.btnResetColor.UseVisualStyleBackColor = true;
|
||||
this.btnResetColor.Click += new System.EventHandler(this.btnResetColor_Click);
|
||||
//
|
||||
// btnOK
|
||||
//
|
||||
this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
|
||||
this.btnOK.Location = new System.Drawing.Point(67, 83);
|
||||
this.btnOK.Name = "btnOK";
|
||||
this.btnOK.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnOK.TabIndex = 3;
|
||||
this.btnOK.Text = "OK";
|
||||
this.btnOK.UseVisualStyleBackColor = true;
|
||||
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
|
||||
//
|
||||
// btnCancel
|
||||
//
|
||||
this.btnCancel.Location = new System.Drawing.Point(148, 83);
|
||||
this.btnCancel.Name = "btnCancel";
|
||||
this.btnCancel.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnCancel.TabIndex = 4;
|
||||
this.btnCancel.Text = "Cancel";
|
||||
this.btnCancel.UseVisualStyleBackColor = true;
|
||||
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
|
||||
//
|
||||
// frmSettingsDialog
|
||||
//
|
||||
this.AcceptButton = this.btnOK;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.CancelButton = this.btnCancel;
|
||||
this.ClientSize = new System.Drawing.Size(234, 118);
|
||||
this.Controls.Add(this.btnCancel);
|
||||
this.Controls.Add(this.btnOK);
|
||||
this.Controls.Add(this.btnResetColor);
|
||||
this.Controls.Add(this.lblColor);
|
||||
this.Controls.Add(this.btnColor);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "frmSettingsDialog";
|
||||
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
|
||||
this.Text = "Embroidery Reader Settings";
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.ColorDialog colorDialog1;
|
||||
private System.Windows.Forms.Button btnColor;
|
||||
private System.Windows.Forms.Label lblColor;
|
||||
private System.Windows.Forms.Button btnResetColor;
|
||||
private System.Windows.Forms.Button btnOK;
|
||||
private System.Windows.Forms.Button btnCancel;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace embroideryReader
|
||||
{
|
||||
public partial class frmSettingsDialog : Form
|
||||
{
|
||||
private bool colorChanged = false;
|
||||
private nc_settings.IniFile _settings;
|
||||
public nc_settings.IniFile settings
|
||||
{
|
||||
get
|
||||
{
|
||||
return _settings;
|
||||
}
|
||||
set
|
||||
{
|
||||
_settings = value;
|
||||
if (settings.getValue("background color", "enabled") == "yes" &&
|
||||
frmMain.checkColorFromStrings(
|
||||
settings.getValue("background color", "red"),
|
||||
settings.getValue("background color", "green"),
|
||||
settings.getValue("background color", "blue")))
|
||||
{
|
||||
lblColor.BackColor = frmMain.makeColorFromStrings(
|
||||
settings.getValue("background color", "red"),
|
||||
settings.getValue("background color", "green"),
|
||||
settings.getValue("background color", "blue"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public frmSettingsDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void btnCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
//public void ShowDialog()
|
||||
//{
|
||||
//public
|
||||
//if (settings.getValue("background color", "enabled") == "yes" &&
|
||||
// frmMain.checkColorFromStrings(
|
||||
// settings.getValue("background color", "red"),
|
||||
// settings.getValue("background color", "green"),
|
||||
// settings.getValue("background color", "blue")))
|
||||
//{
|
||||
// lblColor.BackColor = frmMain.makeColorFromStrings(
|
||||
// settings.getValue("background color", "red"),
|
||||
// settings.getValue("background color", "green"),
|
||||
// settings.getValue("background color", "blue"));
|
||||
//}
|
||||
//this.Show();
|
||||
//}
|
||||
|
||||
private void btnColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
colorDialog1.Color = lblColor.BackColor;
|
||||
if (colorDialog1.ShowDialog() == DialogResult.OK && lblColor.BackColor != colorDialog1.Color)
|
||||
{
|
||||
lblColor.BackColor = colorDialog1.Color;
|
||||
colorChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void btnResetColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (lblColor.BackColor != Color.FromKnownColor(KnownColor.Control))
|
||||
{
|
||||
lblColor.BackColor = Color.FromKnownColor(KnownColor.Control);
|
||||
colorChanged = true;
|
||||
//settings.setValue("background color", "enabled", "no");
|
||||
}
|
||||
}
|
||||
|
||||
private void btnOK_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (colorChanged)
|
||||
{
|
||||
if (lblColor.BackColor != Color.FromKnownColor(KnownColor.Control))
|
||||
{
|
||||
settings.setValue("background color", "enabled", "yes");
|
||||
settings.setValue("background color", "red", lblColor.BackColor.R.ToString());
|
||||
settings.setValue("background color", "green", lblColor.BackColor.G.ToString());
|
||||
settings.setValue("background color", "blue", lblColor.BackColor.B.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
settings.setValue("background color", "enabled", "no");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -117,4 +117,7 @@
|
|||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="colorDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
|
@ -1,240 +0,0 @@
|
|||
// $Id$
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SettingsTester
|
||||
{
|
||||
class fileSection
|
||||
{
|
||||
public string name;
|
||||
public List<stringPair> values = new List<stringPair>();
|
||||
//public List<string> unknownLines = new List<string>();
|
||||
|
||||
public fileSection()
|
||||
{
|
||||
//sectionNum = -1;
|
||||
name = "";
|
||||
values = new List<stringPair>();
|
||||
//unknownLines = new List<string>();
|
||||
}
|
||||
}
|
||||
|
||||
class stringPair
|
||||
{
|
||||
public string value;
|
||||
public string name;
|
||||
//public int lineNum;
|
||||
|
||||
public stringPair()
|
||||
{
|
||||
value = "";
|
||||
name = "";
|
||||
//lineNum = -1;
|
||||
}
|
||||
}
|
||||
|
||||
class nc_Settings
|
||||
{
|
||||
private string _filename = "";
|
||||
private List<fileSection> _sections = new List<fileSection>();
|
||||
|
||||
public static string appPath()
|
||||
{
|
||||
return System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
|
||||
}
|
||||
|
||||
/** If filename does not contain any slashes or backslashes, appPath()
|
||||
* is automatically prepended.*/
|
||||
public nc_Settings(string filename)
|
||||
{
|
||||
_filename = filename;
|
||||
if (!_filename.Contains("\"") && !_filename.Contains("/"))
|
||||
{
|
||||
_filename = System.IO.Path.Combine(appPath(), _filename);
|
||||
}
|
||||
_sections.Add(new fileSection()); //make sure the file has a default section, and it is the first
|
||||
readValues();
|
||||
}
|
||||
|
||||
/** Returns the value associated with name if it exists,
|
||||
* returns a null string if it doesn't. */
|
||||
public string getValue(string name)
|
||||
{
|
||||
return getValue("", name);
|
||||
}
|
||||
|
||||
/** Returns the value of _values[index] if it exists,
|
||||
* returns a null string if it doesn't. */
|
||||
//public string getValue(int index)
|
||||
//{
|
||||
// string retval = null;
|
||||
// if (index < _values.Count)
|
||||
// {
|
||||
// retval = _values[index].value;
|
||||
// }
|
||||
// return retval;
|
||||
//}
|
||||
|
||||
public string getValue(string sectionName, string valueName)
|
||||
{
|
||||
string retval = null;
|
||||
for (int y = 0; y < _sections.Count; y++)
|
||||
{
|
||||
if (_sections[y].name.Equals(sectionName))
|
||||
{
|
||||
for (int x = 0; x < _sections[y].values.Count; x++)
|
||||
{
|
||||
if (_sections[y].values[x].name.Equals(valueName))
|
||||
{
|
||||
retval = _sections[y].values[x].value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
//public int getValueCount()
|
||||
//{
|
||||
// return _values.Count;
|
||||
//}
|
||||
|
||||
/** Returns the name of _values[index] if it exists,
|
||||
* returns a null string if it doesn't. */
|
||||
//public string getName(int index)
|
||||
//{
|
||||
// string retval = null;
|
||||
// if (index < _values.Count)
|
||||
// {
|
||||
// retval = _values[index].name;
|
||||
// }
|
||||
// return retval;
|
||||
//}
|
||||
|
||||
/** Sets the value of name to value. If name doesn't exist,
|
||||
* it will be added. Uses default (no name) section. */
|
||||
public void setValue(string name, string value)
|
||||
{
|
||||
setValue("", name, value);
|
||||
}
|
||||
|
||||
/** Sets the value of name to value. If name doesn't exist,
|
||||
* it will be added. Sections are added as needed. */
|
||||
public void setValue(string sectionName, string valueName, string value)
|
||||
{
|
||||
bool foundValue = false;
|
||||
bool foundSection = false;
|
||||
|
||||
for (int y = 0; y < _sections.Count; y++)
|
||||
{
|
||||
if (_sections[y].name.Equals(sectionName))
|
||||
{
|
||||
foundSection = true;
|
||||
for (int x = 0; x < _sections[y].values.Count; x++)
|
||||
{
|
||||
if (_sections[y].values[x].name.Equals(valueName))
|
||||
{
|
||||
stringPair tmp = new stringPair();
|
||||
tmp.name = valueName;
|
||||
tmp.value = value;
|
||||
//tmp.lineNum = _sections[y].values[x].lineNum;
|
||||
foundValue = true;
|
||||
_sections[y].values[x] = tmp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundValue)
|
||||
{
|
||||
stringPair tmp = new stringPair();
|
||||
tmp.name = valueName;
|
||||
tmp.value = value;
|
||||
//tmp.lineNum = -1;
|
||||
_sections[y].values.Add(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (!foundSection)
|
||||
{
|
||||
fileSection tmpSection = new fileSection();
|
||||
stringPair tmpValue = new stringPair();
|
||||
tmpSection.name = sectionName;
|
||||
//tmpValue.lineNum = -1;
|
||||
tmpValue.name = valueName;
|
||||
tmpValue.value = value;
|
||||
_sections.Add(tmpSection);
|
||||
_sections[_sections.Count - 1].values.Add(tmpValue);
|
||||
}
|
||||
}
|
||||
|
||||
/** Writes all sections and name-value pairs to the file.
|
||||
* Creates the file if it doesn't exist. */
|
||||
public void save()
|
||||
{
|
||||
System.IO.StreamWriter outFile;
|
||||
string tempfile = System.IO.Path.GetDirectoryName(_filename);
|
||||
tempfile = System.IO.Path.Combine(tempfile, System.IO.Path.GetFileNameWithoutExtension(_filename) + ".tmp" + System.IO.Path.GetExtension(_filename));
|
||||
outFile = System.IO.File.CreateText(tempfile);
|
||||
for (int y = 0; y < _sections.Count; y++)
|
||||
{
|
||||
if (y != 0)
|
||||
{
|
||||
outFile.WriteLine();
|
||||
outFile.WriteLine("[" + _sections[y].name + "]");
|
||||
}
|
||||
for (int x = 0; x < _sections[y].values.Count; x++)
|
||||
{
|
||||
outFile.WriteLine(_sections[y].values[x].name + "=" + _sections[y].values[x].value);
|
||||
}
|
||||
}
|
||||
outFile.Close();
|
||||
System.IO.File.Copy(tempfile, _filename, true);
|
||||
System.IO.File.Delete(tempfile);
|
||||
}
|
||||
|
||||
/** Re-reads name-value pairs from file.
|
||||
* Uses same function as constructor. ( readValues() ) */
|
||||
public void reReadValues()
|
||||
{
|
||||
readValues();
|
||||
}
|
||||
|
||||
/** Reads name-value pairs from file. Uses setValue()
|
||||
* to add name-value pairs to _sections[n].values, so
|
||||
* if the value already exists it will be overwritten,
|
||||
* if not it will be added. Any line without an equals
|
||||
* sign will be discarded. Exception: lines that start
|
||||
* with a [ and have a ] later will be read as section
|
||||
* headers. Whitespace before and after will be eaten.*/
|
||||
private void readValues()
|
||||
{
|
||||
System.IO.StreamReader inFile;
|
||||
string inLine;
|
||||
string section = "";
|
||||
//stringPair tmp;
|
||||
if (System.IO.File.Exists(_filename))
|
||||
{
|
||||
inFile = System.IO.File.OpenText(_filename);
|
||||
inLine = inFile.ReadLine();
|
||||
while (inLine != null)
|
||||
{
|
||||
if (inLine.Trim().StartsWith("[") && inLine.Contains("]"))
|
||||
{
|
||||
int start = inLine.IndexOf('[') +1;
|
||||
int length = inLine.IndexOf(']') - start;
|
||||
section = inLine.Substring(start, length);
|
||||
}
|
||||
else if (inLine.Contains("="))
|
||||
{
|
||||
setValue(section, inLine.Remove(inLine.IndexOf("=")), inLine.Substring(inLine.IndexOf("=") + 1));
|
||||
}
|
||||
inLine = inFile.ReadLine();
|
||||
}
|
||||
inFile.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Plik binarny nie jest wyświetlany.
Ładowanie…
Reference in New Issue