public DialogResult ShowDialog() { var cc = new ChooseColor(); cc.structSize = Marshal.SizeOf(cc); //Does not seem to work unless custom colors are initialized. var lpCustColors = Marshal.AllocCoTaskMem(16 * sizeof(int)); cc.custColors = lpCustColors; cc.flags = ChooseColorFlags.RgbInit; try { Marshal.Copy(customColors, 0, lpCustColors, 16); if (Win32Dialogs.ChooseColor(cc)) { Color = ColorTranslator.FromWin32(cc.rgbResult); return(DialogResult.OK); } else { return(DialogResult.Cancel); } } finally { Marshal.FreeCoTaskMem(lpCustColors); } }
public DialogResult ShowDialog() { var ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); if (string.IsNullOrWhiteSpace(Filter)) { ofn.filter = null; } else { ofn.filter = Filter; } ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; if (string.IsNullOrWhiteSpace(InitialDirectory)) { ofn.initialDir = null; } else { ofn.initialDir = InitialDirectory; } if (string.IsNullOrWhiteSpace(Title)) { ofn.title = null; } else { ofn.title = Title; } if (string.IsNullOrWhiteSpace(DefaultExtension)) { ofn.defExt = null; } else { ofn.defExt = DefaultExtension; } if (Win32Dialogs.GetOpenFileName(ofn)) { File = ofn.file; return(DialogResult.OK); } else { return(DialogResult.Cancel); } }