//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Pdf.AcroForms;usingGrapeCity.Documents.Pdf.Actions;usingGrapeCity.Documents.Pdf.Annotations;usingGrapeCity.Documents.Text;usingSystem.Drawing;usingSystem.IO; namespaceDsPdfWeb.Demos{ // This sample is similar to the FormSubmit sample, but adds ActionSound to the// form submit and form reset buttons, so that the user gets audible feedback// when they submit or reset the form.// Note that if you download this sample and run it in standalone mode,// you will need to update the submission URL so that it points to a valid server.publicclassFormSubmitSound {publicintCreatePDF(Stream stream) {var doc = newGcPdfDocument();var page = doc.NewPage(); var rc = Common.Util.AddNote("As in the 'Submit Form' sample, the Submit button's Activate is associated with ActionSubmitForm, " +"and the Reset button's Activate is associated with ActionResetForm. " +"\nIn addition to these handlers, in this sample the buttons' MouseDown events are associated with ActionSound, " +"so that the user gets appropriate audible feedback when clicking the button.", page); var g = page.Graphics;var tf = newTextFormat() { Font = StandardFonts.Times, FontSize = 14 };var ip = newPointF(72, rc.Bottom + 36);float fldOffset = 72 * 2 + 46;float fldHeight = tf.FontSize * 1.2f;float dY = 32; // Text field: g.DrawString("First name:", tf, ip);var fldFirstName = newTextField() { Name = "FirstName", Value = "John" }; fldFirstName.Widget.Page = page; fldFirstName.Widget.Rect = newRectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight); fldFirstName.Widget.DefaultAppearance.Font = tf.Font; fldFirstName.Widget.DefaultAppearance.FontSize = tf.FontSize; doc.AcroForm.Fields.Add(fldFirstName); ip.Y += dY; // Text field: g.DrawString("Last name:", tf, ip);var fldLastName = newTextField() { Name = "LastName", Value = "Smith" }; fldLastName.Widget.Page = page; fldLastName.Widget.Rect = newRectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight); fldLastName.Widget.DefaultAppearance.Font = tf.Font; fldLastName.Widget.DefaultAppearance.FontSize = tf.FontSize; doc.AcroForm.Fields.Add(fldLastName); ip.Y += dY; // Checkbox: g.DrawString("Subscribe to Mailing List:", tf, ip);var fldCheckbox = newCheckBoxField() { Name = "Subscribe", Checked = true }; fldCheckbox.Widget.Page = page; fldCheckbox.Widget.Rect = newRectangleF(ip.X + fldOffset, ip.Y, fldHeight, fldHeight); doc.AcroForm.Fields.Add(fldCheckbox); ip.Y += dY; // Multiline TextBox: g.DrawString("Additional information:", tf, ip);var fldAdditionalInfo = newTextField() { Name = "AdditionalInfo", Multiline = true }; fldAdditionalInfo.Widget.Page = page; fldAdditionalInfo.Widget.Rect = newRectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight * 2); fldAdditionalInfo.Widget.DefaultAppearance.Font = tf.Font; fldAdditionalInfo.Widget.DefaultAppearance.FontSize = tf.FontSize; doc.AcroForm.Fields.Add(fldAdditionalInfo); ip.Y += dY * 2; // Submit form button:var btnSubmit = newPushButtonField(); btnSubmit.Widget.Rect = newRectangleF(ip.X + fldOffset, ip.Y, 72, fldHeight); btnSubmit.Widget.ButtonAppearance.Caption = "Submit"; btnSubmit.Widget.Highlighting = HighlightingMode.Invert; btnSubmit.Widget.Page = page;// The URL for the submission: btnSubmit.Widget.Activate = newActionSubmitForm("/Samples/HandleFormSubmitFields");// Also, associated the MouseDown event with a confirmation sound: btnSubmit.Widget.Events.MouseDown = newActionSound(SoundObject.FromFile(Path.Combine("Resources", "Sounds", "form-submitted.wav"))); doc.AcroForm.Fields.Add(btnSubmit); // Reset form button:var btnReset = newPushButtonField(); btnReset.Widget.Rect = newRectangleF(ip.X + fldOffset + 72 * 1.5f, ip.Y, 72, fldHeight); btnReset.Widget.ButtonAppearance.Caption = "Reset"; btnReset.Widget.Highlighting = HighlightingMode.Invert; btnReset.Widget.Page = page;// Reset the form on button activation: btnReset.Widget.Activate = newActionResetForm();// Also, associated the MouseDown event with a confirmation sound: btnReset.Widget.Events.MouseDown = newActionSound(SoundObject.FromFile(Path.Combine("Resources", "Sounds", "form-reset.wav"))); doc.AcroForm.Fields.Add(btnReset); ip.Y += dY; // Done: doc.Save(stream);return doc.Pages.Count; } }}