I now have a solution (at least, a sort of solution). Solving one problem creates two more. And this is exactly what has happened here, so when I've got some more time I will look into this again.
The original requirement was to disable the ScrollBars in the MdiClient window. The CodeProject solution did this (and a lot more), but there was an unpleasant flickering when the child forms were moved around in the MdiClient workspace. My solution solves this, but:
Unless the parent form is maximized before my solution is applied, the parent form's BackgroundImage is corrupted.
Manually resizing the parent form corrupts its BackgroundImage.
I have provided workarounds for these two problems, but I am not completely happy with them, hence when I have some more time available I will look into this further.
First of all the solution:
I've rewritten the original incorporating just the parts that are necessary for disabling the ScrollBars, and making some changes to the logic to simplify it slightly.
Add a new Class file to you project, and delete the default text. Then paste this into the file:
Code:
Imports System
Imports System.Drawing
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Public Class MdiClientWithoutScrollBars
Inherits NativeWindow
Implements IComponent
Implements IDisposable
Private FParentForm As Form
Private FMdiClient As MdiClient
Private FSite As ISite
Private Const WFNCCALCSIZE As Integer = 131
Private Const SB_BOTH As Integer = 3
<DllImport("user32.dll")> _
Private Shared Function ShowScrollBar(ByVal hWnd As IntPtr, ByVal wBar As Integer, ByVal bShow As Integer) As Integer
End Function
Public Sub New(ByVal TheParentForm As Form)
FSite = Nothing
FParentForm = TheParentForm
FMdiClient = Nothing
If Not FParentForm.IsMdiContainer Then FParentForm.IsMdiContainer = True
For a As Integer = 0 To FParentForm.Controls.Count - 1
FMdiClient = TryCast(FParentForm.Controls(a), MdiClient)
If FMdiClient IsNot Nothing Then
ReleaseHandle()
AssignHandle(FMdiClient.Handle)
Exit For
End If
Next
End Sub
Public Event Disposed As EventHandler Implements IComponent.Disposed
Public Property Site() As ISite Implements IComponent.Site
Get
Return FSite
End Get
Set(ByVal value As ISite)
FSite = value
If FSite Is Nothing Then
Return
End If
End Set
End Property
Public Sub Dispose() Implements IComponent.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If disposing Then
SyncLock Me
If FSite IsNot Nothing AndAlso FSite.Container IsNot Nothing Then
FSite.Container.Remove(Me)
End If
RaiseEvent Disposed(Me, EventArgs.Empty)
End SyncLock
End If
End Sub
Protected Overloads Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WFNCCALCSIZE Then
ShowScrollBar(m.HWnd, SB_BOTH, 0)
End If
MyBase.WndProc(m)
End Sub
End Class
To use this class and apply the workarounds add these code snippets to your MdiParent form.
Code:
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
WindowState = FormWindowState.Maximized
Dim mdi As New MdiClientWithoutScrollBars(Me)
End Sub
Code:
Private Sub Form1_ResizeEnd(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ResizeEnd
Me.Refresh()
End Sub
Due to the changes that I have made, you no longer need to set the IsMdiContainer property in the MdiParent form, this is now done automatically. However you will need to set the BackgroundImage and BackgroundImageLayout properties in the MdiParent form as these are not currently handled by my version. You do not need to add any controls to your project, just the Class file and the code in Sub New as shown above.
Hope this helps.
![[vampire] [vampire] [vampire]](/data/assets/smilies/vampire.gif)
![[bat] [bat] [bat]](/data/assets/smilies/bat.gif)