开发者

Create a System-tray styled box in Winforms (C#)

开发者 https://www.devze.com 2022-12-19 03:39 出处:网络
I\'ve been hunting about for some resources on this, and I can\'t find any, so I\'ll bring in here. I want to make a window similar in style to the quick launch box which you see when you open the qu

I've been hunting about for some resources on this, and I can't find any, so I'll bring in here.

I want to make a window similar in style to the quick launch box which you see when you open the quick launch bar:

Example Window http://img63.imageshack.开发者_开发百科us/img63/6204/volcontrolstyleguide.png

Sadly, I can't find any resources on this; can you help me out?


It's quite simple. Create a new form, and set ControlBox, MaximizeBox, and MinimizeBox properties to false. Set the Title property to an empty string. This will effectively eliminate the the nonclient title bar area, giving you this:

Create a System-tray styled box in Winforms (C#)

The the interior section (like with "Customize") can be duplicated with a properly sized Panel and Link.


Assumptions :

  1. this is a fixed size form, never re-sizable

  2. you want this to work on XP as well as Vista (i.e., without using Vista specific techniques like 'Glass). I mention this because, after all, the System Tray does go back to the late paleolithic :)

Here's how :

  1. create a Form the same size as your .png file

  2. set the ControlBox, MaximizeBox, MinimizeBox properties to 'false

  3. set FormBorderStyle to 'None

  4. set the transparency key of the Form to some color, and set the background color of the Form to the same color : note use a color that does not occur in the .png file.

  5. put a PictureBox on the Form, set its Dock property to 'Fill : set its Margin property #0 for all Margins : set its BackColor to 'Transparent : then, naturally, set the Image property of the PictureBox to your .png file.

NOTE :

If you have prepared your .png image so it is bounded by a transparent area so that it appears rounded : you can use that directly and skip over the whole step of actually making the Form a Rounded Rectangle by use of an API call to set the Region of the Form : this does mean your Form will have a standard rectangular bounding box. If you can live with this : this is a simpler solution. For how to set the Region : read on ...

  1. see "How to make form rounded rectangle or round or triangle" here on SO for how to set the Region of the Form to a RoundedRect : this SO entry has several other links in it to code examples : the link mentioned by Zyphrax here uses the same basic technique.

  2. experiment with the settings to the 'CreateRoundRect to get the rounded corner effect you want.


That sounds like you need Windows 7 API Code Pack, in which some API's are backward compatible with Vista. Since the specific version of Windows is not stated, I cannot say specifically..you could look here and here on CodeProject how this is accomplished.

Hope this helps, Best regards, Tom.


You can take an normal Form and modify it to look like your screenshot:

  1. Set the FormBorderStyle property to None
  2. Round the corners of your form: more info here
  3. (Extend the glass if you like: more info here, only Vista or higher)
  4. Set the background to White and add some controls to finish it off
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号