123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554 |
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using PaintDotNet.Base.SettingModel;
- using System.Collections;
- using System.IO;
- using PaintDotNet.Base.CommTool;
- using System.Collections.Generic;
- using System.Drawing.Imaging;
- using System.Drawing.Drawing2D;
- namespace PaintDotNet.Setting
- {
- public partial class WatermarkSettingsDialog : PdnBaseForm
- {
- #region 组件
- private System.Windows.Forms.GroupBox groupBox2;
- private System.Windows.Forms.Button button2;
- private System.Windows.Forms.Button button1;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.ComboBox comboBox1;
- private System.Windows.Forms.Button button4;
- private System.Windows.Forms.Button button3;
- private System.Windows.Forms.GroupBox groupBox1;
- private System.Windows.Forms.RadioButton radioButton2;
- private System.Windows.Forms.RadioButton radioButton1;
- private System.Windows.Forms.GroupBox groupBox3;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.Label label4;
- private System.Windows.Forms.Label label3;
- private System.Windows.Forms.Label label6;
- private System.Windows.Forms.ComboBox comboBox2;
- private System.Windows.Forms.Label label5;
- private System.Windows.Forms.RadioButton radioButton3;
- private CustomControl.UserTextBox userTextBox2;
- private System.Windows.Forms.RadioButton radioButton4;
- private System.Windows.Forms.TrackBar trackBar1;
- private System.Windows.Forms.GroupBox groupBox4;
- private System.Windows.Forms.Label label7;
- private System.Windows.Forms.RadioButton radioButton5;
- private System.Windows.Forms.RadioButton radioButton6;
- private System.Windows.Forms.RadioButton radioButton8;
- private System.Windows.Forms.RadioButton radioButton7;
- private System.Windows.Forms.Label label8;
- private System.Windows.Forms.Label label9;
- private System.Windows.Forms.ComboBox comboBox3;
- private System.Windows.Forms.Panel panel2;
- private System.Windows.Forms.Label label10;
- private System.Windows.Forms.CheckBox checkBox2;
- private System.Windows.Forms.CheckBox checkBox1;
- private System.Windows.Forms.GroupBox groupBox5;
- private System.Windows.Forms.PictureBox pictureBox2;
- private System.Windows.Forms.Button button5;
- private CustomControl.UserTextBox userTextBox3;
- //private System.Windows.Forms.ColorDialog colorVal;
- private System.Windows.Forms.TextBox userTextBox1;
- PaintDotNet.ColorsForm colorsForm;
- private NumericUpDown numericUpDown1;
- /// <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
- private void InitializeLanguageText()
- {
- this.groupBox2.Text = PdnResources.GetString("Menu.operation.text");
- this.button4.Text = PdnResources.GetString("Menu.File.SaveAs.Text");
- this.button3.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
- this.label1.Text = PdnResources.GetString("Menu.Currentoperationstyle.text") + ":";
- this.button2.Text = PdnResources.GetString("Menu.application.text");
- this.button1.Text = PdnResources.GetString("Menu.File.Save.Text");
- this.groupBox1.Text = PdnResources.GetString("Menu.Type.text");
- this.radioButton2.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Imagewatermark.text");
- this.radioButton1.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Textwatermark.text");
- this.groupBox3.Text = PdnResources.GetString("Menu.Set.Watermarksettings.BasicInformation.text");
- this.button5.Text = PdnResources.GetString("Menu.browse.Text");
- this.radioButton3.Text = PdnResources.GetString("Menu.no.text");
- this.radioButton4.Text = PdnResources.GetString("Menu.Yes.text");
- this.label6.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Fromtheboundaryvalue.text") + ":";
- this.label5.Text = PdnResources.GetString("Menu.transparency.text") + ":";
- this.label4.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Tilewatermark.text") + ":";
- this.label3.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Watermarkposition.text") + ":";
- this.label2.Text = PdnResources.GetString("Menu.LabelAction.DrawWaterMark.Text") + ":";
- this.groupBox4.Text = PdnResources.GetString("Menu.Set.Watermarksettings.ExtendInformation.text");
- this.checkBox2.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Italic.text");
- this.checkBox1.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Bold.text");
- this.label10.Text = PdnResources.GetString("Menu.color.text") + ":";
- this.label9.Text = PdnResources.GetString("Menu.Fontsize.text") + ":";
- this.label8.Text = PdnResources.GetString("Menu.Font.text") + ":";
- this.radioButton8.Text = PdnResources.GetString("Menu.Set.Watermarksettings.backwardlean.text");
- this.radioButton7.Text = PdnResources.GetString("Menu.Verticaldirection.text");
- this.label7.Text = PdnResources.GetString("Menu.direction.text") + ":";
- this.radioButton5.Text = PdnResources.GetString("Menu.Set.Watermarksettings.battering.text");
- this.radioButton6.Text = PdnResources.GetString("Menu.horizontaldirection.text");
- this.groupBox5.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Watermarkpreview.text");
- this.Text = PdnResources.GetString("Menu.Setting.WatermarkSetting.Text");
- }
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.button4 = new System.Windows.Forms.Button();
- this.button3 = new System.Windows.Forms.Button();
- this.comboBox1 = new System.Windows.Forms.ComboBox();
- this.label1 = new System.Windows.Forms.Label();
- this.button2 = new System.Windows.Forms.Button();
- this.button1 = new System.Windows.Forms.Button();
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.radioButton2 = new System.Windows.Forms.RadioButton();
- this.radioButton1 = new System.Windows.Forms.RadioButton();
- this.groupBox3 = new System.Windows.Forms.GroupBox();
- this.userTextBox1 = new System.Windows.Forms.TextBox();
- this.userTextBox3 = new PaintDotNet.CustomControl.UserTextBox();
- this.button5 = new System.Windows.Forms.Button();
- this.trackBar1 = new System.Windows.Forms.TrackBar();
- this.radioButton3 = new System.Windows.Forms.RadioButton();
- this.userTextBox2 = new PaintDotNet.CustomControl.UserTextBox();
- this.radioButton4 = new System.Windows.Forms.RadioButton();
- this.label6 = new System.Windows.Forms.Label();
- this.comboBox2 = new System.Windows.Forms.ComboBox();
- this.label5 = new System.Windows.Forms.Label();
- this.label4 = new System.Windows.Forms.Label();
- this.label3 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.groupBox4 = new System.Windows.Forms.GroupBox();
- this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
- this.checkBox2 = new System.Windows.Forms.CheckBox();
- this.checkBox1 = new System.Windows.Forms.CheckBox();
- this.panel2 = new System.Windows.Forms.Panel();
- this.label10 = new System.Windows.Forms.Label();
- this.label9 = new System.Windows.Forms.Label();
- this.comboBox3 = new System.Windows.Forms.ComboBox();
- this.label8 = new System.Windows.Forms.Label();
- this.radioButton8 = new System.Windows.Forms.RadioButton();
- this.radioButton7 = new System.Windows.Forms.RadioButton();
- this.label7 = new System.Windows.Forms.Label();
- this.radioButton5 = new System.Windows.Forms.RadioButton();
- this.radioButton6 = new System.Windows.Forms.RadioButton();
- this.groupBox5 = new System.Windows.Forms.GroupBox();
- this.pictureBox2 = new System.Windows.Forms.PictureBox();
- this.groupBox2.SuspendLayout();
- this.groupBox1.SuspendLayout();
- this.groupBox3.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
- this.groupBox4.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
- this.groupBox5.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
- this.SuspendLayout();
- //
- // groupBox2
- //
- this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox2.Controls.Add(this.button4);
- this.groupBox2.Controls.Add(this.button3);
- this.groupBox2.Controls.Add(this.comboBox1);
- this.groupBox2.Controls.Add(this.label1);
- this.groupBox2.Controls.Add(this.button2);
- this.groupBox2.Controls.Add(this.button1);
- this.groupBox2.Location = new System.Drawing.Point(13, 12);
- this.groupBox2.Name = "groupBox2";
- this.groupBox2.Size = new System.Drawing.Size(613, 58);
- this.groupBox2.TabIndex = 2;
- this.groupBox2.TabStop = false;
- //
- // button4
- //
- this.button4.Anchor = System.Windows.Forms.AnchorStyles.Right;
- this.button4.Location = new System.Drawing.Point(361, 21);
- this.button4.Name = "button4";
- this.button4.Size = new System.Drawing.Size(75, 23);
- this.button4.TabIndex = 11;
- this.button4.Text = "另存为";
- this.button4.UseVisualStyleBackColor = true;
- this.button4.Click += new System.EventHandler(this.button4_Click);
- //
- // button3
- //
- this.button3.Anchor = System.Windows.Forms.AnchorStyles.Right;
- this.button3.Location = new System.Drawing.Point(280, 21);
- this.button3.Name = "button3";
- this.button3.Size = new System.Drawing.Size(75, 23);
- this.button3.TabIndex = 10;
- this.button3.Text = "删除";
- this.button3.UseVisualStyleBackColor = true;
- this.button3.Click += new System.EventHandler(this.button3_Click);
- //
- // comboBox1
- //
- this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comboBox1.FormattingEnabled = true;
- this.comboBox1.Location = new System.Drawing.Point(114, 23);
- this.comboBox1.Name = "comboBox1";
- this.comboBox1.Size = new System.Drawing.Size(135, 20);
- this.comboBox1.TabIndex = 9;
- this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(19, 26);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(89, 12);
- this.label1.TabIndex = 2;
- this.label1.Text = "当前操作样式:";
- //
- // button2
- //
- this.button2.Anchor = System.Windows.Forms.AnchorStyles.Right;
- this.button2.Location = new System.Drawing.Point(523, 21);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(75, 23);
- this.button2.TabIndex = 1;
- this.button2.Text = "应用";
- this.button2.UseVisualStyleBackColor = true;
- this.button2.Click += new System.EventHandler(this.button2_Click);
- //
- // button1
- //
- this.button1.Anchor = System.Windows.Forms.AnchorStyles.Right;
- this.button1.Location = new System.Drawing.Point(442, 21);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(75, 23);
- this.button1.TabIndex = 0;
- this.button1.Text = "保存";
- this.button1.UseVisualStyleBackColor = true;
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // groupBox1
- //
- this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox1.Controls.Add(this.radioButton2);
- this.groupBox1.Controls.Add(this.radioButton1);
- this.groupBox1.Location = new System.Drawing.Point(13, 76);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(613, 58);
- this.groupBox1.TabIndex = 3;
- this.groupBox1.TabStop = false;
- this.groupBox1.Text = "类型";
- //
- // radioButton2
- //
- this.radioButton2.AutoSize = true;
- this.radioButton2.Cursor = System.Windows.Forms.Cursors.Hand;
- this.radioButton2.Location = new System.Drawing.Point(284, 26);
- this.radioButton2.Name = "radioButton2";
- this.radioButton2.Size = new System.Drawing.Size(71, 16);
- this.radioButton2.TabIndex = 5;
- this.radioButton2.Text = "图片水印";
- this.radioButton2.UseVisualStyleBackColor = true;
- this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
- //
- // radioButton1
- //
- this.radioButton1.AutoSize = true;
- this.radioButton1.Checked = true;
- this.radioButton1.Cursor = System.Windows.Forms.Cursors.Hand;
- this.radioButton1.Location = new System.Drawing.Point(19, 26);
- this.radioButton1.Name = "radioButton1";
- this.radioButton1.Size = new System.Drawing.Size(71, 16);
- this.radioButton1.TabIndex = 4;
- this.radioButton1.TabStop = true;
- this.radioButton1.Text = "文字水印";
- this.radioButton1.UseVisualStyleBackColor = true;
- this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
- //
- // groupBox3
- //
- this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox3.Controls.Add(this.userTextBox1);
- this.groupBox3.Controls.Add(this.userTextBox3);
- this.groupBox3.Controls.Add(this.button5);
- this.groupBox3.Controls.Add(this.trackBar1);
- this.groupBox3.Controls.Add(this.radioButton3);
- this.groupBox3.Controls.Add(this.userTextBox2);
- this.groupBox3.Controls.Add(this.radioButton4);
- this.groupBox3.Controls.Add(this.label6);
- this.groupBox3.Controls.Add(this.comboBox2);
- this.groupBox3.Controls.Add(this.label5);
- this.groupBox3.Controls.Add(this.label4);
- this.groupBox3.Controls.Add(this.label3);
- this.groupBox3.Controls.Add(this.label2);
- this.groupBox3.Location = new System.Drawing.Point(13, 140);
- this.groupBox3.Name = "groupBox3";
- this.groupBox3.Size = new System.Drawing.Size(613, 167);
- this.groupBox3.TabIndex = 4;
- this.groupBox3.TabStop = false;
- this.groupBox3.Text = "基本信息";
- //
- // userTextBox1
- //
- this.userTextBox1.Location = new System.Drawing.Point(90, 24);
- this.userTextBox1.MaxLength = 50;
- this.userTextBox1.Name = "userTextBox1";
- this.userTextBox1.Size = new System.Drawing.Size(508, 21);
- this.userTextBox1.TabIndex = 23;
- this.userTextBox1.TextChanged += new System.EventHandler(this.userTextBox1_TextChanged_1);
- //
- // userTextBox3
- //
- this.userTextBox3.Location = new System.Drawing.Point(375, 122);
- this.userTextBox3.Name = "userTextBox3";
- this.userTextBox3.ReadOnly = true;
- this.userTextBox3.Size = new System.Drawing.Size(46, 21);
- this.userTextBox3.TabIndex = 22;
- this.userTextBox3.Text = "0";
- //
- // button5
- //
- this.button5.Location = new System.Drawing.Point(523, 23);
- this.button5.Name = "button5";
- this.button5.Size = new System.Drawing.Size(75, 23);
- this.button5.TabIndex = 21;
- this.button5.UseVisualStyleBackColor = true;
- this.button5.Visible = false;
- this.button5.Click += new System.EventHandler(this.button5_Click);
- //
- // trackBar1
- //
- this.trackBar1.Cursor = System.Windows.Forms.Cursors.Hand;
- this.trackBar1.Location = new System.Drawing.Point(78, 116);
- this.trackBar1.Maximum = 255;
- this.trackBar1.Name = "trackBar1";
- this.trackBar1.Size = new System.Drawing.Size(262, 45);
- this.trackBar1.TabIndex = 1;
- this.trackBar1.TickStyle = System.Windows.Forms.TickStyle.None;
- this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll);
- //
- // radioButton3
- //
- this.radioButton3.AutoSize = true;
- this.radioButton3.Location = new System.Drawing.Point(186, 93);
- this.radioButton3.Name = "radioButton3";
- this.radioButton3.Size = new System.Drawing.Size(35, 16);
- this.radioButton3.TabIndex = 7;
- this.radioButton3.Text = "否";
- this.radioButton3.UseVisualStyleBackColor = true;
- this.radioButton3.CheckedChanged += new System.EventHandler(this.radioButton3_CheckedChanged);
- //
- // userTextBox2
- //
- this.userTextBox2.Location = new System.Drawing.Point(382, 58);
- this.userTextBox2.MaxLength = 10;
- this.userTextBox2.Name = "userTextBox2";
- this.userTextBox2.Size = new System.Drawing.Size(216, 21);
- this.userTextBox2.TabIndex = 20;
- this.userTextBox2.TextChanged += new System.EventHandler(this.userTextBox2_TextChanged);
- //
- // radioButton4
- //
- this.radioButton4.AutoSize = true;
- this.radioButton4.Checked = true;
- this.radioButton4.Location = new System.Drawing.Point(90, 93);
- this.radioButton4.Name = "radioButton4";
- this.radioButton4.Size = new System.Drawing.Size(35, 16);
- this.radioButton4.TabIndex = 6;
- this.radioButton4.TabStop = true;
- this.radioButton4.Text = "是";
- this.radioButton4.UseVisualStyleBackColor = true;
- this.radioButton4.CheckedChanged += new System.EventHandler(this.radioButton4_CheckedChanged);
- //
- // label6
- //
- this.label6.AutoSize = true;
- this.label6.Location = new System.Drawing.Point(304, 61);
- this.label6.Name = "label6";
- this.label6.Size = new System.Drawing.Size(65, 12);
- this.label6.TabIndex = 19;
- this.label6.Text = "距边界值:";
- //
- // comboBox2
- //
- this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comboBox2.FormattingEnabled = true;
- this.comboBox2.Location = new System.Drawing.Point(90, 58);
- this.comboBox2.Name = "comboBox2";
- this.comboBox2.Size = new System.Drawing.Size(197, 20);
- this.comboBox2.TabIndex = 18;
- this.comboBox2.SelectedIndexChanged += new System.EventHandler(this.comboBox2_SelectedIndexChanged);
- //
- // label5
- //
- this.label5.AutoSize = true;
- this.label5.Location = new System.Drawing.Point(19, 125);
- this.label5.Name = "label5";
- this.label5.Size = new System.Drawing.Size(53, 12);
- this.label5.TabIndex = 17;
- this.label5.Text = "透明度:";
- //
- // label4
- //
- this.label4.AutoSize = true;
- this.label4.Location = new System.Drawing.Point(19, 93);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(65, 12);
- this.label4.TabIndex = 16;
- this.label4.Text = "平铺水印:";
- //
- // label3
- //
- this.label3.AutoSize = true;
- this.label3.Location = new System.Drawing.Point(19, 61);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(65, 12);
- this.label3.TabIndex = 15;
- this.label3.Text = "水印位置:";
- //
- // label2
- //
- this.label2.AutoSize = true;
- this.label2.Location = new System.Drawing.Point(19, 29);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(41, 12);
- this.label2.TabIndex = 6;
- this.label2.Text = "水印:";
- //
- // groupBox4
- //
- this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox4.Controls.Add(this.numericUpDown1);
- this.groupBox4.Controls.Add(this.checkBox2);
- this.groupBox4.Controls.Add(this.checkBox1);
- this.groupBox4.Controls.Add(this.panel2);
- this.groupBox4.Controls.Add(this.label10);
- this.groupBox4.Controls.Add(this.label9);
- this.groupBox4.Controls.Add(this.comboBox3);
- this.groupBox4.Controls.Add(this.label8);
- this.groupBox4.Controls.Add(this.radioButton8);
- this.groupBox4.Controls.Add(this.radioButton7);
- this.groupBox4.Controls.Add(this.label7);
- this.groupBox4.Controls.Add(this.radioButton5);
- this.groupBox4.Controls.Add(this.radioButton6);
- this.groupBox4.Location = new System.Drawing.Point(13, 313);
- this.groupBox4.Name = "groupBox4";
- this.groupBox4.Size = new System.Drawing.Size(613, 118);
- this.groupBox4.TabIndex = 5;
- this.groupBox4.TabStop = false;
- this.groupBox4.Text = "扩展信息";
- //
- // numericUpDown1
- //
- this.numericUpDown1.Location = new System.Drawing.Point(375, 55);
- this.numericUpDown1.Maximum = new decimal(new int[] {
- 49000,
- 0,
- 0,
- 0});
- this.numericUpDown1.Minimum = new decimal(new int[] {
- 1,
- 0,
- 0,
- 0});
- this.numericUpDown1.Name = "numericUpDown1";
- this.numericUpDown1.Size = new System.Drawing.Size(192, 21);
- this.numericUpDown1.TabIndex = 26;
- this.numericUpDown1.Value = new decimal(new int[] {
- 12,
- 0,
- 0,
- 0});
- this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
- //
- // checkBox2
- //
- this.checkBox2.AutoSize = true;
- this.checkBox2.Location = new System.Drawing.Point(347, 93);
- this.checkBox2.Name = "checkBox2";
- this.checkBox2.Size = new System.Drawing.Size(48, 16);
- this.checkBox2.TabIndex = 25;
- this.checkBox2.Text = "斜体";
- this.checkBox2.UseVisualStyleBackColor = true;
- this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
- //
- // checkBox1
- //
- this.checkBox1.AutoSize = true;
- this.checkBox1.Location = new System.Drawing.Point(284, 93);
- this.checkBox1.Name = "checkBox1";
- this.checkBox1.Size = new System.Drawing.Size(48, 16);
- this.checkBox1.TabIndex = 24;
- this.checkBox1.Text = "粗体";
- this.checkBox1.UseVisualStyleBackColor = true;
- this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
- //
- // panel2
- //
- this.panel2.BackColor = System.Drawing.Color.Transparent;
- this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.panel2.Location = new System.Drawing.Point(66, 88);
- this.panel2.Name = "panel2";
- this.panel2.Size = new System.Drawing.Size(191, 21);
- this.panel2.TabIndex = 23;
- this.panel2.Click += new System.EventHandler(this.panel2_Click);
- //
- // label10
- //
- this.label10.AutoSize = true;
- this.label10.Location = new System.Drawing.Point(19, 90);
- this.label10.Name = "label10";
- this.label10.Size = new System.Drawing.Size(41, 12);
- this.label10.TabIndex = 22;
- this.label10.Text = "颜色:";
- //
- // label9
- //
- this.label9.AutoSize = true;
- this.label9.Location = new System.Drawing.Point(322, 58);
- this.label9.Name = "label9";
- this.label9.Size = new System.Drawing.Size(41, 12);
- this.label9.TabIndex = 20;
- this.label9.Text = "字号:";
- //
- // comboBox3
- //
- this.comboBox3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comboBox3.FormattingEnabled = true;
- this.comboBox3.Location = new System.Drawing.Point(66, 55);
- this.comboBox3.Name = "comboBox3";
- this.comboBox3.Size = new System.Drawing.Size(191, 20);
- this.comboBox3.TabIndex = 19;
- this.comboBox3.SelectedIndexChanged += new System.EventHandler(this.comboBox3_SelectedIndexChanged);
- //
- // label8
- //
- this.label8.AutoSize = true;
- this.label8.Location = new System.Drawing.Point(19, 58);
- this.label8.Name = "label8";
- this.label8.Size = new System.Drawing.Size(41, 12);
- this.label8.TabIndex = 10;
- this.label8.Text = "字体:";
- //
- // radioButton8
- //
- this.radioButton8.AutoSize = true;
- this.radioButton8.Location = new System.Drawing.Point(333, 24);
- this.radioButton8.Name = "radioButton8";
- this.radioButton8.Size = new System.Drawing.Size(71, 16);
- this.radioButton8.TabIndex = 9;
- this.radioButton8.Text = "向后倾斜";
- this.radioButton8.UseVisualStyleBackColor = true;
- this.radioButton8.CheckedChanged += new System.EventHandler(this.radioButton8_CheckedChanged);
- //
- // radioButton7
- //
- this.radioButton7.AutoSize = true;
- this.radioButton7.Location = new System.Drawing.Point(159, 24);
- this.radioButton7.Name = "radioButton7";
- this.radioButton7.Size = new System.Drawing.Size(71, 16);
- this.radioButton7.TabIndex = 8;
- this.radioButton7.Text = "垂直方向";
- this.radioButton7.UseVisualStyleBackColor = true;
- this.radioButton7.CheckedChanged += new System.EventHandler(this.radioButton7_CheckedChanged);
- //
- // label7
- //
- this.label7.AutoSize = true;
- this.label7.Location = new System.Drawing.Point(19, 26);
- this.label7.Name = "label7";
- this.label7.Size = new System.Drawing.Size(41, 12);
- this.label7.TabIndex = 7;
- this.label7.Text = "方向:";
- //
- // radioButton5
- //
- this.radioButton5.AutoSize = true;
- this.radioButton5.Location = new System.Drawing.Point(245, 24);
- this.radioButton5.Name = "radioButton5";
- this.radioButton5.Size = new System.Drawing.Size(71, 16);
- this.radioButton5.TabIndex = 5;
- this.radioButton5.Text = "向前倾斜";
- this.radioButton5.UseVisualStyleBackColor = true;
- this.radioButton5.CheckedChanged += new System.EventHandler(this.radioButton5_CheckedChanged);
- //
- // radioButton6
- //
- this.radioButton6.AutoSize = true;
- this.radioButton6.Checked = true;
- this.radioButton6.Location = new System.Drawing.Point(77, 24);
- this.radioButton6.Name = "radioButton6";
- this.radioButton6.Size = new System.Drawing.Size(71, 16);
- this.radioButton6.TabIndex = 4;
- this.radioButton6.TabStop = true;
- this.radioButton6.Text = "水平方向";
- this.radioButton6.UseVisualStyleBackColor = true;
- this.radioButton6.CheckedChanged += new System.EventHandler(this.radioButton6_CheckedChanged);
- //
- // groupBox5
- //
- this.groupBox5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox5.Controls.Add(this.pictureBox2);
- this.groupBox5.Location = new System.Drawing.Point(13, 437);
- this.groupBox5.Name = "groupBox5";
- this.groupBox5.Size = new System.Drawing.Size(613, 236);
- this.groupBox5.TabIndex = 6;
- this.groupBox5.TabStop = false;
- this.groupBox5.Text = "水印预览";
- //
- // pictureBox2
- //
- this.pictureBox2.Location = new System.Drawing.Point(6, 12);
- this.pictureBox2.Name = "pictureBox2";
- this.pictureBox2.Size = new System.Drawing.Size(601, 218);
- this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
- this.pictureBox2.TabIndex = 1;
- this.pictureBox2.TabStop = false;
- //
- // WatermarkSettingsDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.AutoScroll = true;
- this.ClientSize = new System.Drawing.Size(637, 691);
- this.Controls.Add(this.groupBox5);
- this.Controls.Add(this.groupBox4);
- this.Controls.Add(this.groupBox3);
- this.Controls.Add(this.groupBox1);
- this.Controls.Add(this.groupBox2);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
- this.MaximizeBox = false;
- this.MinimizeBox = false;
- this.Name = "WatermarkSettingsDialog";
- this.Text = "水印设置";
- this.Controls.SetChildIndex(this.groupBox2, 0);
- this.Controls.SetChildIndex(this.groupBox1, 0);
- this.Controls.SetChildIndex(this.groupBox3, 0);
- this.Controls.SetChildIndex(this.groupBox4, 0);
- this.Controls.SetChildIndex(this.groupBox5, 0);
- this.groupBox2.ResumeLayout(false);
- this.groupBox2.PerformLayout();
- this.groupBox1.ResumeLayout(false);
- this.groupBox1.PerformLayout();
- this.groupBox3.ResumeLayout(false);
- this.groupBox3.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
- this.groupBox4.ResumeLayout(false);
- this.groupBox4.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
- this.groupBox5.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
- this.ResumeLayout(false);
- }
- private void InitializeColorForm()
- {
- this.colorsForm = new PaintDotNet.ColorsForm();
- //
- // colorsForm
- //
- this.colorsForm.AnalyzeSettingModel = null;
- this.colorsForm.ClientSize = new System.Drawing.Size(209, 217);
- this.colorsForm.EnableInstanceOpacity = true;
- this.colorsForm.ForceActiveTitleBar = true;
- this.colorsForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
- this.colorsForm.KeyPreview = true;
- this.colorsForm.Location = new System.Drawing.Point(0, 0);
- this.colorsForm.MaximizeBox = false;
- this.colorsForm.MinimizeBox = false;
- this.colorsForm.Name = "colorsForm";
- this.colorsForm.ShowInTaskbar = false;
- this.colorsForm.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
- this.colorsForm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.colorsForm.Visible = false;
- this.colorsForm.WhichUserColor = PaintDotNet.WhichUserColor.Primary;
- this.colorsForm.Load += new System.EventHandler(this.colorsForm_Load);
- }
- private void colorsFormUserPrimaryColorChanged(object sender, ColorEventArgs ce)
- {
- }
- /// <summary>
- /// 画板点击
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void panel2_Click(object sender, EventArgs e)
- {
- this.colorsForm.UserPrimaryColor = ColorBgra.FromColor(this.panel2.BackColor);
- this.colorsForm.setSaveBtn_Click(new System.EventHandler(this.panel2Changed));
- this.colorsForm.ShowDialog();
- }
- private void panel2Changed(object sender, EventArgs e)
- {
- this.panel2.BackColor = this.colorsForm.UserPrimaryColor.ToColor();
- this.watermarkModel.color = Convert.ToInt32(this.panel2.BackColor.ToArgb());
- this.pictureBox2.Invalidate();
- this.colorsForm.Close();
- }
- #endregion
- #endregion
- /// <summary>
- /// 另存为文件名
- /// </summary>
- private string newName;
- /// <summary>
- /// 操作样式下拉数据
- /// </summary>
- private List<string> files = new List<string>();
- private float localX = 0;
- private float localY = 0;
- private WatermarkModel watermarkModel = Startup.instance.watermarkModel;
- /// <summary>
- /// 旋转角度
- /// </summary>
- private int angle = 0;
- /// <summary>
- /// 水印位置下拉选
- /// </summary>
- string[] position = new string[]
- { PdnResources.GetString("Menu.Set.Watermarksettings.Topleft.text"),
- PdnResources.GetString("Menu.Set.Watermarksettings.Topmiddle.text"),
- PdnResources.GetString("Menu.Set.Watermarksettings.Topright.text"),
- PdnResources.GetString("Menu.Set.Watermarksettings.Middleleft.text"),
- PdnResources.GetString("Menu.nthemiddle.Text"),
- PdnResources.GetString("Menu.Set.Watermarksettings.Middleright.text"),
- PdnResources.GetString("Menu.Set.Watermarksettings.Bottomleft.text"),
- PdnResources.GetString("Menu.Set.Watermarksettings.Bottommiddle.text"),
- PdnResources.GetString("Menu.Set.Watermarksettings.Bottomright.text") };
- /// <summary>
- /// 暂存文字水印信息
- /// </summary>
- string waterMarkText = "";
- /// <summary>
- /// 暂存图片水印路径
- /// </summary>
- string waterMarkImagePath = "";
- CreateNameDialog dialog;
- public WatermarkSettingsDialog()
- {
- InitializeComponent();
- InitializeLanguageText();
- InitializeColorForm();
- InitializeControl();
- InitializeData();
- }
- /// <summary>
- /// 处理控件
- /// </summary>
- private void InitializeControl()
- {
- this.pictureBox2.Paint += new PaintEventHandler(this.pictureBox2_Paint);
- }
- /// <summary>
- /// pictureBox的绘制事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void pictureBox2_Paint(object sender, PaintEventArgs e)
- {
- WatermarkModel model = new WatermarkModel();
- model = watermarkModel;
- if (this.checkBox1.Checked)
- {
- model.bold = 1;
- }
- else
- {
- model.bold = 2;
- }
- if (this.checkBox2.Checked)
- {
- model.italic = 1;
- }
- else
- {
- model.italic = 2;
- }
- model.position = this.comboBox2.SelectedIndex + 1;
- model.typeface = this.comboBox3.Text;
- model.fontSize = Int32.Parse(this.numericUpDown1.Value.ToString());
- if (this.radioButton2.Checked)
- {
- //drawWatermarkImage(e.Graphics, model);
- drawWatermarkImage(e.Graphics, model);
- }
- else
- {
- drawWatermarkText(e.Graphics, model);
- }
- }
- /// <summary>
- /// 初始化数据
- /// </summary>
- private void InitializeData()
- {
- //绑定字体下拉
- ArrayList fontsItems = new ArrayList();
- System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection();
- foreach (FontFamily fontFamily in fonts.Families)
- {
- fontsItems.Add(fontFamily.Name);
- }
- this.comboBox3.DataSource = fontsItems;
- //绑定位置下拉
- this.comboBox2.DataSource = position;
- //绑定样式下拉
- InitializeStyleName();
- }
- /// <summary>
- /// 绑定样式下拉
- /// </summary>
- private void InitializeStyleName()
- {
- List<string> fileNames = FileOperationHelper.GetFileList(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Watermark\\");
- files.Clear();
- foreach (string fileName in fileNames)
- {
- string name = fileName.Substring(0, fileName.LastIndexOf("."));
- files.Add(name);
- }
- this.comboBox1.SelectedIndexChanged -= this.comboBox1_SelectedIndexChanged;
- this.comboBox1.DataSource = null;
- this.comboBox1.DataSource = files;
- string nowModelName = Startup.instance.configModel.Watermark.Substring(0, Startup.instance.configModel.Watermark.LastIndexOf("."));
- this.comboBox1.SelectedIndex = files.FindIndex(a => a.Equals(nowModelName));
- watermarkModel = XmlSerializeHelper.DESerializer<WatermarkModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Watermark\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open));
- InitializeWaterData();
- this.comboBox1.SelectedIndexChanged += new EventHandler(this.comboBox1_SelectedIndexChanged);
- }
- /// <summary>
- /// 初始化控件的值
- /// </summary>
- private void InitializeWaterData()
- {
- // 水印类型 1文字水印 2图片水印
- if (this.watermarkModel.watermarkType == 2)
- {
- this.radioButton2.Checked = true;
- }
- else
- {
- this.radioButton1.Checked = true;
- }
- // 水印文字
- this.userTextBox1.Text = this.watermarkModel.content;
- //水印位置
- this.comboBox2.SelectedIndex = this.watermarkModel.position - 1;
- // 距边界值
- this.userTextBox2.Text = this.watermarkModel.margin + "";
- // 平铺水印
- if (this.watermarkModel.spread == 2)
- {
- this.radioButton3.Checked = true;
- }
- else
- {
- this.radioButton4.Checked = true;
- }
- // 透明度
- this.trackBar1.Value = this.watermarkModel.transparency;
- this.userTextBox3.Text = this.watermarkModel.transparency + "";
- // 方向
- switch (this.watermarkModel.direction)
- {
- case 1:
- this.radioButton6.Checked = true;
- break;
- case 2:
- this.radioButton7.Checked = true;
- break;
- case 3:
- this.radioButton5.Checked = true;
- break;
- case 4:
- this.radioButton8.Checked = true;
- break;
- default:
- this.radioButton6.Checked = true;
- break;
- }
- //字体
- this.comboBox3.Text = this.watermarkModel.typeface;
- //字号
- this.numericUpDown1.Value = this.watermarkModel.fontSize;
- // 水印文字-颜色
- this.panel2.BackColor = Color.FromArgb(this.watermarkModel.color);
- // 粗体
- if (this.watermarkModel.bold == 1)
- {
- this.checkBox1.Checked = true;
- }
- // 斜体
- if (this.watermarkModel.italic == 1)
- {
- this.checkBox2.Checked = true;
- }
-
- this.pictureBox2.Invalidate();
- //comboBox1_SelectedIndexChanged(null,null);
- }
- /// <summary>
- /// 当前操作样式
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- watermarkModel = XmlSerializeHelper.DESerializer<WatermarkModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Watermark\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open));
- InitializeWaterData();
- }
- /// <summary>
- /// 文字水印
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void radioButton1_CheckedChanged(object sender, EventArgs e)
- {
- if (radioButton1.Checked)
- {
- waterMarkImagePath = this.userTextBox1.Text;
- this.userTextBox1.Text = waterMarkText;
- this.userTextBox1.ReadOnly = false;
- this.watermarkModel.watermarkType = 1;
- this.groupBox4.Visible = true; // 扩展信息
- this.button5.Visible = false;
- this.userTextBox1.Size = new Size(508, 21);
- this.groupBox5.Location = new System.Drawing.Point(12, 437);
- }
- }
- /// <summary>
- /// 图片水印
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void radioButton2_CheckedChanged(object sender, EventArgs e)
- {
- if (radioButton2.Checked)
- {
- waterMarkText = this.userTextBox1.Text;
- this.userTextBox1.Text = waterMarkImagePath;
- this.userTextBox1.ReadOnly = true;
- this.pictureBox2.Refresh();
- this.watermarkModel.watermarkType = 2;
- this.groupBox4.Visible = false; // 扩展信息
- this.button5.Visible = true;
- this.userTextBox1.Size = new Size(508 - 75, 21);
- this.groupBox5.Location = new System.Drawing.Point(12, 313);
- }
- }
- /// <summary>
- /// 基本信息-水印-水印文字
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void userTextBox1_TextChanged(object sender, EventArgs e)
- {
- }
- /// <summary>
- /// 基本信息-水印-选择图片水印
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button5_Click(object sender, EventArgs e)
- {
- var openFileDialog1 = new OpenFileDialog { Filter = "*.jpg,*jpeg,*.bmp,*.ico,*.png,*.tif,*.wmf|*.jpg;*jpeg;*.bmp;*.ico;*.png;*.tif;*.wmf" };
- if (openFileDialog1.ShowDialog() == DialogResult.OK)
- {
- this.userTextBox1.Text = openFileDialog1.InitialDirectory + openFileDialog1.FileName;
- this.watermarkModel.content = this.userTextBox1.Text;
- Image image = Image.FromFile(openFileDialog1.FileName);
- }
- }
- private void userTextBox1_TextChanged_1(object sender, EventArgs e)
- {
- if (this.watermarkModel.content == "")
- {
- this.watermarkModel.content = this.userTextBox1.Text;
- }
- this.pictureBox2.Invalidate();
- }
- /// <summary>
- /// 基本信息-透明度滑块
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void trackBar1_Scroll(object sender, EventArgs e)
- {
- this.userTextBox3.Text = "" + this.trackBar1.Value;
- this.watermarkModel.transparency = this.trackBar1.Value;
- this.pictureBox2.Invalidate();
- }
- /// <summary>
- /// 距边界值
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void userTextBox2_TextChanged(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(this.userTextBox2.Text))
- {
- MessageBox.Show(PdnResources.GetString("Menu.edistancefromtheboundaryaluecanno.Text"));
- return;
- }
- this.watermarkModel.margin = Int32.Parse(this.userTextBox2.Text);
- this.pictureBox2.Invalidate();
- }
- private void radioButton4_CheckedChanged(object sender, EventArgs e)
- {
- this.watermarkModel.spread = 1;
- this.pictureBox2.Invalidate();
- }
- private void radioButton3_CheckedChanged(object sender, EventArgs e)
- {
- this.watermarkModel.spread = 2;
- this.pictureBox2.Invalidate();
- }
- /// <summary>
- /// 扩展信息-方向- 向前倾斜
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void radioButton5_CheckedChanged(object sender, EventArgs e)
- {
- this.angle = -45;
- this.watermarkModel.direction = 3;
- this.pictureBox2.Invalidate();
- }
- private void radioButton6_CheckedChanged(object sender, EventArgs e)
- {
- this.angle = 0;
- this.watermarkModel.direction = 1;
- this.pictureBox2.Invalidate();
- }
- private void radioButton7_CheckedChanged(object sender, EventArgs e)
- {
- this.angle = 90;
- this.watermarkModel.direction = 2;
- this.pictureBox2.Invalidate();
- }
- private void radioButton8_CheckedChanged(object sender, EventArgs e)
- {
- this.angle = 45;
- this.watermarkModel.direction = 4;
- this.pictureBox2.Invalidate();
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button3_Click(object sender, EventArgs e)
- {
- if ("Default".Equals(this.comboBox1.Text))
- {
- MessageBox.Show(PdnResources.GetString("Menu.efaultstylecannotbedelete.Text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.nfirmthedeleti.Text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
- if (dr == DialogResult.OK)
- {
- int newIndex = 0;
- int selectIndex = this.comboBox1.SelectedIndex;
- int tall = files.Count - 1;
- if (selectIndex < tall)
- {
- newIndex = selectIndex;
- }
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Watermark\\" + this.comboBox1.Text + ".xml";
- FileInfo fileInfo = new FileInfo(filePath);
- fileInfo.Delete();
- InitializeStyleName();
- this.comboBox1.SelectedIndex = newIndex;
- watermarkModel = XmlSerializeHelper.DESerializer<WatermarkModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Watermark\\" + this.comboBox1.SelectedItem.ToString() + ".xml", FileMode.Open));
- InitializeWaterData();
- }
- else if (dr == DialogResult.Cancel)
- {
- }
- }
- /// <summary>
- /// 另存为
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button4_Click(object sender, EventArgs e)
- {
- dialog = new CreateNameDialog(this);
- dialog.Text = PdnResources.GetString("Menu.Set.Watermarksettings.Newstyle.text");
- dialog.StartPosition = FormStartPosition.CenterParent;
- dialog.ShowDialog();
- }
- /// <summary>
- /// 另存配置文件
- /// </summary>
- private void CopyConfigAndRename()
- {
- if (this.checkBox1.Checked)
- {
- this.watermarkModel.bold = 1;
- }
- else
- {
- this.watermarkModel.bold = 2;
- }
- if (this.checkBox2.Checked)
- {
- this.watermarkModel.italic = 1;
- }
- else
- {
- this.watermarkModel.italic = 2;
- }
- this.watermarkModel.content = this.userTextBox1.Text;
- this.watermarkModel.position = this.comboBox2.SelectedIndex + 1;
- this.watermarkModel.typeface = this.comboBox3.Text;
- this.watermarkModel.fontSize = Int32.Parse(this.numericUpDown1.Value.ToString());
- string stageModelXml = XmlSerializeHelper.XmlSerialize<WatermarkModel>(this.watermarkModel);
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Watermark\\" + this.newName + ".xml";
- FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create);
- }
- /// <summary>
- /// 保存当前配置文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, EventArgs e)
- {
- if (this.checkBox1.Checked)
- {
- this.watermarkModel.bold = 1;
- }
- else
- {
- this.watermarkModel.bold = 2;
- }
- if (this.checkBox2.Checked)
- {
- this.watermarkModel.italic = 1;
- }
- else
- {
- this.watermarkModel.italic = 2;
- }
- this.watermarkModel.content = this.userTextBox1.Text;
- this.watermarkModel.position = this.comboBox2.SelectedIndex + 1;
- this.watermarkModel.typeface = this.comboBox3.Text;
- this.watermarkModel.fontSize = Int32.Parse(this.numericUpDown1.Value.ToString());
- string stageModelXml = XmlSerializeHelper.XmlSerialize<WatermarkModel>(this.watermarkModel);
- string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Watermark\\" + this.comboBox1.Text + ".xml";
- FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create);
- this.pictureBox2.Invalidate();
- }
- /// <summary>
- /// 应用当前的水印配置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button2_Click(object sender, EventArgs e)
- {
- Startup.instance.watermarkModel = this.watermarkModel;
- Startup.instance.watermarkModel = this.watermarkModel;
- }
- public override void GetCreateName(string name)
- {
- this.newName = name;
- if (files.Contains(this.newName))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Stylenamecannotberepeated.text"), PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- CopyConfigAndRename();
- InitializeStyleName();
- dialog.Close();
- }
- private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
- {
- this.pictureBox2.Invalidate();
- }
- private void checkBox1_CheckedChanged(object sender, EventArgs e)
- {
- this.pictureBox2.Invalidate();
- }
- private void checkBox2_CheckedChanged(object sender, EventArgs e)
- {
- this.pictureBox2.Invalidate();
- }
- private void numericUpDown1_ValueChanged(object sender, EventArgs e)
- {
- this.pictureBox2.Invalidate();
- }
- /// <summary>
- /// 绘制水印-文字
- /// </summary>
- /// <param name="graphics">画布</param>
- /// <param name="model">水印信息</param>
- public void drawWatermarkText(Graphics graphics, WatermarkModel model)
- {
- int width = this.pictureBox2.Width;
- int height = this.pictureBox2.Height;
- int padding = model.margin;
- string text = model.content;
- string fontVal = model.typeface; // 字体
- int fontSize = model.fontSize * 2; // 字号
- int transparency = model.transparency;// 透明度
- Color color = Color.FromArgb(transparency, Color.FromArgb(model.color));// 颜色
- Font font = new Font(fontVal, fontSize, GraphicsUnit.Pixel);
- if (model.bold == 1)
- {
- font = new Font(fontVal, fontSize, FontStyle.Bold, GraphicsUnit.Pixel);//粗体
- }
- if (model.italic == 1)
- {
- font = new Font(fontVal, fontSize, FontStyle.Italic, GraphicsUnit.Pixel);//斜体
- }
- if (model.italic == 1 && model.bold == 1)
- {
- font = new Font(fontVal, fontSize, FontStyle.Bold | FontStyle.Italic, GraphicsUnit.Pixel);//加粗斜体
- }
- //获取可以用来绘制水印图片的有效区域
- Rectangle validRect = new Rectangle(padding, padding, width - padding * 2, height - padding * 2);
- if (model.spread == 2)
- {
- SizeF sf = graphics.MeasureString(text, font); //获取需要绘制的字符串大小
- StringFormat format = GetStringFormat(model.position, sf.Width, sf.Height, this.pictureBox2.Width, this.pictureBox2.Height, model.margin); //获取绘画水印文字的格式,即文字对齐方式
- Matrix mtxSave = graphics.Transform; //原始旋转矩阵
- Matrix matrix = graphics.Transform;
- matrix.RotateAt((float)angle, new PointF(localX + sf.Width / 2, localY + sf.Height / 2));
- graphics.Transform = matrix;
- graphics.DrawString(text, font, new SolidBrush(color), localX, localY);
- graphics.Transform = mtxSave; //还原为原始旋转矩阵
- //graphics.DrawString(text, font, new SolidBrush(color), validRect, format);
- }
- else if (model.spread == 1)
- {
- float textLength = font.Size * text.Length + 30;
- float xpos = 0;
- float ypos = 0;
- // 倾斜
- graphics.RotateTransform(this.angle);
- // 循环打印文字水印
- for (float i = -width / 2; i < width * 1.5; i = i + textLength)
- {
- xpos = i;
- for (float j = -3 * height; j < height * 2.5; j += 50)
- {
- ypos = j;
- graphics.DrawString(text, font, new SolidBrush(color), xpos, ypos);
- }
- }
- }
- }
- /// <summary>
- /// 获取文字水印位置
- /// </summary>
- /// <param name="pos">
- /// 左顶,顶中,右顶,左中,居中,右中,左底,底中,右底
- /// 1左上,2中上,3右上
- /// 4左中,5中, 6右中
- /// 7左下,8中下,9右下
- /// </param>
- /// <returns></returns>
- public StringFormat GetStringFormat(int pos, float textwidth, float textheigth, int width, int heigth, int margin)
- {
- StringFormat format = new StringFormat();
- switch (pos)
- {
- case 1:
- format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Near;
- localX = margin;
- localY = margin;
- break;
- case 2:
- format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Near;
- localX = (width - 2 * margin) / 2 - textwidth / 2;
- localY = margin;
- break;
- case 3:
- format.Alignment = StringAlignment.Far; format.LineAlignment = StringAlignment.Near;
- localX = (width - 2 * margin) - textwidth;
- localY = margin;
- break;
- case 4:
- format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Center;
- localX = margin;
- localY = (heigth - 2 * margin) / 2 - textheigth / 2;
- break;
- case 5:
- localX = (width - 2 * margin) / 2 - textwidth / 2;
- localY = (heigth - 2 * margin) / 2 - textheigth / 2;
- break;
- case 6:
- format.Alignment = StringAlignment.Far; format.LineAlignment = StringAlignment.Center;
- localX = (width - 2 * margin) - textwidth;
- localY = (heigth - 2 * margin) / 2 - textheigth / 2;
- break;
- case 7:
- format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Far;
- localX = margin;
- localY = (heigth - 2 * margin) - textheigth;
- break;
- case 8:
- format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Far;
- localX = (width - 2 * margin) / 2 - textwidth / 2;
- localY = (heigth - 2 * margin) - textheigth;
- break;
- case 9:
- format.Alignment = StringAlignment.Far; format.LineAlignment = StringAlignment.Far;
- localX = (width - 2 * margin) - textwidth;
- localY = (heigth - 2 * margin) - textheigth;
- break;
- default:
- format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center;
- break;
- }
- return format;
- }
- /// <summary>
- /// 图片透明度属性
- /// </summary>
- /// <param name="opcity"></param>
- /// <returns></returns>
- public ImageAttributes GetAlphaImgAttr(int opcity)
- {
- if (opcity < 0 || opcity > 255)
- {
- throw new ArgumentOutOfRangeException("opcity 值为 0~255");
- }
- //颜色矩阵
- float[][] matrixItems =
- {
- new float[]{1,0,0,0,0},
- new float[]{0,1,0,0,0},
- new float[]{0,0,1,0,0},
- new float[]{0,0,0,(float)opcity / 255, 0},
- new float[]{0,0,0,0,1}
- };
- ColorMatrix colorMatrix = new ColorMatrix(matrixItems);
- ImageAttributes imageAtt = new ImageAttributes();
- imageAtt.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
- return imageAtt;
- }
- private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
- {
- this.pictureBox2.Invalidate();
- }
- /// <summary>
- /// 绘制水印-图片
- /// </summary>
- /// <param name="graphics">画布</param>
- /// <param name="model">水印信息</param>
- public void drawWatermarkImage(Graphics graphics, WatermarkModel watermarkModel)
- {
- string waterPath = watermarkModel.content;
- int position = watermarkModel.position; // 设置水印位置,1左上,2中上,3右上,4左中,5中, 6右中,7左下,8中下,9右下
- int padding = watermarkModel.margin;
- int opcity = watermarkModel.transparency;
- Image waterImage = null;
- if (string.IsNullOrEmpty(waterPath))
- {
- return;
- }
- try
- {
- waterImage = Image.FromFile(waterPath, false); //获取水印图片
- }
- catch (Exception)
- {
- return;
- }
- var waterRect = new Rectangle(0, 0, waterImage.Width, waterImage.Height);
- if (opcity <= 0)
- {
- return;
- }
- Rectangle validRect = new Rectangle(padding, padding, this.pictureBox2.Width - padding * 2, this.pictureBox2.Height - padding * 2); //获取可以用来绘制水印图片的有效区域
- ImageAttributes imageAtt = GetAlphaImgAttr(opcity);
- Rectangle destRect = GetRectangleByPostion(validRect, waterRect, position); //计算水印图片的绘制位置
- if (watermarkModel.spread == 2) // 非水印平铺
- {
- //Rectangle destRect = GetRectangleByPostion(validRect, waterRect, position); //计算水印图片的绘制位置
- if (opcity == 255) //如果不透明度=100,那么直接将水印画到当前画布上.
- {
- graphics.DrawImage(waterImage, destRect, waterRect, GraphicsUnit.Pixel);
- }
- else //如果不透明度在0到255之间,设置透明参数
- {
- graphics.DrawImage(waterImage, destRect, 0, 0, waterRect.Width, waterRect.Height, GraphicsUnit.Pixel, imageAtt);//将水印图片画到画布上
- }
- }
- else if (watermarkModel.spread == 1) // 水印平铺
- {
- int width = this.pictureBox2.Width;
- int height = this.pictureBox2.Height;
- float imageLength = waterImage.Width + 10;
- float imageHeight = waterImage.Height + 10;
- float xpos = 0;
- float ypos = 0;
- // 循环打印文字水印
- for (float i = watermarkModel.margin; i <= width; i += imageLength)
- {
- xpos = i;
- for (float j = watermarkModel.margin; j <= height; j += imageHeight)
- {
- ypos = j;
- destRect.X = (int)xpos;
- destRect.Y = (int)ypos;
- graphics.DrawImage(waterImage, destRect, 0, 0, waterRect.Width, waterRect.Height, GraphicsUnit.Pixel, imageAtt);//将水印图片画到画布上
- }
- }
- }
- }
- /// <summary>
- /// 获取图片水印位置,及small在big里的位置
- /// 如果small的高度大于big的高度,返回big的高度
- /// 如果small的宽度大于big的宽度,返回big的宽度
- /// </summary>
- /// <param name="pos">
- /// 1左上,2中上,3右上
- /// 4左中,5中, 6右中
- /// 7左下,8中下,9右下
- /// </param>
- /// <returns></returns>
- public Rectangle GetRectangleByPostion(Rectangle big, Rectangle small, int pos)
- {
- if (big.Width < small.Width)
- {
- small.Width = big.Width;
- }
- if (big.Height < small.Height)
- {
- small.Height = big.Height;
- }
- Rectangle retVal = small;
- switch (pos)
- {
- case 1: retVal.X = 0; retVal.Y = 0; break;
- case 2: retVal.X = (big.Width - small.Width) / 2; retVal.Y = 0; break;
- case 3: retVal.X = big.Width - small.Width; retVal.Y = 0; break;
- case 4: retVal.X = 0; retVal.Y = (big.Height - small.Height) / 2; break;
- case 6: retVal.X = big.Width - small.Width; retVal.Y = (big.Height - small.Height) / 2; break;
- case 7: retVal.X = 0; retVal.Y = big.Height - small.Height; break;
- case 8: retVal.X = (big.Width - small.Width) / 2; retVal.Y = big.Height - small.Height; break;
- case 9: retVal.X = big.Width - small.Width; retVal.Y = big.Height - small.Height; break;
- default: retVal.X = (big.Width - small.Width) / 2; retVal.Y = (big.Height - small.Height) / 2; break;
- }
- retVal.X += big.X;
- retVal.Y += big.Y;
- return retVal;
- }
- private void colorsForm_Load(object sender, EventArgs e)
- {
- }
- }
- }
|