View Full Version : Replacing default close button (C#)
Alex007152
03-13-2007, 03:12 AM
Hi, I'm having trouble with replacing the default close button of my form with my own icon. What i basicaly want as result is something similiar to this:
http://img259.imageshack.us/img259/7335/game1ud7.png
It would be nice if i could replace that whole part in my form with my own one, like CCP did with the EVE Online client. Did anyone succeed in this and know how to do it in Visual C#?
Thanks in advance. :happy:
Reedbeta
03-13-2007, 11:37 AM
The Eve window is probably entirely owner-drawn. It doesn't replace the Windows close button with its own but rather has no Windows title bar at all, and has created its own button that closes the window. I don't know precisely how you do this in C# but it should be an option in the form designer someplace. (In Win32, you'd do it by omitting the WS_CAPTION style in the CreateWindow call.)
Alex007152
03-13-2007, 03:50 PM
The Eve window is probably entirely owner-drawn. It doesn't replace the Windows close button with its own but rather has no Windows title bar at all, and has created its own button that closes the window. I don't know precisely how you do this in C# but it should be an option in the form designer someplace. (In Win32, you'd do it by omitting the WS_CAPTION style in the CreateWindow call.)
Thanks for the reply. I just had a responce from another development community:
http://forums.csharpcorner.com/F_ShowMessages.aspx?ThreadID=28756
Apparantly they removed the title bar and created their own close button indeed. Here's where the form border style can be configured in Visual C# (2005 express edition):
http://img404.imageshack.us/img404/417/scr2oj9.png
Glad to have this pointed out :)
SmokingRope
03-15-2007, 05:23 AM
You could simulate the same behavior as that checkbox by using delegate functions, imported from user32.dll!
public const int WS_CAPTION = 0x00C00000;
public const int GWL_STYLE = -16;
[DllImport("user32")]
public static extern int SetWindowLong(IntPtr pWnd, int pIndex, int pVal);
[DllImport("user32")]
public static extern int GetWindowLong(IntPtr pWnd, int pIndex);
// In Constructor
SetWindowLong(this.Handle, GWL_STYLE, ~WS_CAPTION & GetWindowLong(this.Handle, GWL_STYLE) );
this.Invalidate() // May not be necessarry ...
SmokingRope
03-16-2007, 11:16 AM
I forgot two things in the above post. Firstly you need to add an import declaration:
import System.Runtime.InteropServices;
Also invalidate wasn't sufficient for forcing the window to redraw.
public const int SW_MINIMIZE = 3;
public const int SW_RESTORE = 6;
[DllImport("user32")]
public static extern bool ShowWindow(IntPtr pWnd, int pCmd);
// In Constructor After Invalidate()
ShowWindow(this.Handle, SW_MINIMIZE);
ShowWindow(this.Handle, SW_RESTORE);
If there's a better way for doing the refresh, i'd be interested to see it.
Reedbeta
03-16-2007, 03:36 PM
It should suffice to just change the window style before the window is painted for the first time, e.g. in the constructor. Also, you don't have to muck around with the WinAPI there, you can just set
this.FormBorderStyle = FormBorderStyle.None;
but it's simpler to just do it in the form designer as Alex posted.
vBulletin, Copyright ©2000-2010, Jelsoft Enterprises Ltd.