473,748 Members | 5,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Scrolling bug in MDI client windows

[Cross posted in dotnet.framewor k.windowsforms and dotnet.language s.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(obj ect sender, System.EventArg s e){
Child newMDIChild = new Child();
newMDIChild.MDI Parent = this;
newMDIChild.Sho w();
}

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.TopLeve l = false, and now it's possible.
Like so :

private void Child_Click(obj ect sender, System.EventArg s 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(obj ect sender, System.Windows. Forms.PaintEven tArgs
e)
{
Graphics dc = e.Graphics;

dc.TranslateTra nsform(this.Aut oScrollPosition .X,
this.AutoScroll Position.Y);
Pen myPen = new Pen(Color.Black , 2);
foreach (Line drawline in LineList)
dc.DrawLine(myP en, 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 AutoScrollPosit ion 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.AnchorSt yles.Top |
System.Windows. Forms.AnchorSty les.Left);
this.Controls.A dd(sub);
sub.BringToFron t();

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 3831
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.co m

"James CC" <Ja*****@Nowher e.com> wrote in message
news:eM******** ******@TK2MSFTN GP14.phx.gbl...
[Cross posted in dotnet.framewor k.windowsforms and
dotnet.language s.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(obj ect sender, System.EventArg s e){
Child newMDIChild = new Child();
newMDIChild.MDI Parent = this;
newMDIChild.Sho w();
}

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.TopLeve l = false, and now it's
possible. Like so :

private void Child_Click(obj ect sender, System.EventArg s 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(obj ect sender,
System.Windows. Forms.PaintEven tArgs e)
{
Graphics dc = e.Graphics;

dc.TranslateTra nsform(this.Aut oScrollPosition .X,
this.AutoScroll Position.Y);
Pen myPen = new Pen(Color.Black , 2);
foreach (Line drawline in LineList)
dc.DrawLine(myP en, 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 AutoScrollPosit ion 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.AnchorSt yles.Top |
System.Windows. Forms.AnchorSty les.Left);
this.Controls.A dd(sub);
sub.BringToFron t();

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
919
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 put either tag inside an HTML <TD> and have the same kind of scrolling effect. This would allow me to fill the screen and have the size of the scrolling box change on resize. Thanks in advance.
1
3610
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 trying to explain it I wrote some small C# code to demonstrate the fact that in the threaded version the textbox simple doesn't scroll like it should… please look to the startButton_Click method for the distinction between the two programs..
2
1527
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 different web pages. Is it possible? Thanks, Fabrizio
3
5233
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 use as items in a list. The list would display as many of these controls as I wish to add, scrolling as it needs to. I KNOW this functionality exists already in every list you care to mention but I don't know how to go about making a list...
3
7423
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 fails, i want to scroll to particular postition in the page. Instead the page stays in the same place where the button is. any idea or inputs on scrolling?
1
2356
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 realize that VB.net would be my perfect friend. I have already rewritten most of my assembly controls in VB, but i am not satiesfied with the scrolling performance, though. In assembler, where you can write directly to the video memory, this
2
4229
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; WIDTH: 800px; LINE-HEIGHT: 0px; HEIGHT: 17px" onscroll="javascript: document.getElementById('divPart2').scrollLeft = this.scrollLeft;"> scrolls the datagrid horizontally. When the horizontal scroll box is dragged or any of the scrollbar arrows is
3
11754
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 any idea or trick of how to achieve this? Appreciate your ideas..... Thanks Chamnap
11
7654
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 characters into the display myself - but that's not the main issue at this time. I've tried a scrolling multiline text box but once the original viewable area fills up and it starts scrolling the flashing of the entire area drives me nuts. The...
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9249
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8244
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.