ÿþusing System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Reflection; using System.Runtime.InteropServices; using System.Drawing; using System.IO; using System.Diagnostics; using System.Net; using System.Collections.Specialized; using System.Net.Sockets; using System.Security.Principal; using HotelPms.Share.Windows.Component; using Microsoft.Win32; namespace HotelPms.Share.Windows.Util { /// ****************************** Description ******************************* /// Ç%·0¹0Æ0à0 Tðy /// 0Nl(u¯0é0¹0 /// Ç%‚i‰ /// 0ˆ0O0OF0¢•peƖ /// 0û0‡eW[R¢•pe(w•U00SQLybk‡eW[ÖN) /// û0Inch0cm0dot YÛc /// 0û0 /// Ç%e\tk /// 020070803 \(g0ÝRŸ °e‰\Ob /// 20071015 y0u nœU SqlStrEscape_All(),sqlStrEscape_SingleQuoteý R0 0' 0Ò! 0'' 0j0i00¨0¹0±0ü0×0æQt0 /// ****************************** Declarations ****************************** public class GeneralSub { /// <summary> /// 1 Inch = 2.54 Cm /// </summary> public const float INCH_TO_CM = 2.54F; public const int WM_COPYDATA = 0x004A; private const int GW_HWNDFIRST = 0; private const int GW_HWNDLAST = 1; private const int GW_HWNDNEXT = 2; private const int GW_HWNDPREV = 3; [DllImport("User32.Dll")] public static extern void GetWindowText(int h, StringBuilder s, int nMaxCount); [DllImport("user32")] private static extern int GetWindow(int hwnd, int wCmd); [StructLayout(LayoutKind.Sequential)] public struct COPYDATASTRUCT { public IntPtr dwData; public int cbData; [MarshalAs(UnmanagedType.LPStr)] public string lpData; } [DllImport("User32.dll", EntryPoint = "SendMessage")] private static extern int SendMessage( int hWnd, // handle to destination window int Msg, // message int wParam, // first message parameter ref COPYDATASTRUCT lParam // second message parameter ); private const int WS_SHOWNORMAL = 1; private const Int32 AW_BLEND = 0x00080000; [System.Runtime.InteropServices.DllImport("user32.dll")] private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow); [System.Runtime.InteropServices.DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr hWnd); [System.Runtime.InteropServices.DllImport("user32.dll")] private static extern void SendMessageA(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam); [System.Runtime.InteropServices.DllImport("user32.dll")] private extern static IntPtr FindWindow(string lpClassName, string lpWindowName); [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int wndproc); [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern int GetWindowLong(IntPtr hWnd, int nIndex); public const int GWL_STYLE = -16; public const int WS_DISABLED = 0x8000000; [DllImport("user32.dll", SetLastError = true)] private static extern IntPtr GetSystemMenu(IntPtr hwnd, bool bRevert); [DllImport("user32.dll", SetLastError = true)] private static extern int GetMenuItemCount(IntPtr hMenu); [DllImport("user32.dll", SetLastError = true)] private static extern int RemoveMenu(IntPtr hMenu, int uPosition, int uFlags); private const int MF_BYPOSITION = 0x00000400; private static string SqlLimitChar = "',%[_"; //SQLybk‡eW[  0ÿ;ÿ?ÿ [DllImport("shfolder.dll", CharSet = CharSet.Auto)] private static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder, IntPtr hToken, int dwFlags, StringBuilder lpszPath); private const int MAX_PATH = 260; private const int CSIDL_COMMON_DESKTOPDIRECTORY = 0x0019; public static string GetAllUsersDesktopFolderPath() { StringBuilder sbPath = new StringBuilder(MAX_PATH); SHGetFolderPath(IntPtr.Zero, CSIDL_COMMON_DESKTOPDIRECTORY, IntPtr.Zero, 0, sbPath); return sbPath.ToString(); } [DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")] public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize); /// <summary> /// /// </summary> public static void FreeMemory() { GC.Collect(); GC.WaitForPendingFinalizers(); if (Environment.OSVersion.Platform == PlatformID.Win32NT) { SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1); } } /// <summary> /// Windown0óS Nn0×Ü0¿0ó0’0!q¹Rk0Y0‹0 /// </summary> /// <param name="form"></param> public static void DisableFormSysMenuCloseButton(Form form) { IntPtr hWindow = form.Handle; IntPtr hMenu = GetSystemMenu(hWindow, false); int count = GetMenuItemCount(hMenu); RemoveMenu(hMenu, count - 1, MF_BYPOSITION); RemoveMenu(hMenu, count - 2, MF_BYPOSITION); } /// <summary> /// APIg0³0ó0È0í0ü0ë0’0 g¹Rû0!q¹Rk0Y0‹0 /// </summary> /// <param name="c"></param> /// <param name="enabled"></param> public static void SetControlEnabled(Control c, bool enabled) { if (enabled) { SetWindowLong(c.Handle, GWL_STYLE, (~WS_DISABLED) & GetWindowLong(c.Handle, GWL_STYLE)); } else { SetWindowLong(c.Handle, GWL_STYLE, WS_DISABLED | GetWindowLong(c.Handle, GWL_STYLE)); } } #region &&&0Format¢•pe¤0&&& /// <summary> /// "0"g0_pe’0Format /// </summary> /// <param name="hoObj">hoObj</param> /// <param name="MaxLenth">úQ›Rw•U0</param> /// <returns>string</returns> public static string Format(object hoObj, int MaxLenth) { return Format(hoObj, MaxLenth, '0', true); } /// <summary> /// cš[‡eW[g0_pe’0Format /// </summary> /// <param name="hoObj">hoObj</param> /// <param name="MaxLenth">úQ›Rw•U0</param> /// <param name="formatChar">cš[‡eW[</param> /// <returns>string</returns> public static string Format(object hoObj, int MaxLenth, char formatChar) { return Format(hoObj, MaxLenth, formatChar, true); } /// <summary> /// cš[‡eW[g0_pe’0Format /// </summary> /// <param name="hoObj">hoObj</param> /// <param name="MaxLenth">úQ›Rw•U0</param> /// <param name="formatChar">cš[‡eW[</param> /// <param name="IsBeforeAdd">...</param> /// <returns>string</returns> public static string Format(object hoObj, int MaxLenth, char formatChar, bool IsBeforeAdd) { try { string wsRet = hoObj.ToString(); int wiLen = wsRet.Length; string wsFormat = new string(formatChar, MaxLenth); if (IsBeforeAdd == true) { wsRet = wsFormat + wsRet; wsRet = wsRet.Substring(wiLen); } else { wsRet = wsRet + wsFormat; wsRet = wsRet.Substring(0, MaxLenth); } return wsRet; } catch { return ""; } } #endregion /// <summary> /// Tðyg0³0ó0È0í0ü0ë0’0ÖS—_Y0‹0 /// </summary> /// <param name="classInstance">classInstance(controlName’0cc0f0D0‹0¯0é0¹0)</param> /// <param name="controlName">controlName</param> /// <returns>object</returns> public static object GetControlByName(object classInstance, string controlName) { try { //return classInstance.GetType().GetField(controlName, //System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(classInstance); return classInstance.GetType().GetField(controlName, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(classInstance); } catch { return null; } } /// <summary> /// ¯0é0¹0 Tg0CreateInstance /// </summary> /// <param name="hoObj">hoObj</param> /// <returns>string</returns> public static object? ClassForName(string codeBase, string hsClsName) { System.Reflection.Assembly woAssem = null; Type woType = null; try { woAssem = System.Reflection.Assembly.Load(codeBase); woType = woAssem.GetType(hsClsName); return Activator.CreateInstance(woType); } catch { return null; } } /// <summary> /// ¯0é0¹0 Tg0CreateInstance /// </summary> /// <param name="hoObj">hoObj</param> /// <returns>string</returns> public static object? ClassForName(string hsClsName) { return ClassForName(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, hsClsName); } /// <summary> /// Call static member function by name /// </summary> /// <param name="codeBase">í0ü0É0Y0‹0 Assembly T</param> /// <param name="className">¯0é0¹0 T</param> /// <param name="memberName">static member T</param> /// <param name="memberName">_pe</param> /// <returns>object</returns> public static object CallStaticMember(string codeBase, string className, string memberName, object[] paraList) { System.Reflection.Assembly woAssem = null; Type woType = null; try { woAssem = System.Reflection.Assembly.Load(codeBase); woType = woAssem.GetType(className); return woType.InvokeMember(memberName, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null, paraList); } catch { return null; } } /// <summary> /// /// </summary> /// <param name="codebase">Projectn0 Tðyÿ‹OH0p0 Forms0Lib</param> /// <param name="clsName"></param> /// <returns></returns> public static string GetCloneCode(string codebase, string clsName) { object item = ClassForName(codebase, clsName); Type woType = item.GetType(); FieldInfo[] woFields = woType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static); string ret = string.Empty; for (int i = 0; i < woFields.Length; i++) { int len = woFields[i].Name.Length; string name = woFields[i].Name.Substring(0, 1).ToUpper() + woFields[i].Name.Substring(1); if (name.StartsWith("M_")) { name = name.Substring(2); } if (woFields[i].FieldType.FullName.Contains("System.Collections.Generic.List")) { ret += string.Format("item.{0} = new List<{0}>(); ", name) + Environment.NewLine; } else { ret += string.Format("item.{0} = {1}; ", name, woFields[i].Name) + Environment.NewLine; } } return ret; } /// <summary> /// /// </summary> /// <param name="codebase">Projectn0 Tðyÿ‹OH0p0 Forms0Lib</param> /// <param name="clsName"></param> /// <returns></returns> public static string GetConvertDataRowCode(string codebase, string clsName) { object item = ClassForName(codebase, clsName); Type woType = item.GetType(); FieldInfo[] woFields = woType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static); string ret = string.Empty; for (int i = 0; i < woFields.Length; i++) { //int len = woFields[i].Name.Length; string name = woFields[i].Name.Replace("m_", ""); name = name.Substring(0, 1).ToUpper() + name.Substring(1); if (woFields[i].FieldType.FullName.Contains("System.Collections.Generic.List")) { continue; } if (woFields[i].FieldType.FullName.Contains("System.Data.DataSet")) { continue; } if ("System.Boolean".Equals(woFields[i].FieldType.FullName)) { ret += string.Format("this.{1} = CConvert.ToBool(row[\"{0}\"]); ", name, woFields[i].Name) + Environment.NewLine; } else if ("System.Decimal".Equals(woFields[i].FieldType.FullName)) { ret += string.Format("this.{1} = CConvert.ToDecimal(row[\"{0}\"]); ", name, woFields[i].Name) + Environment.NewLine; } else if ("System.Int32".Equals(woFields[i].FieldType.FullName)) { ret += string.Format("this.{1} = CConvert.ToInt(row[\"{0}\"],{1}); ", name, woFields[i].Name) + Environment.NewLine; } else if ("System.String".Equals(woFields[i].FieldType.FullName)) { ret += string.Format("this.{1} = row[\"{0}\"].ToString(); ", name, woFields[i].Name) + Environment.NewLine; } else if ("System.DateTime".Equals(woFields[i].FieldType.FullName)) { ret += string.Format("this.{1} = row.IsNull(\"{0}\") ? DateTime.MinValue : (System.DateTime)row[\"{0}\"]; ", name, woFields[i].Name) + Environment.NewLine; } else { ret += string.Format("this.{1} = ({2})ConvertDBValue(row[\"{0}\"],{1}); ", name, woFields[i].Name, woFields[i].FieldType.FullName) + Environment.NewLine; } } return ret; } /// <summary> þ[aŒ³0ó0È0í0ü0ë0…Qn0hQf0n0³0ó0È0í0ü0ë0n0Rc /// </summary> /// <param name="top">Q0^Y0‹0gRn0³0ó0È0í0ü0ë0</param> /// <returns>³0ó0È0í0ü0ë0n0ê0¹0È0</returns> public static string GetFormAllControlCode(Control top) { //System.Collections.ArrayList buf = new System.Collections.ArrayList(); StringBuilder buf = new StringBuilder(); foreach (Control c in top.Controls) { if (c.Name.Length == 0) { continue; } buf.AppendLine(string.Format(" case \"{0}\":", c.Name)); buf.AppendLine(string.Format(" return {0};", c.Name)); if (c.Controls.Count > 0) { buf.AppendLine(""); buf.AppendLine(string.Format(" #region {0}", c.Name)); buf.Append(GetFormAllControlCode(c)); buf.AppendLine(" #endregion"); buf.AppendLine(""); } } return buf.ToString(); } /// <summary>SQLybk‡eW[ Ç0ü0¿0Ù0ü0¹0æQtþ[Ü_n0ºpn0‡eW[ YÛc ''h0[]g0òV€0 /// </summary> /// <param name="InString"></param> /// <returns></returns> public static string sqlStrEscape_All(string InString) { string tmpString = string.Empty; string outString = string.Empty; for (int i = 0; i < InString.ToString().Length; i++) { tmpString = InString.ToString().Substring(i, 1); switch (tmpString.ToString()) { // INSERT , UPDATE , SELECT ( 0= 0 0LIKE 0h0‚0k0Å_‰) j0i0k0f0 YÛcL0Å_‰ case "'": tmpString = tmpString.ToString().Replace("'", "''"); break; // SELECT ( 0LIKE 0O(uBfk0Å_‰)k0f0 YÛcL0Å_‰ case "%": tmpString = tmpString.ToString().Replace("%", "[%]"); break; case "[": tmpString = tmpString.ToString().Replace("[", "[[]"); break; case "_": tmpString = tmpString.ToString().Replace("_", "[_]"); break; default: break; } outString = outString + tmpString.ToString(); } return outString; } /// <summary>SQLybk‡eW[ Ç0ü0¿0Ù0ü0¹0æQtþ[Ü_n0ºpn0‡eW[ YÛc( 0' 0Ò! 0'' 0n00 ÿ /// </summary> /// <param name="InString"></param> /// <returns></returns> public static string sqlStrEscape_SingleQuote(string InString) { string tmpString = string.Empty; string outString = string.Empty; for (int i = 0; i < InString.ToString().Length; i++) { tmpString = InString.ToString().Substring(i, 1); switch (tmpString.ToString()) { // INSERT , UPDATE , SELECT ( 0= 0h0 0LIKE 0h0‚0k0Å_‰) j0i0k0f0 YÛcL0Å_‰ case "'": tmpString = tmpString.ToString().Replace("'", "''"); break; default: break; } outString = outString + tmpString.ToString(); } return outString; } /// <summary>SQLybk‡eW[ ‡eW[Rn0-Nk0SQLybk‡eW[L0+T~0Œ0f0D0‹0K0i0F0K0 /// </summary> /// <param name="value">‡eW[R</param> /// <returns></returns> public static string GetSqlLimitChar(string value) { for (int i = 0; i <= value.Length - 1; i++) { if (SqlLimitChar.IndexOf(value[i]) != -1) { return value[i].ToString(); } } return string.Empty; } public static void SetWindowActive(System.Diagnostics.Process process) { //IntPtr hwnd = FindWindow(null, "[!|f)R(ui"}n0agöNeQ›R]"); //ShowWindowAsync(hwnd, WS_SHOWNORMAL); //SetForegroundWindow(hwnd); int i = 0; while (process.MainWindowHandle.ToInt32() == 0 && i < 100) { System.Threading.Thread.Sleep(500); process.Refresh(); i++; } ShowWindowAsync(process.MainWindowHandle, WS_SHOWNORMAL); SetForegroundWindow(process.MainWindowHandle); //click //SendMessageA(process.MainWindowHandle, 513, IntPtr.Zero, IntPtr.Zero); //SendMessageA(process.MainWindowHandle, 514, IntPtr.Zero, IntPtr.Zero); } public static bool ToBool(string value) { try { return bool.Parse(value); } catch { return false; } } public static int FindWindowByText(int hwnd, string text) { StringBuilder nameBuffer = null; int hwndTarget = GetWindow(hwnd, GW_HWNDFIRST); while (hwndTarget != 0) { nameBuffer = new StringBuilder(1024); GetWindowText(hwndTarget, nameBuffer, nameBuffer.Capacity); if (nameBuffer.ToString().Contains(text)) { return hwndTarget; } hwndTarget = GetWindow(hwndTarget, GW_HWNDNEXT); } return 0; } public static bool SendMsgToWindow(int hwnd, string winText, string sendText) { int WINDOW_HANDLER = FindWindowByText(hwnd, winText); if (WINDOW_HANDLER == 0) { return false; } byte[] sarr = System.Text.Encoding.Default.GetBytes(sendText); int len = sarr.Length; COPYDATASTRUCT cds; cds.dwData = (IntPtr)100; cds.lpData = sendText; cds.cbData = len + 1; SendMessage(WINDOW_HANDLER, WM_COPYDATA, 0, ref cds); return true; } /// <summary> /// Ç0ü0¿0Ù0ü0¹0n0peW[‹WÇ0ü0¿0’0;ub—k0hˆ:yY0‹0Bfk00 0-1 0or 00 0n04XTo00zz}vk0Y0‹0 /// </summary> /// <param name="value"></param> /// <returns></returns> public static string ToFormText(int value) { if (value == -1 || value == 0) { return string.Empty; } else { return value.ToString(); } } public static string ToFormTextPlus(int value) { if (value < 0) { return string.Empty; } else { return value.ToString(); } } /// <summary> /// ³0ó0È0í0ü0ë0Õ0©0Ã0«0¹0g0M0‹0K0i0F0K0 /// </summary> /// <param name="obj"></param> /// <returns></returns> public static bool CtrlCanFocus(Control obj) { if (obj is CTextBox) { if ((obj as CTextBox).Enabled && (obj as CTextBox).Visible) { return true; } } else { if (obj.Enabled && obj.Visible) { return true; } } return false; } /// <summary> /// GetWeekOfMonth /// </summary> /// <param name="dtSel"></param> /// <returns></returns> public static int GetWeekOfMonth(DateTime dtSel) { if (dtSel.Day == 1) { return 0; } DateTime dtStart = new DateTime(dtSel.Year, dtSel.Month, 1); int dayofweek = (int)dtStart.DayOfWeek; int startWeekDays = 7 - dayofweek; if (dtSel.Day <= startWeekDays) { return 0; } int aday = dtSel.Day + 7 - startWeekDays; return (aday / 7 + (aday % 7 > 0 ? 1 : 0)) - 1; } /// <summary> /// GetDayWeekCode /// </summary> /// <param name="dt_CheckDay_A"></param> /// <returns></returns> public static int GetDayWeekCode(DateTime dt_CheckDay_A) { int nDayWeek = 0; switch (dt_CheckDay_A.DayOfWeek.ToString()) // Nåen0ÜfåeÁ0§0Ã0¯0 { case "Sunday": nDayWeek = 0; break; case "Monday": nDayWeek = 1; break; case "Tuesday": nDayWeek = 2; break; case "Wednesday": nDayWeek = 3; break; case "Thursday": nDayWeek = 4; break; case "Friday": nDayWeek = 5; break; case "Saturday": nDayWeek = 6; break; default: break; } return nDayWeek; } /// <summary> /// ³0ó0È0í0ü0ë0n0MOn’0Š—{Y0‹0 /// </summary> /// <param name="obj"></param> /// <param name="location"></param> public static void GetLocationToScreen(Control obj, ref System.Drawing.Point location) { location.X += obj.Location.X; location.Y += obj.Location.Y; if (obj.Parent is Form) { return; } GetLocationToScreen(obj.Parent, ref location); } /// <summary> /// DataGridViewn0PopUpMOn’0ԏY0 /// </summary> /// <param name="ownerForm"></param> /// <param name="grid"></param> /// <returns></returns> public static System.Drawing.Point GetPopUpLocation(Form ownerForm, DataGridView grid) { System.Drawing.Point location = ownerForm.PointToScreen(new System.Drawing.Point(0, 0)); GeneralSub.GetLocationToScreen(grid, ref location); //for (int i = 0; i < grid.CurrentCell.ColumnIndex; i++) //{ // if (!grid.Columns[i].Visible) { continue; } // location.X += grid.Columns[i].Width; //} for (int i = 0; i < grid.ColumnCount; i++) { if (!grid.Columns[i].Visible) { continue; } if (grid.Columns[i].DisplayIndex >= grid.Columns[grid.CurrentCell.ColumnIndex].DisplayIndex) { continue; } location.X += grid.Columns[i].Width; } location.X += 3; location.X -= grid.HorizontalScrollingOffset; location.Y += grid.ColumnHeadersHeight; location.Y += grid.Rows[0].Height * (grid.CurrentCell.RowIndex - grid.FirstDisplayedScrollingRowIndex + 1); location.Y += 1; return location; } public static System.Drawing.Point GetPopUpLocationEx(Form ownerForm, DataGridView grid) { System.Drawing.Point location = ownerForm.PointToScreen(new System.Drawing.Point(0, 0)); GeneralSub.GetLocationToScreen(grid, ref location); for (int i = 0; i < grid.CurrentCell.ColumnIndex; i++) { location.X += grid.Columns[i].Width; } location.X += 3; location.X -= grid.HorizontalScrollingOffset; location.Y += (grid.ColumnHeadersVisible ? grid.ColumnHeadersHeight : 0); for (int i = grid.FirstDisplayedScrollingRowIndex; i <= grid.CurrentCell.RowIndex; i++) { location.Y += grid.Rows[i].Height; } location.Y += 1; return location; } /// <summary> IDEâ0ü0É0K0i0F0K0 /// </summary> /// <returns></returns> public static bool IsIdeMode() { return (Environment.CommandLine.Contains(".vshost.exe")); } /// <summary> ‡eW[R’0cš[W0_0Ð0¤0È0k0Y0‹0('YM0D04XTo0óStP’0«0Ã0È00\U0D04XTo0óStPk0zz}v?ceQ) /// </summary> /// <param name="Xstr">‡eW[R</param> /// <param name="Bytes">š[W0_0w•U0</param> /// <returns>string</returns> public static string Xformat(string Xstr, int Bytes) { try { if ("".Equals(Xstr)) { return new string(' ', Bytes); } Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); //NET5g0Shift-JIS’0qbF0¹eÕl System.Text.Encoding enc = System.Text.Encoding.GetEncoding("Shift_JIS"); //sjis byte[] wvBuff = enc.GetBytes(Xstr.ToString() + new string(' ', Bytes));// 'abcde ' return enc.GetString(wvBuff, 0, Bytes); } catch { return new string(' ', Bytes); } } /// <summary> ‡eW[R’0cš[W0_0Ð0¤0È0k0Y0‹0('YM0D04XTo0æ]tP’0«0Ã0È00\U0D04XTo0æ]tPk0zz}v?ceQ) /// </summary> /// <param name="Xstr"></param> /// <param name="Bytes"></param> /// <returns></returns> public static string XformatL(string Xstr, int Bytes) { try { if ("".Equals(Xstr)) { return new string(' ', Bytes); } Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); //NET5g0Shift-JIS’0qbF0¹eÕl System.Text.Encoding enc = System.Text.Encoding.GetEncoding("Shift_JIS"); //sjis byte[] wvBuff = enc.GetBytes(new string(' ', Bytes) + Xstr.ToString());// ' abcde' return enc.GetString(wvBuff, wvBuff.Length - Bytes, Bytes); } catch { return new string(' ', Bytes); } } /// <summary> valuen0æ]K0‰0length‡eW[’0RŠ0ÖSŠ0 /// </summary> /// <param name="value"></param> /// <param name="length"></param> /// <returns></returns> public static string Left(string value, int length) { try { if (value.Length <= length) { return value; } return value.Substring(0, length); } catch { return string.Empty; } } /// <summary>‡eW[Ro0cš[W0_0w•U0g00'YM0D04XTo0R‹00\U0D04XTo0‹kŠ0’0ԏY0</summary> /// <param name="Xstr">‡eW[R</param> /// <param name="startIdx">‹•ËYMOn0^ÿ</param> /// <param name="Bytes">cš[W0_0w•U0</param> /// <returns>string</returns> public static string MidB(string Xstr, int startIdx, int Bytes) { try { string result = string.Empty;//liu 2010/03/17 add Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); //NET5g0Shift-JIS’0qbF0¹eÕl System.Text.Encoding enc = System.Text.Encoding.GetEncoding("Shift_JIS"); //sjis byte[] wvBuff = enc.GetBytes(Xstr.ToString()); //if (wvBuff.Length < startIdx + Bytes) { return Xstr; } //if (wvBuff.Length < startIdx + Bytes) { return string.Empty; }//liu 2010/03/17 //Redmne#9256 //20170608 Ûk)R Redmne#9256 startIdx ÿBytesˆ0Š0‚0\U0D0h0M0o00startIdxK0‰0n0‹kŠ0’0ԏY0ˆ0F0k0Y0‹0 if (wvBuff.Length <= startIdx) { return string.Empty; }//‹•ËYMOnL0X[(WW0j0D0 if (wvBuff.Length - startIdx < Bytes) { Bytes = wvBuff.Length - startIdx; }//‹•ËYMOnK0‰0‹kŠ0h0RŠ0ÖSŠ0w•U0n0¿Šte result = enc.GetString(wvBuff, startIdx, Bytes); if (enc.GetByteCount(result) > Bytes) { result = result.Substring(0, result.Length - 1); }//liu 2010/03/17 add return result; } catch { return Xstr; } } /// <summary> XstrK0‰0Bytes‡eW[’0RŠ0ÖSŠ0(ByteXSMO0RŒ0‹04XTo0JS҉R!qW0h0j0‹0) /// </summary> /// <param name="Xstr"></param> /// <param name="Bytes"></param> /// <returns></returns> public static string MidB(string Xstr, int Bytes) { try { string result = string.Empty; Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); //NET5g0Shift-JIS’0qbF0¹eÕl System.Text.Encoding enc = System.Text.Encoding.GetEncoding("Shift_JIS"); //sjis int strbytelen = 0; for (int i = 0; i < Xstr.Length; i++) { string strChar = Xstr.Substring(i, 1); strbytelen += enc.GetByteCount(strChar); if (strbytelen > Bytes) { break; } result += strChar; } return result; } catch { return string.Empty.PadLeft(Bytes); } } /// <summary> cš[W0_0Ð0¤0È0peg0‡eW[’09eLˆY0‹0(List) /// </summary> /// <param name="value"></param> /// <param name="lineByteSize"></param> /// <returns></returns> public static List<string> GetMultLine(string value, int lineByteSize) { List<string> list = new List<string>(); if (value.Length == 0) { list.Add(new string(' ', lineByteSize)); return list; } int totalLen = GetStrLenB(value); int len = 0; string remain = value; while (len < totalLen) { string line = GeneralSub.MidB(remain, lineByteSize); len += GetStrLenB(line); remain = remain.Substring(line.Length); list.Add(PadRightB(line, lineByteSize)); } return list; } /// <summary> cš[W0_0Ð0¤0È0peg0‡eW[’09eLˆY0‹0(string) /// </summary> /// <param name="value"></param> /// <param name="lineByteSize">ByteXSMO0RŒ0‹04XTo0JS҉R!qW0h0j0‹0</param> /// <param name="canMinLineWord">1Lˆn0gNO‡eW[pe0S0Œ0’0…H0‹0h0 Nn0Lˆk0ý RY0‹0(‡eW[pe)</param> /// <param name="maxLine">1åN N’0cš[W0_04XT]0n0Lˆpe~0g0’0ԏY0</param> /// <returns></returns> public static string GetMultLineB(string value, int lineByteSize, int canMinLineWord, int maxLine) { if (value.Length > 0) { int lineCount = 0; string ret = string.Empty; string tmp = string.Empty; do { tmp = GeneralSub.MidB(value, lineByteSize); value = value.Replace(tmp, ""); ret += (ret.Length > 0 ? Environment.NewLine : "") + tmp; if (value.Length <= canMinLineWord) { ret += value; break; } lineCount++; if (maxLine > 0 && lineCount >= maxLine) break; } while (value.Length > canMinLineWord); value = ret; } return value; } /// <summary> Ð0¤0È0pek0j0‹0~0g0æ]tPk0‡eW[ËW0(JS҉zz}v) /// </summary> /// <param name="value"></param> /// <param name="totalByte"></param> /// <returns></returns> public static string PadLeftB(string value, int totalByte) { return PadLeftB(value, totalByte, ' '); } /// <summary> Ð0¤0È0pek0j0‹0~0g0æ]tPk0‡eW[ËW0(ËW0‡eW[cš[) /// </summary> /// <param name="value"></param> /// <param name="totalByte"></param> /// <param name="paddingChar"></param> /// <returns></returns> public static string PadLeftB(string value, int totalByte, char paddingChar) { string line = GeneralSub.MidB(value, totalByte); int remainCount = totalByte - GetStrLenB(line); if (remainCount > 0) { line = new string(paddingChar, remainCount) + line; } return line; } /// <summary> Ð0¤0È0pek0j0‹0~0g0óStPk0‡eW[ËW0(JS҉zz}v) /// </summary> /// <param name="value"></param> /// <param name="totalByte"></param> /// <returns></returns> public static string PadRightB(string value, int totalByte) { return PadRightB(value, totalByte, ' '); } /// <summary> Ð0¤0È0pek0j0‹0~0g0óStPk0‡eW[ËW0(ËW0‡eW[cš[) /// </summary> /// <param name="value"></param> /// <param name="totalByte"></param> /// <param name="paddingChar"></param> /// <returns></returns> public static string PadRightB(string value, int totalByte, char paddingChar) { string line = GeneralSub.MidB(value, totalByte); int remainCount = totalByte - GetStrLenB(line); if (remainCount > 0) { line += new string(paddingChar, remainCount); } return line; } /// <summary> JS҉¹0Ú0ü0¹0 /// </summary> /// <param name="count"></param> /// <returns></returns> public static string Space(int count) { return new string(' ', count); } /// <summary> hQ҉¹0Ú0ü0¹0 /// </summary> /// <param name="count"></param> /// <returns></returns> public static string SpaceDouble(int count) { return new string('0', count); } /// <summary> ‡eW[Rn0Ð0¤0È0pe’0Bl0‹0 /// </summary> /// <param name="Xstr"></param> /// <returns></returns> public static int GetStrLenB(string Xstr) { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); //NET5g0Shift-JIS’0qbF0¹eÕl System.Text.Encoding enc = System.Text.Encoding.GetEncoding("Shift_JIS"); //sjis return enc.GetBytes(Xstr.ToString()).Length; } /// <summary> /// /// </summary> /// <param name="value"></param> /// <param name="g"></param> /// <returns></returns> public static string GetFitArea(string value, Graphics g, Font font, float maxWidth, GraphicsUnit pageUnit) { string itemName = value; g.PageUnit = pageUnit; float allWidth = g.MeasureString(itemName, font).Width; if (allWidth > maxWidth) { while (itemName.Length > 0) { itemName = itemName.Substring(0, itemName.Length - 1); allWidth = g.MeasureString(itemName, font).Width; if (allWidth <= maxWidth) { break; } } } return itemName; } public static Encoding GetEncoding(string fileName) { //return GetEncoding(fileName, Encoding.Default); //StreamReader sr = new StreamReader(fileName, Encoding.Default); StreamReader sr = new StreamReader(fileName, Encoding.Default); sr.ReadToEnd(); Encoding encoding = sr.CurrentEncoding; sr.Close(); if (encoding.CodePage == 932) { string fsjis = System.IO.File.ReadAllText(fileName, Encoding.Default); //SJIS string fjis = System.IO.File.ReadAllText(fileName, Encoding.GetEncoding(50221)); //JIS if (fjis.Length < fsjis.Length) { encoding = Encoding.GetEncoding(50221); } } return encoding; } /// <summary> þ[aŒ³0ó0È0í0ü0ë0…Qn0hQf0n0³0ó0È0í0ü0ë0n0Rc /// </summary> /// <param name="top">Q0^Y0‹0gRn0³0ó0È0í0ü0ë0</param> /// <returns>³0ó0È0í0ü0ë0n0ê0¹0È0</returns> public static Control[] GetAllControls(Control top) { //System.Collections.ArrayList buf = new System.Collections.ArrayList(); List<Control> buf = new List<Control>(); foreach (Control c in top.Controls) { buf.Add(c); buf.AddRange(GetAllControls(c)); } return (Control[])buf.ToArray(); } /// <summary> þ[aŒ³0ó0È0í0ü0ë0…Qn0NôY0‹0¿0¤0×0’0Nd0ԏY0 /// </summary> /// <param name="top">Q0^Y0‹0gRn0³0ó0È0í0ü0ë0</param> /// <param name="type">NôY0‹0¿0¤0×0</param> /// <returns>³0ó0È0í0ü0ë0</returns> public static Control GetFirstControl(Control top, Type type) { foreach (Control c in top.Controls) { if (c.GetType().Equals(type)) { return c; } Control obj = GetFirstControl(c, type); if (obj != null) { return obj; } } return null; } /// <summary> /// ª‰Õ0©0ü0à0n0ÖS—_ /// </summary> /// <param name="obj"></param> /// <returns></returns> public static Form GetOwnerForm(Control obj) { if (obj.Parent == null) { return null; } else if (obj.Parent is Form) { return obj.Parent as Form; } else { return GetOwnerForm(obj.Parent); } } /// <summary> /// ·0¹0Æ0à0.z%R /// </summary> /// <returns></returns> public static string GetOpertatingSystemName() { System.OperatingSystem os = System.Environment.OSVersion; string name = "Unknown"; switch (os.Platform) { case System.PlatformID.Win32Windows: switch (os.Version.Minor) { case 0: name = "Windows 95"; break; case 10: name = "Windows 98"; break; case 90: name = "Windows ME"; break; } break; case System.PlatformID.Win32NT: switch (os.Version.Major) { case 3: name = "Windws NT 3.51"; break; case 4: name = "Windows NT 4"; break; case 5: switch (os.Version.Minor) { case 0: name = "Windows 2000"; break; case 1: name = "Windows XP"; break; case 2: name = "Windows Server 2003"; break; } break; case 6: switch (os.Version.Minor) { case 0: name = "Windows Vista"; break; case 1: name = "Windows 7"; break; } break; } break; } return name; } /// <summary> /// Tðyk0ˆ0‹0Enumk0X[(WY0‹0K0i0F0K0 /// </summary> /// <param name="enumType"></param> /// <param name="name"></param> /// <returns></returns> public static bool IsExistsEnumName(Type enumType, string name) { try { object value = Enum.Parse(enumType, name); return (value != null); } catch { return false; } } /// <summary> /// DOS ³0Þ0ó0É0n0Ÿ[Lˆ /// </summary> /// <param name="cmd"></param> /// <returns></returns> public static string ExecuteDosCmd(string cmd) { using (Process process = new Process()) { process.StartInfo.FileName = "cmd.exe"; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; process.Start(); process.StandardInput.WriteLine(cmd); process.StandardInput.WriteLine("exit"); string myResult = process.StandardOutput.ReadToEnd(); process.Close(); return myResult; } } /// <summary> /// ¡{t€¹e_g0cmd’0Ÿ[Lˆ /// </summary> /// <returns></returns> public static bool RunCmd() { try { using (Process myPro = new Process()) { ProcessStartInfo psi = new ProcessStartInfo("cmd.exe"); psi.Verb = "runas"; myPro.StartInfo = psi; myPro.Start(); myPro.WaitForExit(); return true; } } catch { return false; } } /// <summary> /// cš[W0_0ؚU0k0a0‡0F0i0J0U00‹0Font’0ԏY0 /// </summary> /// <param name="text">Á0§0Ã0¯0Y0‹0‡eW[R</param> /// <param name="height">ÎS0_0D0ؚU0</param> /// <param name="f">.~\‹•ËYFont</param> /// <param name="g">æQt(uGraphics</param> /// <param name="sf">æQt(uStringFormat</param> /// <returns></returns> public static Font SetCollectFontSize(string text, int height, Font f, Graphics g, StringFormat sf) { bool ok = false; while (!ok) { SizeF sff = g.MeasureString(text, f, 50, sf); Size sfff = new Size((int)(sff.Width), (int)(sff.Height)); if (height < sfff.Height) { if (f.Size <= 1.0) { ok = true; } else { f = new Font(f.FontFamily.Name, f.Size - 0.5f); } } else { ok = true; } } return f; } /// <summary> DataGridViewn0Ç0Õ0©0ë0È0’0-Šš[ /// </summary> /// <param name="grid"></param> /// <param name="isAlternatingRows"></param> public static void InitDataGridView(DataGridView grid, bool isAlternatingRows) { grid.ReadOnly = true; grid.EnableHeadersVisualStyles = false; //»0ë0n0ƒXLuÚ}’0N͑Ú}k0Y0‹0 grid.CellBorderStyle = DataGridViewCellBorderStyle.Single; grid.ForeColor = System.Drawing.Color.Black; if (isAlternatingRows) { grid.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(255, 216, 228, 248); } grid.AutoGenerateColumns = true; grid.RowHeadersVisible = false; grid.AllowUserToAddRows = false; grid.AllowUserToDeleteRows = false; grid.AllowUserToResizeColumns = true; grid.AllowUserToResizeRows = false; grid.MultiSelect = false; grid.SelectionMode = DataGridViewSelectionMode.FullRowSelect; } /// <summary> …_a0 /// </summary> /// <param name="milliseconds"></param> public static void Wait(double milliseconds) { DateTime t = DateTime.Now.AddMilliseconds(milliseconds); while (DateTime.Now < t) { Application.DoEvents(); if (DateTime.Now.AddMilliseconds(milliseconds + 1000) < t) { break; } //-Ng0·0¹0Æ0à0Bf“• Y0c0_0ÿÿ } } /// <summary> êRIPn0ÖS—_ /// </summary> /// <returns></returns> public static List<string> GetLocalIpv4() { IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName()); List<string> IpCollection = new List<string>(); foreach (IPAddress ip in localIPs) { if (ip.AddressFamily == AddressFamily.InterNetwork) { IpCollection.Add(ip.ToString()); } } return IpCollection; } /// <summary> êRn0¢•peCQn0Å`1X’0hˆ:y /// </summary> /// <param name="isAll">true:gRK0‰0þs(W~0g0hQè / false:r0h0d0MR~0g0</param> /// <param name="isIncludeMe">true:êR‚0hˆ:y / false:^—hˆ:y</param> /// <param name="isExtractSameFanctionName">true:͑‰Y0‹0¢•peo0d–O0 / false:͑‰Y0‹0¢•pe‚0d–K0j0D0</param> /// <returns></returns> public static string WriteMethod(bool isAll,bool isIncludeMe,bool isExtractSameFanctionName) { //(Æ0¹0È0(u)þs(Wn0¢•peK0‰00|TúQW0CQn0¢•pe’0åw‹0¹eÕl‹O string myMethod = ""; try { System.Diagnostics.StackFrame callerFrame = null; MethodBase callerMethod = null; //êRn0¢•pe(S0n0¢•pen0r0h0d0MRn0¢•pe) callerFrame = new System.Diagnostics.StackFrame(1); callerMethod = callerFrame.GetMethod(); myMethod = callerMethod.ReflectedType.FullName + "." + callerMethod.Name; //yrŠkæQt’0Y0‹0¢•pe bool isOpenConnect = myMethod == "Oat.Library.CommonClass.Data.MsSqlNet.OpenConnect"; bool isCloseConnect = myMethod == "Oat.Library.CommonClass.Data.MsSqlNet.Close"; Dictionary<string, string> noMethodList = new Dictionary<string, string>(); if (isOpenConnect || isCloseConnect) { //åN Nn0h0S00n0¢•pe T’0ÖS—_W0f0‚0asTL0j0D0n0g00 //noMethodList.Add(".ctor", "¯0é0¹0¤0ó0¹0¿0ó0¹0Bf"); noMethodList.Add("Oat.Library.CommonClass.Data.MsSqlNet..ctor", "¯0é0¹0¤0ó0¹0¿0ó0¹0Bf"); noMethodList.Add("Dispose", ""); noMethodList.Add("CreateDBAccess", ""); noMethodList.Add("CreateCommonDBAccess", ""); noMethodList.Add("GetDataTable", ""); noMethodList.Add("GetDataSet", ""); noMethodList.Add("ExecuteNonQuery", ""); noMethodList.Add("GetDataReader", ""); noMethodList.Add("ExecuteScalar", ""); } //ËY0‹0ju÷S int startFrameIndex = isIncludeMe ? 1 : 2; //|TúQW0CQ¢•pehˆ:y for (int i = startFrameIndex; i <= 100; i++)//h0Š0B0H0Z0Max100 { callerFrame = new System.Diagnostics.StackFrame(i); if (callerFrame == null) break; callerMethod = callerFrame.GetMethod(); if (callerMethod == null) break; if (isExtractSameFanctionName && callerMethod.ReflectedType.FullName + "." + callerMethod.Name == myMethod)//_peUD0j0i0o0d–O04XT { continue;//#š}Y0‹0 T To0þ[aŒY } myMethod = callerMethod.ReflectedType.FullName + "." + callerMethod.Name; if (isOpenConnect || isCloseConnect) { if (noMethodList.ContainsKey(callerMethod.Name)) continue;//þ[aŒY if (noMethodList.ContainsKey(myMethod)) continue;//þ[aŒY } Console.WriteLine("0Stack" + (i - 1) + "0" + myMethod + (isOpenConnect ? "0OpenConnect0" : "") + (isCloseConnect ? "0CloseConnect0" : "")); if (!isAll) break; } } catch { myMethod = "0ÿ0" + myMethod; } return myMethod; } public static void SetDoubleBuffered(Control control) { // set instance non-public property with name "DoubleBuffered" to true typeof(Control).InvokeMember("DoubleBuffered", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, control, new object[] { true }); } public static void AutoBottomScroll(DataGridView grid) { int rowlimit = grid.DisplayedRowCount(true); if (rowlimit < grid.RowCount) { grid.FirstDisplayedScrollingRowIndex = grid.RowCount - 1; } } public static float Inch_To_Cm(float inch) { return inch * INCH_TO_CM;//Inch’!cm } public static float CM_TO_INCH(float cm) { return cm / INCH_TO_CM;//cm’!Inch } public static float INCH_TO_DOT(float inch) { //System.Drawing.Image i; //i.HorizontalResolution;//dpi //i.VerticalResolution;//dpi return inch * 96F;//Inch’!Dot } public static float DOT_TO_INCH(float dot) { return dot / 96F;//Dot’!Inch } public static float CM_TO_DOT(float cm) { return cm * 96F / INCH_TO_CM;//cm’!Dot } public static float DOT_TO_CM(float dot) { return dot * INCH_TO_CM / 96F;//Dot’!cm } public static byte[] FileToByte(string fileName) { //======================================== //fileNamen0;uÏP’0­Š¼Byteg0ԏY0 //======================================== byte[] imageb = null; try { using (FileStream fs = File.OpenRead(fileName)) { imageb = new byte[fs.Length]; fs.Read(imageb, 0, imageb.Length); fs.Close(); } return imageb; } catch (Exception ex) { MessageBox.Show(ex.Message, "FileToByte", MessageBoxButtons.OK, MessageBoxIcon.Error); return null; } } public static bool ByteToFile(byte[] imageb, string fileName) { //======================================== //imageb’0¤0á0ü0¸0SW00fileNamen0;uÏPh0W0f0ÝOX[ //======================================== try { using (FileStream fs = File.OpenWrite(fileName)) { fs.Write(imageb, 0, imageb.Length); fs.Close(); } return true; } catch (Exception ex) { MessageBox.Show(ex.Message, "ByteToFile", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } } public static bool SaveJpgImage(Image image,string saveFileName, Int64 quality) { //======================================== //image’0jpgg0ÝOX[ //======================================== try { //jpg(ÁTêŒØN) //Int64 quality = 20; // ÁTêŒì0Ù0ë0ÿ20 System.Drawing.Imaging.ImageCodecInfo jpgEncoder = null; // JPEG(un0¨0ó0³0ü0À0n0ÖS—_ foreach (System.Drawing.Imaging.ImageCodecInfo ici in System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()) { if (ici.FormatID == System.Drawing.Imaging.ImageFormat.Jpeg.Guid) { jpgEncoder = ici; break; } } // ¨0ó0³0ü0À0k0!nY0Ñ0é0á0ü0¿0n0\Ob System.Drawing.Imaging.EncoderParameter encParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality); // Ñ0é0á0ü0¿0’0M‘Rk0 args = new Queue<string>(Environment.GetCommandLineArgs()); args.Dequeue(); // args[0] is always exe path/filename return string.Join(" ", args.ToArray()); } public static void ReStart(System.Threading.Mutex hMutex) { string commandLineArgs = GetCommandLineArgs(); string exePath = Application.ExecutablePath; try { if (hMutex != null) { // GC.KeepAlive á0½0Ã0É0L0|Ts0úQU0Œ0‹0~0g00¬0Ù0ü0¸0 ³0ì0¯0·0ç0ó0þ[aŒK0‰0d–YU0Œ0‹0 GC.KeepAlive(hMutex); // Mutex ’0‰•X0‹0 (ckW0O0o0 ª0Ö0¸0§0¯0È0n04xÄh’0ÝO<ŠY0‹0 ’0ÂSgq) hMutex.Close(); } Process.Start(exePath, commandLineArgs); Environment.Exit(0); } catch { throw; } } public static DateTime BeginOfMonth(DateTime dt)//gRåe’0ԏY0 { return dt.AddDays((dt.Day - 1) * -1); } public static DateTime EndOfMonth(DateTime dt)// g+gåe’0ԏY0 { return new DateTime(dt.Year, dt.Month, DaysInMonth(dt)); } public static int DaysInMonth(DateTime dt) { return DateTime.DaysInMonth(dt.Year, dt.Month); } /// <summary> /// ;ub—N§‰k0âek0‹•D0_0K0i0F0K0 /// </summary> /// <param name="a_typ"></param> /// <returns></returns> public static Form GetOpenForm(Type a_typ) { foreach (Form item in Application.OpenForms) { if (a_typ == item.GetType()) { return item; } } return null; } // ============== (http://note.chiebukuro.yahoo.co.jp/detail/n145045) // Bitmap’0Byte‹WM‘R(Ð0¤0Ê0ê0)k0 YÛc // b__o00_pek0eQ›Rcš[Y0‹0Bitmapn0Õ0¡0¤0ë0b__h0Y0‹00 // ,{ÿ_pe: Bitmap‹W;uÏPÅ`1X // ;bŠ0$P: Byte‹WM‘R(Ð0¤0Ê0ê0)n0;uÏPÅ`1X public static byte[] ConvertImageToBytes(System.Drawing.Bitmap bmp) { // eQ›R_pen0pu8^Bfn0¨0é0ü0æQt if (bmp == null) { return null; } // ԏtS(uÐ0¤0È0‹WM‘R byte[] ImageBytes; // á0â0ê0¹0È0ê0ü0à0n0ub using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { #region bmpn04XT // Bitmap;uÏP’00Bitmapn0Õ0¡0¤0ë0b__g0¹0È0ê0ü0à0k0ÝOX[ //bmp.Save(ms, bmp.RawFormat); //bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); #endregion #region jpgn04XT //jpg(ÁTêŒØN) Int64 quality = 50; // ÁTêŒì0Ù0ë0ÿ20 System.Drawing.Imaging.ImageCodecInfo jpgEncoder = null; // JPEG(un0¨0ó0³0ü0À0n0ÖS—_ foreach (System.Drawing.Imaging.ImageCodecInfo ici in System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()) { if (ici.FormatID == System.Drawing.Imaging.ImageFormat.Jpeg.Guid) { jpgEncoder = ici; break; } } // ¨0ó0³0ü0À0k0!nY0Ñ0é0á0ü0¿0n0\Ob System.Drawing.Imaging.EncoderParameter encParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality); // Ñ0é0á0ü0¿0’0M‘Rk0 /// *j4ls^¹eT /// </summary> /// <param name="align"></param> /// <returns></returns> public static StringAlignment ToStringAlignment(DataGridViewContentAlignment align) { StringAlignment ag = StringAlignment.Near; switch (align) { case DataGridViewContentAlignment.BottomCenter: case DataGridViewContentAlignment.MiddleCenter: case DataGridViewContentAlignment.TopCenter: ag = StringAlignment.Center; break; case DataGridViewContentAlignment.BottomLeft: case DataGridViewContentAlignment.MiddleLeft: case DataGridViewContentAlignment.TopLeft: ag = StringAlignment.Near; break; case DataGridViewContentAlignment.BottomRight: case DataGridViewContentAlignment.MiddleRight: case DataGridViewContentAlignment.TopRight: ag = StringAlignment.Far; break; } return ag; } /// <summary> /// &~‚Wôv¹eT /// </summary> /// <param name="align"></param> /// <returns></returns> public static StringAlignment ToLineStringAlignment(DataGridViewContentAlignment align) { StringAlignment ag = StringAlignment.Center; switch (align) { case DataGridViewContentAlignment.TopCenter: case DataGridViewContentAlignment.TopLeft: case DataGridViewContentAlignment.TopRight: ag = StringAlignment.Near; break; case DataGridViewContentAlignment.MiddleCenter: case DataGridViewContentAlignment.MiddleLeft: case DataGridViewContentAlignment.MiddleRight: ag = StringAlignment.Center; break; case DataGridViewContentAlignment.BottomCenter: case DataGridViewContentAlignment.BottomRight: case DataGridViewContentAlignment.BottomLeft: ag = StringAlignment.Far; break; } return ag; } /// <summary> /// Clipboardx0³0Ô0ü0 /// </summary> /// <param name="data"></param> public static void CopyToClipboard(string data) { try { Clipboard.SetDataObject(data, true); } catch { } } } }