About the author

Brian Keating is a developer addicted to Microsoft Technologies.

Month List

RecentComments

Comment RSS

Extension Method for Wpf Window with Froms Owner

clock January 28, 2010 18:47 by author Brian Keating |

 

Extension Method

internal static class InteropExtensions
{
    public static bool? ShowDialog(this System.Windows.Window win, IntPtr handle)
    {
        WindowInteropHelper helper = new WindowInteropHelper(win);
        helper.Owner = handle;
        return win.ShowDialog();
    }
}

 

Usage

var win = new WpfWindow();
win.ShowDalog(windowsFormOwnerHandle);




Key modifiers

clock December 23, 2009 07:32 by author Brian Keating |

Recently I used PInvoke to check if the SHIFT key was pressed while i was doing a drag operation......

what I should have done then and have done now is

 

if((Keyboard.Modifiers & ModifierKeys.Shift) != ModifierKeys.None)
  Trace.WriteLine("Shift is pressed");




Windows Forms Validation

clock November 5, 2009 17:53 by author Brian Keating |

One approach for validating child controls on windows froms is to

Validation.

  • Add a Validated event handler to all child controls you're interested in.
  • On a button event handler call this.ValidateChildren();

This will ensure the validation routine on all child controls will be called, if for example you've added an ErrorProvider control extender to your form you can set it up in the validated event handlers.