Utilities.cs
上传用户:hbhltzc
上传日期:2022-06-04
资源大小:1925k
文件大小:2k
源码类别:

xml/soap/webservice

开发平台:

Visual C++

  1. using System;
  2. using System.Xml;
  3. using System.Text;
  4. using System.Runtime.InteropServices;
  5. using System.Windows.Forms;
  6. using System.Drawing;
  7. namespace XmlNotepad
  8. {
  9.     public sealed class Utilities
  10.     {
  11.         private Utilities() { }
  12.         public static void InitializeWriterSettings(XmlWriterSettings settings, IServiceProvider sp) {
  13.             settings.CheckCharacters = false;
  14.             settings.Indent = true;
  15.             settings.IndentChars = "  ";
  16.             settings.NewLineChars = "rn";
  17.             settings.NewLineHandling = NewLineHandling.Replace;
  18.             if (sp != null) {
  19.                 Settings s = (Settings)sp.GetService(typeof(Settings));
  20.                 if (s != null) {
  21.                     settings.Indent = (bool)s["AutoFormatOnSave"];
  22.                     IndentChar indentChar = (IndentChar)s["IndentChar"];
  23.                     int indentLevel = (int)s["IndentLevel"];
  24.                     char ch = (indentChar == IndentChar.Space) ? ' ' : 't';
  25.                     settings.IndentChars = new string(ch, indentLevel);
  26.                     settings.NewLineChars = (string)s["NewLineChars"];
  27.                 }
  28.             }
  29.         }
  30.         
  31.         // Lighten up the given baseColor so it is easy to read on the system Highlight color background.
  32.         public static Brush HighlightTextBrush(Color baseColor) {
  33.             SolidBrush ht = SystemBrushes.Highlight as SolidBrush;
  34.             Color selectedColor = ht != null ? ht.Color : Color.FromArgb(49, 106, 197);
  35.             HLSColor cls = new HLSColor(baseColor);
  36.             HLSColor hls = new HLSColor(selectedColor);
  37.             int luminosity = (hls.Luminosity > 120) ? 20 : 220;
  38.             return new SolidBrush(HLSColor.ColorFromHLS(cls.Hue, luminosity, cls.Saturation));
  39.         }
  40.         public static void OpenUrl(IntPtr hwnd, string url) {
  41.             const int SW_SHOWNORMAL = 1;
  42.             ShellExecute(hwnd, "open", url, null, Application.StartupPath, SW_SHOWNORMAL);
  43.         }
  44.         [DllImport("Shell32.dll", EntryPoint = "ShellExecuteA",
  45.              SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true,
  46.              CallingConvention = CallingConvention.StdCall)]
  47.         static extern int ShellExecute(IntPtr handle, string verb, string file,
  48.             string args, string dir, int show);
  49.     }
  50.     public static class CurrentEvent {
  51.         public static EventArgs Event;
  52.     }
  53. }