Navigation

Search

Categories

On this page

Windows Forms - How to disable the close button
Generics FAQ - from fundamentals to best practices
Professional Developers Conference 2005 (PDC2005) Sessions Download
Microsoft taking their bugs seriously
My Ultimate Tool List
Modern Office Slang
Web Design Wisdom
How to send really big files
Website Design Reviews at Unmatched Style
Sometimes even Darth needs to relax
Professional Fonts
Form Help without Popups
Coloured Nerds
Ten Best Things To Say If You Get Caught Sleeping At Your Desk
John Martz -- Illustrator

Archive

Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 178
This Year: 0
This Month: 0
This Week: 0
Comments: 551

Sign In

 Sunday, October 30, 2005
Sunday, October 30, 2005 12:36:39 PM UTC (  |  )

Here is a snippet of code I found on the microsoft.public.dotnet.framework.windowsforms newsgroup to disable the close button on a windows forms application whilst maintaining the minimize and restore buttons..

1) Add a reference to System.Runtime.InteropServices at the top of your form, like so:

using System.Runtime.InteropServices;

2) Add references to the required Win32 functions and constants, like so:

[DllImport("User32.dll", CharSet=CharSet.Auto)]
private static extern IntPtr GetSystemMenu ( IntPtr hWnd, int bRevert );

[DllImport("User32.dll", CharSet=CharSet.Auto)]
private static extern int GetMenuItemCount(IntPtr hMenu);

[DllImport("User32.dll", CharSet=CharSet.Auto)]
private static extern int DrawMenuBar(IntPtr hWnd);

[DllImport("User32.dll", CharSet=CharSet.Auto)]
private static extern int RemoveMenu(IntPtr hMenu, int nPosition, int wFlags);

private const int MF_BYPOSITION = 0x400;
private const int MF_REMOVE = 0x1000;

3) Create the RemoveCloseButton function that does the magic:

private void RemoveCloseButton(Form frmForm)
{
  IntPtr hMenu;
  int n;
  hMenu = GetSystemMenu(frmForm.Handle, 0);
  if (!(hMenu == IntPtr.Zero))
  {
    n = GetMenuItemCount(hMenu);
    if (n > 0)
    {
      RemoveMenu(hMenu, n - 1, MF_BYPOSITION);
      RemoveMenu(hMenu, n - 2, MF_BYPOSITION);
    }
    DrawMenuBar(frmForm.Handle);
  }
}

4) Make a call to the RemoveCloseButton function in your form constructor, like so:

public Form1()
{
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent();

  //
  // TODO: Add any constructor code after InitializeComponent call
  //
  RemoveCloseButton(this);
}

That's it, give it a try and watch in amazement as your close button is disabled.
BTW,
here is the link to the original forum post. 

| Trackback | # 
Sunday, October 30, 2005 10:31:19 AM UTC (  |  )

MSDN has published 4 FAQ articles on Generics that  should cover just about everything you would ever want to know about generic types. 

I haven't had to delve into the depths of Generics yet so I'm just going to hang on to these links for when I need to go into battle.

| Trackback | # 
 Tuesday, October 25, 2005
Monday, October 24, 2005 4:44:48 PM UTC ( )

It looks like the PDC05 session content is going to be available online for 6 months.  Download'em while you can.  Just looking at the session topics it looks like most of the stuff is VS2005 and beyond so VB6 programmers don't bother looking here unless you want to know what the future will look like. :)

You can also buy a DVD of the content if you don't want to go on a download frenzy... but who doesn't!?!

| Trackback | # 
 Monday, October 24, 2005
Monday, October 24, 2005 11:30:17 AM UTC ( )

The upcoming release of Vista is looking like it will be a much more reliable product than any previous release of Windows, and for good reason too.  Check out this video to see what I mean.

| Trackback | # 
 Thursday, October 20, 2005
Thursday, October 20, 2005 10:44:30 AM UTC (  |  )

Inspired by the wonderful Scott Hanselman and his fantastic Ultimate Tool List I've decided to share my very own list of tools that I love to use and that make my life just that little bit easier.

