473,396 Members | 1,879 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,396 software developers and data experts.

Layout-Resize-OnLoad

Hi,
This is my first experiment with C#, I'm trying to handle the resize
event. According to the documentation I should handle the Layout event
for this. My question is: how do I register this event? The following
code does not work because I never recieve the OnLoad event. What am I
doing wrong?

public class frmMain : System.Windows.Forms.Form
{
protected virtual void OnLoad(EventArgs e)
{
frmMain.ActiveForm.Layout += new
System.Windows.Forms.LayoutEventHandler(this.frmMa in_Layout);
}

private void frmMain_Layout(object sender,
System.Windows.Forms.LayoutEventArgs e)
{
splMain.Left = pgTasks.Left + pgTasks.Width;
splMain.Height = this.Height;
}
}

Another question, while I'm here, the line:

frmMain.ActiveForm.Layout += new
System.Windows.Forms.LayoutEventHandler(this.frmMa in_Layout);

does not make sense to me. I would think that the line should be:

this.ActiveForm.Layout += new
System.Windows.Forms.LayoutEventHandler(this.frmMa in_Layout);

replacing 'frmMain' with 'this' but the 'this' object reference has a
very different set of intellisense attributes, of which ActiveForm is
not one of them.

Thanks

Nov 15 '05 #1
3 3250
John wrote:
protected virtual void OnLoad(EventArgs e)
{
frmMain.ActiveForm.Layout += new
System.Windows.Forms.LayoutEventHandler(this.frmMa in_Layout);
}


Sorry for the, somewhat, quick post, replacing 'virtual' with 'override'
solves the OnLoad problem, but it still doesn't solve the original
question: How do I register the LayoutEventHandler?

Registering in the OnLoad event is incorrect because ActiveForm is null
at that point.

Thanks

Nov 15 '05 #2
I take it you are coming from VB6?

frmMain.ActiveForm is a static member, and is not what you should be doing.
Instead
this.Layout + = new
System.Windows.Forms.LayoutEventHandle(this.frmMai n_Layout);
should work.
Also, you could simply override OnLayout in your form class, just make sure
you call base.OnLayout.
"John" <john@no_spam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
John wrote:
protected virtual void OnLoad(EventArgs e)
{
frmMain.ActiveForm.Layout += new
System.Windows.Forms.LayoutEventHandler(this.frmMa in_Layout);
}


Sorry for the, somewhat, quick post, replacing 'virtual' with 'override'
solves the OnLoad problem, but it still doesn't solve the original
question: How do I register the LayoutEventHandler?

Registering in the OnLoad event is incorrect because ActiveForm is null
at that point.

Thanks

Nov 15 '05 #3
John,
Just like you can override the OnLoad method to handle the Load event, you
can override the OnLayout method to handle the Layout event. In both cases
remember to call your base.OnLoad or base.OnLayout method.

Overriding the method is more efficient than handling the event for the
current class.

http://msdn.microsoft.com/library/de...ayoutTopic.asp

Hope this helps
Jay

"John" <john@no_spam> wrote in message
news:uA**************@TK2MSFTNGP10.phx.gbl...
Hi,
This is my first experiment with C#, I'm trying to handle the resize
event. According to the documentation I should handle the Layout event
for this. My question is: how do I register this event? The following
code does not work because I never recieve the OnLoad event. What am I
doing wrong?

public class frmMain : System.Windows.Forms.Form
{
protected virtual void OnLoad(EventArgs e)
{
frmMain.ActiveForm.Layout += new
System.Windows.Forms.LayoutEventHandler(this.frmMa in_Layout);
}

private void frmMain_Layout(object sender,
System.Windows.Forms.LayoutEventArgs e)
{
splMain.Left = pgTasks.Left + pgTasks.Width;
splMain.Height = this.Height;
}
}

Another question, while I'm here, the line:

frmMain.ActiveForm.Layout += new
System.Windows.Forms.LayoutEventHandler(this.frmMa in_Layout);

does not make sense to me. I would think that the line should be:

this.ActiveForm.Layout += new
System.Windows.Forms.LayoutEventHandler(this.frmMa in_Layout);

replacing 'frmMain' with 'this' but the 'this' object reference has a
very different set of intellisense attributes, of which ActiveForm is
not one of them.

Thanks

Nov 15 '05 #4

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

Similar topics

82
by: Peter Diedrich | last post by:
The site design is pretty simple: ============================================ | Head | ============================================ | | ...
39
by: Zak McGregor | last post by:
Hi all Are there any good solutions to aligning form field names and input boxes without resorting to tables? I am struggling to do this nicely at the moment. Thanks Ciao Zak
47
by: Neal | last post by:
Patrick Griffiths weighs in on the CSS vs table layout debate in his blog entry "Tables my ass" - http://www.htmldog.com/ptg/archives/000049.php . A quite good article.
20
by: Tammy | last post by:
What would be a good alternative to using frames? I need something that will section my webpage into two halves and can change both frames on a single click. Thanks in Advance, Tammy
30
by: Diane Wilson | last post by:
I'm trying (once again) to figure out how to make a robust CSS layout style that can replace tables. I'd like to be able to do a basic two-column layout, with a one-column header, a two column...
4
by: NWx | last post by:
Hi, I develop an ASP.NET app which should be used from Internet, so I don't have control over what browsers will be used. I don't want to target every possible users, so I don't really mind is...
3
by: Samuel Shulman | last post by:
I am looking for good guidance for positioning controls on the form.document, it is absolute nightmare and I don't know where to begin Thank you, Samuel Shulman
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
5
by: Jeff User | last post by:
Hi all I am writing program/framework to server a web site dynamically based on stored web page data with C#, .net1.1 What is the preferred means of controlling page layout, frames or...
53
by: brave1979 | last post by:
Please check out my javascript library that allows you to create any layout for your web page, nested as deep as you like, adjusting to width and height of a browser window. You just describe it in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.