Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5944359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:31:35+00:00 2026-05-22T16:31:35+00:00

I have a C# .NET WinForm app which draws to the non-client area. Everything

  • 0

I have a C# .NET WinForm app which draws to the non-client area. Everything works fine and the drawing happens as expected with the exception of when the form loads.

I catch the WM_NCPAINT fine but when i try to get the DC using GetDCEx it always returns null until the form has been displayed which is perfectly logical but that means that the non-client area isnt painted again until the window is resized which means that when the form is first loaded or restored from a minimized state the NC area isnt redrawn and remains white.

This seems to be unique to Windows 7.

So how do I draw to the NC area in this situation?

EDIT: I should add that I dont care about Aero glass and my form disables it entirely.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:31:35+00:00Added an answer on May 22, 2026 at 4:31 pm

    Instead of GetDCEx, I use GetWindowDC. Below is the code I use, and I haven’t had an issue with Windows 7. As Hans commented, the best way is to set the FormBorderStyle to None, but then I like to put in my own borders using this code from csharptest.net

    Imports System.Runtime.InteropServices
    
    Public Class NCForm    
      Inherits Form
    
      Public Sub New()
        Me.FormBorderStyle = FormBorderStyle.None
      End Sub
    
      Protected Overrides Sub WndProc(ByRef m As Message)
        MyBase.WndProc(m)
    
        If m.Msg = Win32.WM_NCCALCSIZE Then        
          If m.WParam <> IntPtr.Zero Then
            Dim tmpResize As Win32.NCCALCSIZE_PARAMS = Marshal.PtrToStructure(m.LParam, GetType(Win32.NCCALCSIZE_PARAMS))
            With tmpResize.rcNewWindow
              .Left += 2
              .Top += 2
              .Right -= 2
              .Bottom -= 2
            End With
            Marshal.StructureToPtr(tmpResize, m.LParam, False)
          Else
            Dim tmpResize As Win32.RECT = Marshal.PtrToStructure(m.LParam, GetType(Win32.RECT))
            With tmpResize
              .Left += 2
              .Top += 2
              .Right -= 2
              .Bottom -= 2
            End With
            Marshal.StructureToPtr(tmpResize, m.LParam, False)
          End If
          m.Result = New IntPtr(1)
    
        ElseIf m.Msg = Win32.WM_NCPAINT Then
          Dim tmpDC as IntPtr = Win32.GetWindowDC(m.HWnd)
          Using tmpG As Graphics = Graphics.FromHdc(tmpDC)
            tmpG.DrawRectangle(Pens.Red, New Rectangle(0, 0, Me.Width - 1, Me.Height - 1))
            tmpG.DrawRectangle(SystemPens.Window, New Rectangle(1, 1, Me.Width-3, Me.Height - 3))
          End Using
          Win32.ReleaseDC(m.HWnd, tmpDC)
        End If
      End Sub
    

    Of course, once you do this, then you have to handle any resize, min-max, closing functionality yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an .NET 4 .exe (Winform Desktop app) to which I have added
I have a .net winforms app which has a few animation effects, fade ins
I've got a VB.NET WinForms app in which I have the need to refer
I have a legacy WinForms Mdi App in VB.Net 2.0 which I am adding
This is my first winform app in .NET... I have made a couple of
I have a .NET C# winforms application which works great on my machine, but
I have a .NET 2.0 app that runs just fine on XP and Vista,
I have a .NET Winform Click-Once-deployed fat client that talks to three databases, 2
I am developing a 32bit WinForm app (target: .NET 3.5). My client insists the
I have the below code in a .Net 4 Winforms app which loads an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.