Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How disable scrollbars in a maximized mdi parent form? 4

Status
Not open for further replies.

FemPro

Programmer
Feb 15, 2008
28
GR
Hello everyone.
I have a mdi parent window state maximized form and many mdi child forms. When i load a child form and move it, the scrollbars are appearing in the parent form. How can i disable the scrollbars in mdi parent form? Any help will be much appreciated.

Thank you
in advanced
FemPro.
 
earthandfire what do you mean "not without rewriting the underlying redraw code"? Which code is this?
 
The file that would need to be modified is MdiClientController.cs, however I haven't yet had time to work fully through it. My c# is not good enough to do this quickly, and I probably won't get a chance to spend enough time on it for a couple of weeks. However, it is an interesting exercise, and I will have a look at it. If you want to experiment yourself, the method DrawImage seems to be the best place to start.

By the way, thanks for the star, but, if andrea96 hadn't found this link, I don't think we would have come up with any form of realistic solution!

[vampire][bat]
 
Thank you again so much earthandfire when i told "when run the program and move the child form i can see the its track" i meant its breadcrumb if this is the right word to describe it better. I will be very happy, if you spend "a little time" to help me again to solve my problem. Also i will never stop searching and experiment myself.
And ofcource a star for andrea found the source code!

Thanks anyone
in advance.
 
If you want to try the code out yourself, have a look at:


this will enable you to convert the c# into VB.

As usual, nothing is straightforward ... although this is one of the best converters that I have found, the translated code will almost certainly not work unedited.

I will definitely be experimenting with the code myself over the next couple of weeks and will post back when I have made some progress.



[vampire][bat]
 
That's a great tool thank you much. The code that is being converted must me place onto a class or a module in vb 2005?
 
i 've did it but i am getting an error Error
'Namespace' statements can occur only at file or namespace level. in statement Namespace Slusser.Components i don't know why.
 
When you create a new Class Library project, VS creates a file called Class1.vb, which looks like:

Code:
Public Class Class1

End Class

Delete those two statements and then paste the code in and it should be ok - but you are likely to get quite a few other errors, those will probably include errors to do with these lines:

Implements IComponent
Implements IDisposable

plus, if you have Option Strict On, several relating to type conversion failures.

The type conversion errors are easy to correct (just wrap them in CType(expression causing the problem, requiredtype) statements). The Interface problems, I don't have time to look at now because that involves a more detailed analysis of the code.

[vampire][bat]
 
I've had a quick play with this, but it didn't seem to remove the dragging effects - all I've done at this stage for testing purposes is to move the range calculations into WndProc when the resize message is sent - but I think more will have to be done.

[vampire][bat]
 
chrissie, I escaped at Christmas. No more Java, no more WebSphere - yippee!!

By the way chrissie, I seem to be having ltd difficulties - any help would be gratefully received.

[vampire][bat]
 
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][bat]
 
E&F thank you very much once more for your effort!

What do you mean "Unless the parent form is maximized before my solution is applied, the parent form's BackgroundImage is corrupted."

There is no problem about "Manually resizing the parent form corrupts its BackgroundImage." because i have set the mdi parent's AutoSizeMode to GrowAndShrink.
Also i want the mdi parent form always maximized from the startup position as i have set it up to when the user closes the program. But i think that if i set the maximizebox to false it would be ok.

Well, just one more question, the C:\CodeProjectDownloads\mdiclientcontroller_src\MdiClientController\bin\Release\MdiClientController.dll i located as i followed your instractions, does is it still necassary? I deleted the MdiClientController for my mdi parent form and i saw that's works nice without it. Must i have to delete the dll from bin\Debug folder which exists there with the execution file?

Thank you
so much again.
 
The testing that I did was with one of the picture files that comes with Windows and unless the form was Maximized prior to instanciating MdiClientWithoutScrollBars the Image was slightly corrupted. Also, the Image gets slightly corrupted during manual resizing. With the settings you have suggested i.e.:

[Tab]AutoSizeMode = GrowAndShrink
[Tab]MaximizeBox = False

those problems disappear.

Yes, you can delete MdiClientController.dll form both your bin\debug foldfer and your bin\release folder. Additionally check your references under Solution Explorer, there may still be a reference to the library, if there is then you can delete that as well.

You can also delete the line:

[tt] WindowState = FormWindowState.Maximized
[/tt]


from your Parent form as that is now no longer needed and also you can get rid of the three lines for the Resize.End event as they are no longer needed.


Hope this helps.


[vampire][bat]
 
By the way, even a Maximized window with the Restore/Maximize button disabled can be "Restored", by double-clicking in the TitleBar.

This should prevent that from happening:

Code:
	Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize

		WindowState = FormWindowState.Maximized

	End Sub


[vampire][bat]
 
Thank you so much earthandfire, really nice job.
This is a nice idea, but i think it would be better to stay always maximized and not see that is restoring and maximizing automatically. Also this prevents user minimizing the window. Is there a way to do these?
 
Code:
Protected Overloads Overrides Sub WndProc(ByRef m As Message)
        MyBase.WndProc(m)
    End Sub
Knowing about this little part is quite helpful.

-I hate Microsoft!
-Forever and always forward.
 
Question, unless the answer will totally derail this topic, but what (if any) is the deferenece between:

Code:
Imports System.Runtime.InteropServices.

    <DllImport("user32.dll")> _
    Private Shared Function ShowScrollBar(ByVal hWnd As IntPtr, ByVal wBar As Integer, ByVal bShow As Integer) As Integer
    End Function

And
Code:
    Private Declare Sub ShowScrollBar Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal wBar As Integer, ByVal bShow As Integer)

I assume the only difference is in the first you can do processing when the event actually fires? I guess what I'm trying to make sure is that one isn't more correct to use than the other?

-I hate Microsoft!
-Forever and always forward.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top