none
minimize, maximize, and close button image...

    Question

  • hey,

    In Visual C# 2005 express how would I use some images I made for the minimize, maximize, and close buttons, and change the defaults to the ones I made?

    The images are .PNG if that is somthing you need to know...

     

     

    Thanks :)

    Monday, July 17, 2006 1:22 AM

Answers

All replies

  • I don't believe you can change the images alone without changing the entire form. 

    The way alot of people do it is you create a borderless form and write all the code to move, minimize, maximize, restore window and close the form yourself.  All of that is extremely easy except for the "code the form to move" part.  I have never got that part to work so I gave up on custom graphical forms.

    There is a tutorial in the MSDN Library on how to do all this, it has examples in C# even.  Search in the index for non-shaped forms.
    Monday, July 17, 2006 2:29 AM
  • k, I did a search in the MSDN library for non-shaped forms and it found nothing... ... ...

     

     

     

    Thanks :)

    Monday, July 17, 2006 3:08 AM
  • using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

    namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private Point mouseOffset;
            private bool isMouseDown = false;

            private void MOUSEDOWNEVENT(object sender, MouseEventArgs e)
            {
                int xOffset;
                int yOffset;

                if (e.Button == MouseButtons.Left)
                {
                    xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
                    yOffset = -e.Y - SystemInformation.CaptionHeight -
                        SystemInformation.FrameBorderSize.Height;
                    mouseOffset = new Point(xOffset, yOffset);
                    isMouseDown = true;
                }
            }

            private void MOUSEMOVEEVENT(object sender, MouseEventArgs e)
            {
                if (isMouseDown)
                {
                    Point mousePos = Control.MousePosition;
                    mousePos.Offset(mouseOffset.X, mouseOffset.Y);
                    Location = mousePos;
                }

            }

            private void MOUSEUPEVENT(object sender, MouseEventArgs e)
            {
                // Changes the isMouseDown field so that the form does
                // not move unless the user is pressing the left mouse button.
                if (e.Button == MouseButtons.Left)
                {
                    isMouseDown = false;
                }

            }
        }
    }

    There is the code for you.  It works as well.  The only thing you have left to do is code the form to be minimized, maximized, and closed.

    Use these:

    WindowState = FormWindowState.Minimized;
    WindowState = FormWindowState.Maximized;

    To use those, just create buttons, and put each of those in the buttons click event.  You should know how to make a close button.

    Then just set each buttons background image to your images. 
    Monday, July 17, 2006 5:07 AM
  • Also on a side note, I do not know how to write the code to allow the user to right click and close the application from the task bar.
    Monday, July 17, 2006 5:11 AM
  • ok, I think I see what you are saying, so then the button part, in order to create my own top border...the part with the words and contains the buttons, I would have to make the image there on the top of the form and then add the buttons inside of it and keep it docked there?

     

    EDIT: actualy ya thta is the way I guess I should do it, but how do I make the image(topbar that hold the buttons witch I will put in seperatly) stay docked at the top of the toolstrips? becuase if I try to dock it at the top the 2 toolstrips stay at the verry top and the image is at the top of everything but the toolstrips, so how would I do this?

     

     

    Thanks :)

    Monday, July 17, 2006 5:03 PM
  • Yet again borderless form. Try this thread. There is a website to get a full-implementation of window with custom border for free. It uses images to draw the control box and elements.


    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=458067&SiteID=1

     

    Monday, July 17, 2006 10:10 PM
  • So I am gunna have to do alot of code just to make a image stay docked above everything?

     

     

     

     

    Thanks :)

    Monday, July 17, 2006 10:38 PM
  • Ok, I looked at the link and then the link that has the custom border skin code stuff, I downloaded the project and copyed the code to see if it worked, I edited parts that had errors to fix my programs settings and then I ran the program, and it still has no border, so I tryed putting fixed3D border on to see if it would work, but it has the windows default still, So I put it back to no border... so what should I do?

     

     

    Thanks :)

    Tuesday, July 18, 2006 8:26 PM
  • The DemoForm should be fully implemented with custom border.
    Wednesday, July 19, 2006 3:17 PM
  • opps,

    I actualy forgot to make it so it reads the file, it works now, but I ahve a problem thta I think I can fix but I need help, on form1's code were it has this:

    public partial class Form1 : Form

    how do I make it so it can have Form1, Form, AND LonghornForm?

    becuase the form got a little messed up when I took out Form and made it LonghornForm.

    I think I can fix this by having all 3, is this possible?

     

     

     

    Thanks :)

    Wednesday, July 19, 2006 6:39 PM
  • You inherit directly from LonghornForm. I think I used the demoform as my base class instead of longhorn.

    Wednesday, July 19, 2006 7:54 PM
  • Well...is there a reason why the form's toolbar all the sudden has all of it's controls missing? and for some reason allt he sudden the top border of the form goes transparent on one side and I can see the toolbar control behind the topborder? it looks really strange, lol

     

     

     

     

    Thanks :)

     

    EDIT:

    OK, so I took out all of the files thta made the border skin and made everything back to the way it was before I added the skin, so everything is normal EXCEPT for the toolstrip al, of it's items are still missing... I checked in Form1.Desighner and aparently the items still exist but are nowhere to be found.... ... ...what should I do?

     

     

    Thanks :)

    Thursday, July 20, 2006 12:56 AM
  • Ok,

    I have made the skinning thing work, it looks fine, but there is one problem...

    The Close, maximize, restore, and minimize buttons are to far down...I want them to be at the very top of the TopBorder...like the Windows Vista ones are...

    I looked int he code below for somthing that does what I am trying to do but I dont see anything...so is there anything in the code below that will do what I am trying to do?

    #region Using directives

    using System;

    using System.Drawing;

    using System.Drawing.Drawing2D;

    using System.Windows.Forms;

    #endregion

    namespace notebook_pro

    {

    public class LonghornForm : CustomBorderForm

    {

    public LonghornForm()

    {

    }

    protected override void OnResize(EventArgs e)

    {

    base.OnResize(e);

    int diam = 10;

    GraphicsPath path = new GraphicsPath();

    path.AddArc(0, 0, diam, diam, -90, -90);

    path.AddLines(new Point[] {new Point(0,diam), new Point(0, Height),

    new Point(Width, Height), new Point(Width, diam)});

    path.AddArc(Width - diam, 0, diam, diam, 0, -90);

    path.CloseFigure();

    this.Region = new Region(path);

    }

    protected override CustomBorderAppearance CreateBorderAppearance

    {

    get

    {

    CustomBorderAppearance appearance = new CustomBorderAppearance();

    appearance.BorderTop = Properties.Resources.BorderTop;

    appearance.BorderTopLeft = Properties.Resources.BorderTopLeft;

    appearance.BorderTopRight = Properties.Resources.BorderTopRight;

    appearance.BorderRight = Properties.Resources.BorderRight;

    appearance.BorderLeft = Properties.Resources.BorderLeft;

    appearance.BorderBottom = Properties.Resources.BorderBottom;

    appearance.BorderBottomLeft = Properties.Resources.BorderBottomLeft;

    appearance.BorderBottomRight = Properties.Resources.BorderBottomRight;

    appearance.BorderTopSizing = SizingType.Stretch;

    appearance.BorderBottomSizing = SizingType.Stretch;

    appearance.BorderLeftSizing = SizingType.Tile;

    appearance.BorderRightSizing = SizingType.Tile;

    appearance.CloseButton.ImageNormal = Properties.Resources.Close;

    appearance.CloseButton.ImageDisabled = Properties.Resources.CloseDisabled;

    appearance.CloseButton.ImageActive = Properties.Resources.ClosePressed;

    appearance.CloseButton.ImageHover = Properties.Resources.CloseHot;

    appearance.MaximizeButton.ImageNormal = Properties.Resources.Maximize;

    appearance.MaximizeButton.ImageDisabled = Properties.Resources.MaximizeDisabled;

    appearance.MaximizeButton.ImageActive = Properties.Resources.MaximizePressed;

    appearance.MaximizeButton.ImageHover = Properties.Resources.MaximizeHot;

    appearance.MinimizeButton.ImageNormal = Properties.Resources.Minimize;

    appearance.MinimizeButton.ImageDisabled = Properties.Resources.MinimizeDisabled;

    appearance.MinimizeButton.ImageActive = Properties.Resources.MinimizePressed;

    appearance.MinimizeButton.ImageHover = Properties.Resources.MinimizeHot;

    appearance.RestoreButton.ImageNormal = Properties.Resources.Restore;

    appearance.RestoreButton.ImageDisabled = Properties.Resources.RestoreDisabled;

    appearance.RestoreButton.ImageActive = Properties.Resources.RestorePressed;

    appearance.RestoreButton.ImageHover = Properties.Resources.RestoreHot;

    appearance.ButtonSize = Properties.Resources.Close.Size;

    appearance.ButtonSpacing = 1;

    appearance.TitleColor = Color.White;

    appearance.TitleFont = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);

    //this.DoubleBuffered = true;

    appearance.BorderSize = new Padding(3);

    appearance.TitleBarSize = 32;

    this.NonClientAreaDoubleBuffering = true;

    return appearance;

    }

    }

    }

    }

     

    thanks )

    Tuesday, August 08, 2006 8:10 PM
  • What about this 2 settings? Have you played around with these?

    appearance.BorderSize = new Padding(3);

    appearance.TitleBarSize = 32;

     

    The other thing is that the actual images used for the buttons are probably padded already.

     

    Thursday, August 10, 2006 8:16 PM
  • ya, I have.

    the second one it the size of the topbar, and the first one is the border size.

    the buttons are 10 pixels away from the top...

    Friday, August 11, 2006 1:05 AM