Save file - done

This commit is contained in:
Anton Mukhin
2023-05-04 17:32:46 +03:00
parent 462aca461e
commit dcea501d11
5 changed files with 82 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
namespace McBitFont {
partial class Form1 {
partial class MainForm {
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
@@ -67,6 +67,8 @@
this.mirrorXToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.mirrorYToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dlgSave = new System.Windows.Forms.SaveFileDialog();
this.dlgOpen = new System.Windows.Forms.OpenFileDialog();
((System.ComponentModel.ISupportInitialize)(this.nudX)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudY)).BeginInit();
this.panel1.SuspendLayout();
@@ -413,26 +415,27 @@
// newToolStripMenuItem
//
this.newToolStripMenuItem.Name = "newToolStripMenuItem";
this.newToolStripMenuItem.Size = new System.Drawing.Size(103, 22);
this.newToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.newToolStripMenuItem.Text = "New";
this.newToolStripMenuItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click);
//
// openToolStripMenuItem
//
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
this.openToolStripMenuItem.Size = new System.Drawing.Size(103, 22);
this.openToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.openToolStripMenuItem.Text = "Open";
//
// saveToolStripMenuItem
//
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
this.saveToolStripMenuItem.Size = new System.Drawing.Size(103, 22);
this.saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.saveToolStripMenuItem.Text = "Save";
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
//
// exitToolStripMenuItem
//
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(103, 22);
this.exitToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.exitToolStripMenuItem.Text = "Exit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
//
@@ -533,7 +536,18 @@
this.aboutToolStripMenuItem.Size = new System.Drawing.Size(52, 20);
this.aboutToolStripMenuItem.Text = "About";
//
// Form1
// dlgSave
//
this.dlgSave.DefaultExt = "mbf";
this.dlgSave.Filter = "McBitFont files|*.mbf|All files|*.*";
//
// dlgOpen
//
this.dlgOpen.DefaultExt = "mbf";
this.dlgOpen.FileName = "openFileDialog1";
this.dlgOpen.Filter = "McBitFont files|*.mbf|All files|*.*";
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
@@ -556,7 +570,7 @@
this.Controls.Add(this.dotPanel);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "Form1";
this.Name = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "McBitFont";
this.Load += new System.EventHandler(this.Form1_Load);
@@ -615,6 +629,8 @@
private System.Windows.Forms.ToolStripMenuItem mirrorXToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem mirrorYToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem;
private System.Windows.Forms.SaveFileDialog dlgSave;
private System.Windows.Forms.OpenFileDialog dlgOpen;
}
}

View File

@@ -10,10 +10,14 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using System.Runtime.InteropServices;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.InteropServices.ComTypes;
namespace McBitFont {
public partial class Form1 : Form {
public partial class MainForm : Form {
[Serializable]
public struct FrameMiniature {
public FrameMiniature(int cc, int ww, int hh) {
code = cc;
@@ -27,6 +31,12 @@ namespace McBitFont {
public bool[,] data;
};
[Serializable]
public struct SaveBlock {
public bool monospaced;
public List<FrameMiniature> frames;
}
private FrameMiniature f;
List<FrameMiniature> frames = new List<FrameMiniature>();
private int cellSize = 10;
@@ -37,7 +47,7 @@ namespace McBitFont {
bool monospaced = false;
bool modified = false;
public Form1() {
public MainForm() {
InitializeComponent();
this.dotPanel.MouseWheel += new MouseEventHandler(this.dotPanel_MouseWheel);
}
@@ -401,7 +411,7 @@ namespace McBitFont {
for (i = 32; i < 128; i++)
frames.Add(new FrameMiniature(i, neww, newh));
}
if (form.cbLatin.Checked) {
if (form.cbExtended.Checked) {
for (i = 128; i < 256; i++)
frames.Add(new FrameMiniature(i, neww, newh));
}
@@ -418,6 +428,7 @@ namespace McBitFont {
f = frames.First();
dotPanel.Refresh();
miniList.Refresh();
form.Dispose();
}
}
@@ -437,6 +448,42 @@ namespace McBitFont {
dotPanel.Refresh();
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e) {
if (dlgSave.ShowDialog() == DialogResult.OK) {
//MessageBox.Show(dlgSave.FileName);
SaveBlock sav;
sav.monospaced = monospaced;
sav.frames = frames;
BinaryFormatter formatter = new BinaryFormatter();
using (System.IO.Stream ms = File.OpenWrite(dlgSave.FileName)) {
formatter.Serialize(ms, sav);
ms.Close();
}
//string filename = @"c:\temp\list.bin";
//var list = new List<X>();
//list.Add(new X { N = 1, S = "No. 1" });
//list.Add(new X { N = 2, S = "No. 2" });
//list.Add(new X { N = 3, S = "No. 3" });
//BinaryFormatter formatter = new BinaryFormatter();
//using (System.IO.Stream ms = File.OpenWrite(filename)) {
// formatter.Serialize(ms, list);
//}
//using (FileStream fs = File.Open(filename, FileMode.Open)) {
// object obj = formatter.Deserialize(fs);
// var newlist = (List<X>)obj;
// foreach (X x in newlist) {
// Console.Out.WriteLine($"N={x.N}, S={x.S}");
// }
//}
}
}
private void hScroll_ValueChanged(object sender, EventArgs e) {
label5.Text = hScroll.Value.ToString();
dotPanel.Refresh();

View File

@@ -123,4 +123,10 @@
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>127, 17</value>
</metadata>
<metadata name="dlgSave.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>242, 17</value>
</metadata>
<metadata name="dlgOpen.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>336, 17</value>
</metadata>
</root>

View File

@@ -201,7 +201,9 @@
//
// New
//
this.AcceptButton = this.btnOK;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(284, 161);
this.Controls.Add(this.cbSingle);
this.Controls.Add(this.btnCancel);

View File

@@ -13,7 +13,7 @@ namespace McBitFont {
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new MainForm());
}
}
}