WinForm
Things related to coding C# WinForm applications in .Net
If you want to snag clipboard data from a different application into the context of your running .Net application, here's how you can do it:
private static Image _clipBoardImage = null;
private static Image GetImageFromCopyPasteBuffer()
{
Thread t = new Thread(new ThreadStart(GetClipboardBitmap));
t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();
return _clipBoardImage;
}
private static void GetClipboardBitmap()
{
IDataObject data = Clipboard.GetDataObject();
if (data == null || !data.GetDataPresent(DataFormats.Bitmap, true))
throw new ApplicationException("No clipboard image data was present.");
_clipBoardImage = (Image)data.GetData(DataFormats.Bitmap);
}
Hope this helps!
It is relatively easy to control access to the various HTTP request types (protocols) for your ASP.Net WebService.
Add something like this to the system.web section of your web.config:
<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpGet"/> <!-- Because this web service is all GET methods -->
<add name="HttpPostLocalhost"/> <!-- So you can test/POST locally -->
<remove name="Documentation"/> <!-- So the outside world can't see your methods documentation -->
<remove name="HttpPost"/> <!-- Remove general POSTs from the outside world -->
</protocols>
</webServices>
Of course you will want to tailor this to the needs of your own web service. :)
Yeah, this really has nothing to do with programming, but wow, was this annoying. Some how, Outlook shrunk itself down to just the title bar and I couldn't find a way to restore it to a useful size (it was either just the title bar or fully maximized).
Lo and behold, there is a handy-dandy way to resize your windows.
First, Restore the window. Next, right-click on the title bar and choose "Size". This allows you to customize (and fix whatever borked it) the window size.
Always check your context menu is the moral of the story I guess...
Here's a general way to catch most outside exceptions in your WinForm code. Add this to your program wrapper:
Normal
0
false
false
false
EN-US
X-NONE
X-NONE
MicrosoftInternetExplorer4
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:"Times New Roman";
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
Application.ThreadException +=
new ThreadExceptionEventHandler(Application_ThreadException);
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Of course, it is always better to handle specific cases with specific types of exceptions, but it is also nice to have a general handler for anything that escapes your exception handling.