Click here to Skip to main content
15,123,619 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my project I have to display a clock over the MDI form for which I overrided the
method and on
I am creating a rectangle filling it and displaying date text over it.
On running this is working fine over users having Windows 7 machines but when i deployed the same application over Windows 10 all they can see is a line in place of rectangle.

What am I doing wrong or something different needed to do over Windows 10.

Please suggest.

What I have tried:

private void Main_OnNcPaint(ref Message m)
            paintTitleBar = m;
            IntPtr hdc = GetWindowDC(m.HWnd);
            Graphics g = Graphics.FromHdc(hdc);
            RectangleF titleBarRectF = g.VisibleClipBounds;
            int formWidth = (int)titleBarRectF.Width;
            int CaptionHeight = Bounds.Height - ClientRectangle.Height;
            Size CloseButtonSize = SystemInformation.CaptionButtonSize;
            int X = formWidth - (CloseButtonSize.Width * 4) - 200;
            int Y = 4;
            int width = 200;
            int height = CaptionHeight - 10;
            string dateText;            
                dateText = DateTime.Now.ToString("dd MMM yyyy hh:mm:ss tt");          
            RectangleF timeDisplayRectF = new RectangleF(X, Y, width, height);
            g.FillRectangle(new SolidBrush(Color.Black), timeDisplayRectF);            
            Font font = new Font(Font.FontFamily, Font.Size + 2, FontStyle.Bold);
            g.DrawString(dateText, font, new SolidBrush(Color.White), timeDisplayRectF);
            ReleaseDC(m.HWnd, hdc);
            m.Result = IntPtr.Zero;           
Gerry Schmitz 3-Sep-20 8:57am
It's a pointless "hack". Stick to working with controls in the client area.
honeyashu 3-Sep-20 23:36pm
Thanks Gerry. I agree but requirement is I have to display a clock bar on top corner of my application, so the hack.
Gerry Schmitz 4-Sep-20 0:42am
Check your final height. Don't expect Win 10 "defaults" to always match Win 7 / 8.

"int height = CaptionHeight - 10;"
honeyashu 7-Sep-20 2:27am
Tried. But not worked.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900