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.images...35/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:
Replacing default close button (C#)
Started by Alex007152, Mar 13 2007 10:12 AM
5 replies to this topic
#2
Posted 13 March 2007 - 06:37 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.)
reedbeta.com - developer blog, OpenGL demos, and other projects
#3
Posted 13 March 2007 - 10:50 PM
Reedbeta said:
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.csharp...?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):

Glad to have this pointed out :)
#4
Posted 15 March 2007 - 12:23 PM
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 ...
#5
Posted 16 March 2007 - 06:16 PM
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.
If there's a better way for doing the refresh, i'd be interested to see it.
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.
#6
Posted 16 March 2007 - 10: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.
reedbeta.com - developer blog, OpenGL demos, and other projects
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












