1 of 3 comp done

This commit is contained in:
DavidMakarov 2024-10-04 12:20:51 +04:00
parent 38db4c11d2
commit 13ba5c0649
4 changed files with 61 additions and 1 deletions

View File

@ -2,6 +2,7 @@
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
using Components.SaveToPdfHelpers;
using System.Text;
namespace Components
{
@ -13,6 +14,7 @@ namespace Components
public void CreateDoc(string title, string path, List<string[][]> tables)
{
_document = new Document();
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
DefineStyles(_document);
_section = _document.AddSection();

View File

@ -28,18 +28,35 @@
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
userControlTableDocument1 = new Components.UserControlTableDocument(components);
button1 = new Button();
SuspendLayout();
//
// button1
//
button1.Location = new Point(12, 12);
button1.Name = "button1";
button1.Size = new Size(188, 65);
button1.TabIndex = 0;
button1.Text = "Сохранить первый компонент";
button1.UseVisualStyleBackColor = true;
button1.Click += button1_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(button1);
Name = "FormMain";
Text = "cB";
Text = "Testing form";
ResumeLayout(false);
}
#endregion
private Components.UserControlTableDocument userControlTableDocument1;
private Button button1;
}
}

View File

@ -6,5 +6,43 @@ namespace TestingForm
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog
{
Filter = "pdf|*.pdf",
};
if (dialog.ShowDialog() == DialogResult.OK)
{
List<string[][]> tables = new List<string[][]>();
string[][] table1 = new string[2][];
table1[0] = new string[] { "test", "test 2" };
table1[1] = new string[] { "test next", "test next 2" };
string[][] table2 = new string[3][];
table2[0] = new string[] { "ttt", "ttt 2", "ttt 3" };
table2[1] = new string[] { "ttt next", "ttt next 2" };
table2[2] = new string[] { "next" };
tables.Add(table1);
tables.Add(table2);
try
{
userControlTableDocument1.SaveToDocument(
"Çàãîëîâîê äîêóìåíòà",
dialog.FileName,
tables
);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
MessageBox.Show("Óñïåøíî");
}
}
}

View File

@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="userControlTableDocument1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>