public virtual bool ContainsText(TextDataFormat format) { //valid values are 0x0 to 0x4 if (!ClientUtils.IsEnumValid(format, (int)format, (int)TextDataFormat.Text, (int)TextDataFormat.CommaSeparatedValue)) { throw new InvalidEnumArgumentException(nameof(format), (int)format, typeof(TextDataFormat)); } return(GetDataPresent(ConvertToDataFormats(format), false)); }
/// <summary> /// Specifies the Help keyword to display when the user invokes Help for a control. /// </summary> public virtual void SetHelpNavigator(Control ctl, HelpNavigator navigator) { if (!ClientUtils.IsEnumValid(navigator, (int)navigator, (int)HelpNavigator.Topic, (int)HelpNavigator.TopicId)) { throw new InvalidEnumArgumentException(nameof(navigator), (int)navigator, typeof(HelpNavigator)); } _navigators[ctl] = navigator; SetShowHelp(ctl, true); UpdateEventBinding(ctl); }
/// <include file='doc\TrayIcon.uex' path='docs/doc[@for="NotifyIcon.ShowBalloonTip"]/*' /> /// <devdoc> /// <para> /// Displays a balloon tooltip in the taskbar with the specified title, /// text, and icon for a duration of the specified timeout value. /// /// The system enforces minimum and maximum timeout values. Timeout /// values that are too large are set to the maximum value and values /// that are too small default to the minimum value. The operating system's /// default minimum and maximum timeout values are 10 seconds and 30 seconds, /// respectively. /// /// No more than one balloon ToolTip at at time is displayed for the taskbar. /// If an application attempts to display a ToolTip when one is already being displayed, /// the ToolTip will not appear until the existing balloon ToolTip has been visible for at /// least the system minimum timeout value. For example, a balloon ToolTip with timeout /// set to 30 seconds has been visible for seven seconds when another application attempts /// to display a balloon ToolTip. If the system minimum timeout is ten seconds, the first /// ToolTip displays for an additional three seconds before being replaced by the second ToolTip. /// </para> /// </devdoc> public void ShowBalloonTip(int timeout, string tipTitle, string tipText, ToolTipIcon tipIcon) { if (timeout < 0) { throw new ArgumentOutOfRangeException("timeout", SR.GetString(SR.InvalidArgument, "timeout", (timeout).ToString(CultureInfo.CurrentCulture))); } if (string.IsNullOrEmpty(tipText)) { throw new ArgumentException(SR.GetString(SR.NotifyIconEmptyOrNullTipText)); } //valid values are 0x0 to 0x3 if (!ClientUtils.IsEnumValid(tipIcon, (int)tipIcon, (int)ToolTipIcon.None, (int)ToolTipIcon.Error)) { throw new InvalidEnumArgumentException("tipIcon", (int)tipIcon, typeof(ToolTipIcon)); } if (added) { // Bail if in design mode... if (DesignMode) { return; } IntSecurity.UnrestrictedWindows.Demand(); NativeMethods.NOTIFYICONDATA data = new NativeMethods.NOTIFYICONDATA(); if (window.Handle == IntPtr.Zero) { window.CreateHandle(new CreateParams()); } data.hWnd = window.Handle; data.uID = id; data.uFlags = NativeMethods.NIF_INFO; data.uTimeoutOrVersion = timeout; data.szInfoTitle = tipTitle; data.szInfo = tipText; switch (tipIcon) { case ToolTipIcon.Info: data.dwInfoFlags = NativeMethods.NIIF_INFO; break; case ToolTipIcon.Warning: data.dwInfoFlags = NativeMethods.NIIF_WARNING; break; case ToolTipIcon.Error: data.dwInfoFlags = NativeMethods.NIIF_ERROR; break; case ToolTipIcon.None: data.dwInfoFlags = NativeMethods.NIIF_NONE; break; } UnsafeNativeMethods.Shell_NotifyIcon(NativeMethods.NIM_MODIFY, data); } }
/// <include file='doc\HelpProvider.uex' path='docs/doc[@for="HelpProvider.SetHelpNavigator"]/*' /> /// <devdoc> /// <para> /// Specifies the Help keyword to display when /// the user invokes Help for a control. /// </para> /// </devdoc> public virtual void SetHelpNavigator(Control ctl, HelpNavigator navigator) { //valid values are 0x80000001 to 0x80000007 if (!ClientUtils.IsEnumValid(navigator, (int)navigator, (int)HelpNavigator.Topic, (int)HelpNavigator.TopicId)) { //validate the HelpNavigator enum throw new InvalidEnumArgumentException("navigator", (int)navigator, typeof(HelpNavigator)); } navigators[ctl] = navigator; SetShowHelp(ctl, true); UpdateEventBinding(ctl); }
public virtual void SetText(string textData, TextDataFormat format) { if (string.IsNullOrEmpty(textData)) { throw new ArgumentNullException(nameof(textData)); } //valid values are 0x0 to 0x4 if (!ClientUtils.IsEnumValid(format, (int)format, (int)TextDataFormat.Text, (int)TextDataFormat.CommaSeparatedValue)) { throw new InvalidEnumArgumentException(nameof(format), (int)format, typeof(TextDataFormat)); } SetData(ConvertToDataFormats(format), false, textData); }
public virtual string GetText(TextDataFormat format) { //valid values are 0x0 to 0x4 if (!ClientUtils.IsEnumValid(format, (int)format, (int)TextDataFormat.Text, (int)TextDataFormat.CommaSeparatedValue)) { throw new InvalidEnumArgumentException(nameof(format), (int)format, typeof(TextDataFormat)); } if (GetData(ConvertToDataFormats(format), false) is string text) { return(text); } return(string.Empty); }
public static void SetText(string text, TextDataFormat format) { if (string.IsNullOrEmpty(text)) { throw new ArgumentNullException(nameof(text)); } if (!ClientUtils.IsEnumValid(format, (int)format, (int)TextDataFormat.Text, (int)TextDataFormat.CommaSeparatedValue)) { throw new InvalidEnumArgumentException(nameof(format), (int)format, typeof(TextDataFormat)); } IDataObject dataObject = new DataObject(); dataObject.SetData(ConvertToDataFormats(format), false, text); Clipboard.SetDataObject(dataObject, true); }
public static bool ContainsText(TextDataFormat format) { if (!ClientUtils.IsEnumValid(format, (int)format, (int)TextDataFormat.Text, (int)TextDataFormat.CommaSeparatedValue)) { throw new InvalidEnumArgumentException(nameof(format), (int)format, typeof(TextDataFormat)); } IDataObject dataObject = Clipboard.GetDataObject(); if (dataObject != null) { return(dataObject.GetDataPresent(ConvertToDataFormats(format), false)); } return(false); }
public static string GetText(TextDataFormat format) { if (!ClientUtils.IsEnumValid(format, (int)format, (int)TextDataFormat.Text, (int)TextDataFormat.CommaSeparatedValue)) { throw new InvalidEnumArgumentException(nameof(format), (int)format, typeof(TextDataFormat)); } IDataObject dataObject = Clipboard.GetDataObject(); if (dataObject != null) { if (dataObject.GetData(ConvertToDataFormats(format), false) is string text) { return(text); } } return(string.Empty); }
/// <include file='doc\Clipboard.uex' path='docs/doc[@for="Clipboard.GetText1"]/*' /> public static string GetText(TextDataFormat format) { // valid values are 0x0 to 0x4 inclusive if (!ClientUtils.IsEnumValid(format, (int)format, (int)TextDataFormat.Text, (int)TextDataFormat.CommaSeparatedValue)) { throw new InvalidEnumArgumentException("format", (int)format, typeof(TextDataFormat)); } IDataObject dataObject = Clipboard.GetDataObject(); if (dataObject != null) { string text = dataObject.GetData(ConvertToDataFormats(format), false) as string; if (text != null) { return(text); } } return(String.Empty); }
/// <include file='doc\Panel.uex' path='docs/doc[@for="Panel.StringFromBorderStyle"]/*' /> /// <devdoc> /// </devdoc> /// <internalonly/> private static string StringFromBorderStyle(BorderStyle value) { Type borderStyleType = typeof(BorderStyle); return((ClientUtils.IsEnumValid(value, (int)value, (int)BorderStyle.None, (int)BorderStyle.Fixed3D)) ? (borderStyleType.ToString() + "." + value.ToString()) : "[Invalid BorderStyle]"); }
private static DialogResult ShowCore(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, bool showHelp) { if (!ClientUtils.IsEnumValid(buttons, (int)buttons, (int)MessageBoxButtons.OK, (int)MessageBoxButtons.RetryCancel)) { throw new InvalidEnumArgumentException(nameof(buttons), (int)buttons, typeof(MessageBoxButtons)); } // valid values are 0x0 0x10 0x20 0x30 0x40, chop off the last 4 bits and check that it's between 0 and 4. if (!WindowsFormsUtils.EnumValidator.IsEnumWithinShiftedRange(icon, /*numBitsToShift*/ 4, /*min*/ 0x0, /*max*/ 0x4)) { throw new InvalidEnumArgumentException(nameof(icon), (int)icon, typeof(MessageBoxIcon)); } // valid values are 0x0 0x100, 0x200, chop off the last 8 bits and check that it's between 0 and 2. if (!WindowsFormsUtils.EnumValidator.IsEnumWithinShiftedRange(defaultButton, /*numBitsToShift*/ 8, /*min*/ 0x0, /*max*/ 0x2)) { throw new InvalidEnumArgumentException(nameof(defaultButton), (int)defaultButton, typeof(DialogResult)); } // options intentionally not verified because we don't expose all the options Win32 supports. if (!SystemInformation.UserInteractive && (options & (MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly)) == 0) { throw new InvalidOperationException(SR.CantShowModalOnNonInteractive); } if (owner != null && (options & (MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly)) != 0) { throw new ArgumentException(SR.CantShowMBServiceWithOwner, "options"); } if (showHelp && (options & (MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly)) != 0) { throw new ArgumentException(SR.CantShowMBServiceWithHelp, "options"); } int style = (showHelp) ? HELP_BUTTON : 0; style |= (int)buttons | (int)icon | (int)defaultButton | (int)options; IntPtr handle = IntPtr.Zero; if (showHelp || ((options & (MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly)) == 0)) { if (owner == null) { handle = UnsafeNativeMethods.GetActiveWindow(); } else { handle = Control.GetSafeHandle(owner); } } IntPtr userCookie = IntPtr.Zero; if (Application.UseVisualStyles) { // CLR4.0 or later, shell32.dll needs to be loaded explicitly. if (UnsafeNativeMethods.GetModuleHandle(ExternDll.Shell32) == IntPtr.Zero) { if (UnsafeNativeMethods.LoadLibraryFromSystemPathIfAvailable(ExternDll.Shell32) == IntPtr.Zero) { int lastWin32Error = Marshal.GetLastWin32Error(); throw new Win32Exception(lastWin32Error, string.Format(SR.LoadDLLError, ExternDll.Shell32)); } } // Activate theming scope to get theming for controls at design time and when hosted in browser. // NOTE: If a theming context is already active, this call is very fast, so shouldn't be a perf issue. userCookie = UnsafeNativeMethods.ThemingScope.Activate(); } Application.BeginModalMessageLoop(); DialogResult result; try { result = Win32ToDialogResult(SafeNativeMethods.MessageBox(new HandleRef(owner, handle), text, caption, style)); } finally { Application.EndModalMessageLoop(); UnsafeNativeMethods.ThemingScope.Deactivate(userCookie); } // Right after the dialog box is closed, Windows sends WM_SETFOCUS back to the previously active control // but since we have disabled this thread main window the message is lost. So we have to send it again after // we enable the main window. // UnsafeNativeMethods.SendMessage(new HandleRef(owner, handle), Interop.WindowMessages.WM_SETFOCUS, 0, 0); return(result); }
// IsValidTextImageRelation // valid values are 0,1,2,4,8 // Method for verifying // Verify that the number is between 0 and 8 // Verify that the bit that is on - thus forcing it to be a power of two. // public static bool IsValidTextImageRelation(TextImageRelation relation) { return(ClientUtils.IsEnumValid(relation, (int)relation, (int)TextImageRelation.Overlay, (int)TextImageRelation.TextBeforeImage, 1)); }
public static bool IsValidTextImageRelation(TextImageRelation relation) => ClientUtils.IsEnumValid(relation, (int)relation, 0, 8, 1);