473,411 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Scrolling bug in MDI client windows

[Cross posted in dotnet.framework.windowsforms and dotnet.languages.csharp,
because it could apply to either]

I have a strange bug in C# using windows forms. To make sure it's not some
bug with my code, I've gone back to a simple test app, and still see the
same behavior.

I have created a simple C# Windows MDI Application, as in MSDN, ie :

1) Create Windows Application (Form1), set IsMDIContainer to true
2) Create MainMenu component in the form, with top level '&File', submenu
'&New' and '&Close', and another top level '&Window' with MDIList set to
true.
3) Create another Form ('Child')
4) Create a Click event handler for the New menu item :
private void New_OnClick(object sender, System.EventArgs e){
Child newMDIChild = new Child();
newMDIChild.MDIParent = this;
newMDIChild.Show();
}

So far so good.

Now I want another window (Form) that appears inside the Child window when I
click it - let's call it a 'SubForm'. I had some problems with this until I
learnt that I could set SubForm.TopLevel = false, and now it's possible.
Like so :

private void Child_Click(object sender, System.EventArgs e)
{
SubForm sub;
sub = new SubForm();
sub.TopLevel = false;
sub.Parent = this;
sub.Show();
}

Obviously I want more functionality, but this makes my point. Now try
running the code. Use 'New' to create a Child window, then click inside that
window to get the sub window.

Here's the problem. If Child has AutoScroll set to true, then when you move
the SubForm so that it is partially outside the Child window (I use the
bottom right of the Child window), scroll bars appear. If you then scroll
down part way, the SubForm moves with the scrolling. But sometimes (only
sometimes) when you then try to move the SubForm (by dragging the titlebar),
it won't move. Clicking the SubForm doesn't seem to help. You have to move
the scroll bars again, and sometimes (only sometimes) it then goes back to
normal, and you can move the SubForm.
I have noticed that when this occurs, other scroll related problems arise,
specifically, I have a paint routine for the Child form, that draws several
lines stored in a LineList on the Child's background :

private void Child_Paint(object sender, System.Windows.Forms.PaintEventArgs
e)
{
Graphics dc = e.Graphics;

dc.TranslateTransform(this.AutoScrollPosition.X,
this.AutoScrollPosition.Y);
Pen myPen = new Pen(Color.Black, 2);
foreach (Line drawline in LineList)
dc.DrawLine(myPen, line.From, line.To);
}

When the problem with the SubForm happens, the lines are also drawn
incorrectly - I'm not sure exactly what is wrong, it seems like the clip
rectangle is wrongly positioned, and also the AutoScrollPosition is off.
When the SubForm is working correctly, the drawing works fine.
Interestingly, the same problem arises in an SDI window, though it seems
harder to get it to happen, but it does occasionally.
For completeness sake, I should mention that I've tried adding one or more
of the following lines to Child_Click(), and a few others as well.

sub.Anchor = (System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Left);
this.Controls.Add(sub);
sub.BringToFront();

None seem to make any difference.
I am working in C#, in Visual Studio 2002, and (I think) .Net Framework 1.1.

Well, sorry it's such a long post, but I wanted to be complete and thorough,
not to mention clear. Does anyone have any ideas why this is happening, or,
more importantly, how I can avoid it or fix it?

I am still researching this, and if I find anything I will most certainly
post back. I am also going to look into managing the scrolling myself, and
would welcome any info on how to do this, since I don't yet know how.

Right, thanks for reading this epic, and thanks in advance for any help.

James CC

PS. Sometimes, when no one knows how to solve the given problem, posts go
unanswered. Could any nice person who bothers to test this at least post
back to let me know if you can reproduce the problem or not, since I have
only tested it on one computer...
Nov 17 '05 #1
2 3814
James,

This isn't really a bug, because you aren't supposed to be setting the
parent of the subform to the child in the MDI window. That new form's
parent should be set to the MDI parent (through the MdiParent property) and
then shown on it's own.

The behavior is undefined when you parent the windows like this.

Why don't you just set the MdiParent property to the MdiParent?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"James CC" <Ja*****@Nowhere.com> wrote in message
news:eM**************@TK2MSFTNGP14.phx.gbl...
[Cross posted in dotnet.framework.windowsforms and
dotnet.languages.csharp, because it could apply to either]

I have a strange bug in C# using windows forms. To make sure it's not some
bug with my code, I've gone back to a simple test app, and still see the
same behavior.

I have created a simple C# Windows MDI Application, as in MSDN, ie :

1) Create Windows Application (Form1), set IsMDIContainer to true
2) Create MainMenu component in the form, with top level '&File', submenu
'&New' and '&Close', and another top level '&Window' with MDIList set to
true.
3) Create another Form ('Child')
4) Create a Click event handler for the New menu item :
private void New_OnClick(object sender, System.EventArgs e){
Child newMDIChild = new Child();
newMDIChild.MDIParent = this;
newMDIChild.Show();
}

So far so good.

Now I want another window (Form) that appears inside the Child window when
I click it - let's call it a 'SubForm'. I had some problems with this
until I learnt that I could set SubForm.TopLevel = false, and now it's
possible. Like so :

private void Child_Click(object sender, System.EventArgs e)
{
SubForm sub;
sub = new SubForm();
sub.TopLevel = false;
sub.Parent = this;
sub.Show();
}

Obviously I want more functionality, but this makes my point. Now try
running the code. Use 'New' to create a Child window, then click inside
that window to get the sub window.

