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

后端 未结 4 694
感动是毒
感动是毒 2020-12-09 14:08

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

相关标签:
4条回答
  • 2020-12-09 14:24

    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 讨论(0)
  • 2020-12-09 14:27

    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:

    Simple winforms window without nonclient area

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

    0 讨论(0)
  • 2020-12-09 14:37

    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.

    0 讨论(0)
  • 2020-12-09 14:44

    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.

    0 讨论(0)
提交回复
热议问题