Preventing MCI Client Form From Drawing Borders

A

alw

Why does Form2 below draw borders (on 2nd and subsequent Shows) in
spite of every attempt to prevent it...
Code:
Public Class Form1
Dim frm2 As Form2
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Me.IsMdiContainer = True
frm2 = New Form2
frm2.MdiParent = Me
Me.Size = New Size(300, 300)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Me.Show()
frm2.Show()
End Sub
End Class
'--------------------------------------
Public Class Form2
Dim WithEvents Timer1 As Timer
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.StartPosition =
System.Windows.Forms.FormStartPosition.Manual
Me.Size = New Size(200, 200)
Me.Location = New Point(50, 50)
Timer1 = New Timer
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Form2_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
' The above works OK here and the Non-Client Area is NOT
painted on first Show
' But if form is hidden and reshown, as in Timer1_Tick()
below,
' it DOES paint the Non-Client Area
End Sub
Private Sub Form_Layout(ByVal sender As Object, ByVal e As
LayoutEventArgs) Handles MyBase.Layout
' Neither statement works here to prevent NCA drawing
'SetWindowLong(Me.Handle, GWL_EXSTYLE, IntPtr.Zero)
'Me.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.None
End Sub

Private Sub Form2_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint
' This would paint entire Form space, including borders
'e.Graphics.FillRectangle(Brushes.White, Me.ClientRectangle)
End Sub
Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
' Non-Client Area still gets painted even though it should
not!
Const WM_NCPAINT As Int32 = &H85
If m.Msg <> WM_NCPAINT Then MyBase.WndProc(m)
End Sub
Protected Overrides Sub OnPaintBackground(ByVal e As
System.Windows.Forms.PaintEventArgs)
' This would paint entire Form space, including borders
'MyBase.OnPaintBackground(e)
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Me.Hide()
' Shouldn't be necessary to repeat this, but even so, it has
no effect ...
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
' The following still paints the Non-Client Area, even tho'
there should be no borders!
Me.Show()
End Sub
End Class
 
A

alw

As a Postscript, I have found that using SetWindowLong to remove the
WS_EX_CLIENTEDGE style (and WS_BORDER), as suggested in numerous other
posts, does not work. As with setting the FormBorderStyle, it works
for the first time the Form is displayed. But, if the form is
subsequently hidden and then reshown, it goes through: Resize,
ClientResize, Activated, Resize, ClientResize & StyleChange before
finally showing!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top