in visual c# express edition 2005 is it possible to add your own window border, like in some programs there are custom made min,max and close buttons instead of the xp ones. how can i do it in visual studio??:p

Dani AI

Generated

asked about making a custom window frame in Visual C# (Express 2005). pointed toward removing the standard chrome and drawing your own controls; below is a concise, practical expansion that fills in the missing steps and common pitfalls. s separate question about reporting errors to a remote DB is off-topic for this thread and should be posted separately; a quick note on that appears at the end.

Make the OS chrome go away and implement three pieces yourself: a draggable title area, custom Min/Max/Close handlers, and hit-testing for resize. The minimal move handler uses two Win32 calls (ReleaseCapture + SendMessage) from a mouse-down on your title bar. Example move code:

using System.Runtime.InteropServices;

const int WM_NCLBUTTONDOWN = 0x00A1;
const int HTCAPTION = 0x02;

[DllImport("user32.dll")]
static extern bool ReleaseCapture();

[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

private void titleBar_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        ReleaseCapture();
        SendMessage(this.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
    }
}

To allow the user to resize, override WndProc and answer WM_NCHITTEST with the appropriate HT* values based on cursor position near window edges/corners. A common approach checks a few pixels from each border and returns HTLEFT, HTRIGHT, HTTOP, HTBOTTOM, HTTOPLEFT, etc., so Windows handles resizing for you.

private const int WM_NCHITTEST = 0x84;
private const int HTCLIENT = 1;
private const int HTLEFT = 10;
private const int HTRIGHT = 11;
private const int HTTOP = 12;
private const int HTTOPLEFT = 13;
private const int HTTOPRIGHT = 14;
private const int HTBOTTOM = 15;
private const int HTBOTTOMLEFT = 16;
private const int HTBOTTOMRIGHT = 17;
private const int resizeBorder = 6;

protected override void WndProc(ref Message m)
{
    if (m.Msg == WM_NCHITTEST)
    {
        base.WndProc(ref m);
        if ((int)m.Result == HTCLIENT)
        {
            int lParam = m.LParam.ToInt32();
            Point pos = PointToClient(new Point(lParam & 0xffff, lParam >> 16));
            if (pos.X <= resizeBorder && pos.Y <= resizeBorder) m.Result = (IntPtr)HTTOPLEFT;
            else if (pos.X >= ClientSize.Width - resizeBorder && pos.Y <= resizeBorder) m.Result = (IntPtr)HTTOPRIGHT;
            else if (pos.X <= resizeBorder) m.Result = (IntPtr)HTLEFT;
            else if (pos.X >= ClientSize.Width - resizeBorder) m.Result = (IntPtr)HTRIGHT;
            else if (pos.Y <= resizeBorder) m.Result = (IntPtr)HTTOP;
            else if (pos.Y >= ClientSize.Height - resizeBorder) m.Result = (IntPtr)HTBOTTOM;
        }
        return;
    }
    base.WndProc(ref m);
}

Additional points: wire your custom buttons to set WindowState (minimize/maximize) or call Close(). Test keyboard shortcuts and accessibility (Alt+F4, taskbar behavior, screen readers). Use double buffering or optimized painting to avoid flicker. For heavy chrome work, consider WPF (templates/WindowChrome) in newer toolsets—it simplifies custom frames. Visual C# Express 2005 supports WinForms-based custom chrome; the shown techniques work there.

For : for server-side error collection use structured logging or an error handler that posts exceptions to a web service which stores them in the DB; for ASP.NET, frameworks like ELMAH or a logging library (log4net/NLog) + a small web API are common solutions — start a new thread with your platform details and sample code for targeted help.

Recommended Answers

All 3 Replies

anyone?

hi all,

I want to catch an error and report to a remote Database in a server.how can i do it?
can any one help me..

thankz

set the FormBorderStyle to none and then add your customized buttons

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.