Graphics Tools

  • Windows Clippings - A simple but elegant window capture utility.  It's not as full featured as some other screen capture tools but it sure is executed nicely.  For example, it'll handle rounded edges on windows and do it's best to give your captured images meaningful names.  What it doesn't do is allow you to capture the entire screen or regions.
  • AVEiconifier - This is a great little utility to convert icons to and from PNG files. You can download it here.
  • Cropper - Very clean screen capture utility.  Highly recommended.  source available

Here are some other lists of peoples favourite tools

| Trackback | # 
Wednesday, October 19, 2005 8:44:41 PM UTC ( )
Dictionary of modern office slang
| Trackback | # 
 Tuesday, October 18, 2005
Monday, October 17, 2005 2:01:27 PM UTC (  |  |  |  |  )
There is a great site called YourTotalSite which provides great advice for developers of web applications.  Just little things, usability things, design things, yellow-fadey things, stock photo things, logisticy things... you get the idea.
| Trackback | # 
Monday, October 17, 2005 1:48:47 PM UTC (  |  |  )

YouSendIt is a web site that allows you to send large files to anyone without using email.  It's easy to use, no need to register and can use SSL if you are sending private information.  It has some other solutions in the same product range that allow you to send photo albums (really just a collection of files).

Here is how it works:

  1. Choose who you want to send a file to. It can be anyone with an email address. You can specify multiple email addresses separated by commas.
  2. Select a file to send. You can send photos, audio, documents or anything else. Your file will be stored by YouSendIt without ever filling up your recipient's mailbox.
  3. Click on the Send button. YouSendIt will automatically email your recipient a link to your file stored on our server. Your file will be deleted after 7 days or 25 downloads, whichever occurs first.

The great thing about this site is that it is completely free and does not require registration.  God knows how they make any money.  Maybe they just use the information in the files for extortion -- After all they must see some pretty funny stuff pass by.

| Trackback | # 
Monday, October 17, 2005 1:27:18 PM UTC (  |  |  )

Just thought I'd post a link to this site which does reviews of website designs.  Very nice

http://www.unmatchedstyle.com/

| Trackback | # 
 Monday, October 17, 2005
Monday, October 17, 2005 11:53:25 AM UTC ( )

| Trackback | # 
Monday, October 17, 2005 11:45:03 AM UTC (  |  )
Monday, October 17, 2005 11:02:59 AM UTC (  |  |  |  )

Here is a good little article on providing help on web pages without resorting to popups.  It's nothing particularly now or exciting but I like this solution because of it's simplicity and it is also very intuitive for users.

| Trackback | # 
 Wednesday, October 12, 2005
Tuesday, October 11, 2005 6:32:52 PM UTC ( )

Here is the deal.  99% of all developers should not be allowed to go near user interfaces because they have a demonstrated inability to make things look pretty.  Here is a little tool that may make it a little easier for our nerdy friends (and that means me).  ColorBlender.com | Your free online color matching toolbox

| Trackback | # 
 Wednesday, October 05, 2005
Tuesday, October 04, 2005 3:41:25 PM UTC ( )

10) "They told me at the blood bank this might happen."

9) "This is just a 15 minute power-nap like they raved about in that time management course you sent me to."

8) "Whew! Guess I left the top off the White-Out. You probably got here just in time!"

7) "I wasn't sleeping! I was meditating on the mission statement and envisioning a new paradigm."

6) "I was testing my keyboard for drool resistance."

5) "I was doing a highly specific Yoga exercise to relieve work-related stress. Are you discriminatory toward people who practice Yoga?"

4) "Why did you interrupt me? I had almost figured out a solution to our biggest problem."

3) "The coffee machine is broken..."

2) "Someone must've put decaf in the wrong pot..."

And the #1 best thing to say if you get caught sleeping at your desk...

1) " ... in Jesus' name. Amen."

| Trackback | # 
 Monday, October 03, 2005
Sunday, October 02, 2005 6:34:21 PM UTC ( )

Have a look at John Martz web site.  He is a kick-ass illustrator.  over and out

| Trackback | #