Here's the problem. If Child has AutoScroll set to true, then when you
move the SubForm so that it is partially outside the Child window (I use
the bottom right of the Child window), scroll bars appear. If you then
scroll down part way, the SubForm moves with the scrolling. But sometimes
(only sometimes) when you then try to move the SubForm (by dragging the
titlebar), it won't move. Clicking the SubForm doesn't seem to help. You
have to move the scroll bars again, and sometimes (only sometimes) it then
goes back to normal, and you can move the SubForm.
I have noticed that when this occurs, other scroll related problems arise,
specifically, I have a paint routine for the Child form, that draws
several lines stored in a LineList on the Child's background :

private void Child_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
Graphics dc = e.Graphics;

dc.TranslateTransform(this.AutoScrollPosition.X,
this.AutoScrollPosition.Y);
Pen myPen = new Pen(Color.Black, 2);
foreach (Line drawline in LineList)
dc.DrawLine(myPen, line.From, line.To);
}

When the problem with the SubForm happens, the lines are also drawn
incorrectly - I'm not sure exactly what is wrong, it seems like the clip
rectangle is wrongly positioned, and also the AutoScrollPosition is off.
When the SubForm is working correctly, the drawing works fine.
Interestingly, the same problem arises in an SDI window, though it seems
harder to get it to happen, but it does occasionally.
For completeness sake, I should mention that I've tried adding one or more
of the following lines to Child_Click(), and a few others as well.

sub.Anchor = (System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Left);
this.Controls.Add(sub);
sub.BringToFront();

None seem to make any difference.
I am working in C#, in Visual Studio 2002, and (I think) .Net Framework
1.1.

Well, sorry it's such a long post, but I wanted to be complete and
thorough, not to mention clear. Does anyone have any ideas why this is
happening, or, more importantly, how I can avoid it or fix it?

I am still researching this, and if I find anything I will most certainly
post back. I am also going to look into managing the scrolling myself, and
would welcome any info on how to do this, since I don't yet know how.

Right, thanks for reading this epic, and thanks in advance for any help.

James CC

PS. Sometimes, when no one knows how to solve the given problem, posts go
unanswered. Could any nice person who bothers to test this at least post
back to let me know if you can reproduce the problem or not, since I have
only tested it on one computer...

Nov 17 '05 #2
Dear Nicholas,

That gives me another MDI Child window, based on the SubForm instead of the
ChildForm, free to be moved to anywhere witin the MDI parent's work area.

What I want is for the SubForm to appear *WITHIN* the Child window - limited
to moving within the Child window only, scrolling with the Child Window,
etc. If you have the time, the example I gave will show you what I mean,
albeit with buggy scrolling.

For what it's worth, I did try using the Child window as an MDIParent but it
didn't work.

An example of what I'm after can be seen in Visual FoxPro (the display with
loads of sub windows linked by lines), or indeed in Visual Studio when you
are designing a form in Design mode (which shows the form, titlebar and all,
INSIDE the MDI child window that is the document, though it might be
simulated).

It should be possible; forms are basically just controls (according to the
C# documents), so it should be possible to do, similar to any other control.
In Windows, you can put windows inside other windows, and it happens often
(notably an MDI child window inside an application inside the desktop). The
only question is whether it is possible in C#, or whether I need to switch
to C++ or similar.

As to why I want to do this, I need to collect and display information
inside the Child window for parts of the project, and they need to be
movable, and resizable, and so on, and I realised that all of the
functionality (and more) that I needed was already part of a window. Writing
a collection of controls to emulate the functionality of a window seemed
more complicated than just using a window - though if I can't solve this
then I'll have no option but to do so.

I hope that clarifies...

Thanks for your taking the time though. I appreciate it.

James
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
by: Jim M | last post by:
I have had great success with using <iframe> with overflow-y set to auto. I can get a similar look with the <iframe> tag. BUT... In all cases I need to have fixed heights. Is there a way to...
1
by: Wesman | last post by:
Threads, textboxes and scrolling Thanks in advance for any information on this matter. I have run into a small richtextbox, scrolling and tread issue. Which has me totally confused. Instead of...
2
by: Fabrizio | last post by:
Hi, I'm trying to deal with ASP.NET and i would like to know if there is any control or any method that allows me, like in JAVA classes, to have, for example, scrolling news with links to...
3
by: Oddball | last post by:
Hello again, I have a problem that I can't seem to find any help for. I'm probably not typing the correct words into goo... *cough*... MSN. I have created a user control which I would like to...
3
by: venky | last post by:
I have a question. In asp.net page, how do u scroll to particular position in a page. I have a button at the end of my page, when i click the button, i do some validation and if the validation...
1
by: Oberfuhrer | last post by:
Hello all VB.net friends ! i have done most of my programming in assembly, at least so far. Recently i decided to learn a high level language for windows programming. I didnt take long to...
2
by: Eduard | last post by:
I have a ASP.Net datagrid wrap in the following div: <DIV id="divPart2" style="OVERFLOW: hidden">. Another div controls the horizontal scrolling: <DIV id="scroll1" style="OVERFLOW: scroll;...
3
by: Chamnap | last post by:
Hello everybody, I have one problem. I want to do something after the user finished scrolling. The scroll event fires whenever the user is scrolling. I don't want this actually. Does anyone has...
11
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I know I sound like a one-note Johnny on this but I'm still looking for a solution. I need to display characters coming in from a serial port or a socket. I also need to be able to type...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.