473,803 Members | 3,534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically-created menus and mdi children

I posted a similar message earlier but we've geared away from the
original topic somewhat so I thought I'd post again in hopes of getting
input from others.

I am creating a MenuStrip dynamically. For each ToolStripMenuIt em, I'm
adding an event handler so that the same routine gets called regardless
of which menu item was clicked. All of this works great - my menu is
being loaded properly and my routine gets called properly.

Within the Tag property of each ToolStripMenuIt em I store the name of a
form that I want opened as an mdi child of my main form. I couldn't
get this to work properly, so for testing purposes I've reduced my
problem to the following scenario (which really has nothing to do with
the Tag property or the fact that my form names are stored in
variables):

Behind my main form I created the following routine:

Private Sub LoadForm()
Dim frm As New frmTest
With frm
.MdiParent = Me
.Left = 0
.Top = 0
.Show()
End With
End Sub

I also added a button to my form and in the click event of the button,
I call the above routine.

In my routine that gets called when a menu item is clicked, I call the
same LoadForm routine.

If I click my button, frmTest loads as an mdi child as it should.
If I click a menu item, my form does not get loaded (and yes, I've
confirmed that the routine is getting called).
Incidentally, if I comment out the line that says '.MdiParent = Me', my
form will open as a normal Windows form. However, as soon as I
uncomment out that line, my form will not load.

I'm puzzled as to why such a simple thing would work when I click a
button but not when I click a menu item.

As an aside, I tried loading a menu with static menu items (instead of
loading it dynamically), and everything worked fine - my mdi child form
loaded properly.

Any help would be greatly appreciated.

Thanks,

Steve

Apr 15 '06
12 3179
Good. I am looking forward to knowing...

(PS: a recommendation: when you create the new app do enforce strict ON)

Apr 15 '06 #11
Okay, I created the new app and it worked. I then figured out what the
differences were and figured out what caused it to not work in my
original app, although I'm still not really sure why.

In my first app, my main form is not the first form that opens. I open
a Login form first and authenticate the user. If the user enters a
valid username/password, I open the Main Form and close the Login form.
In my project properties under the 'Application' tab I had changed my
Startup Form to be my Login form and in the 'Shutdown mode' option I
changed the default (When startup form closes) to 'When last form
closes'.

That seems to be what caused the problem because I am able to duplicate
the problem in my second application.

My second application loads my main form first, and duing the load of
that form I open the Login form with ShowDialog. If the user
authenticates properly I pass back to the Main Form a result of
DialogResult.Ye s - otherwise I pass back DialogBox.No. If the user
does not authenticate properly (after 3 tries) I just close the main
form and I'm done. Otherwise my main form continues to load and I load
my main menu. This works fine.

If you've got any idea as to why my first way doesn't load the mdi
children properly, I'd be curious to know. I suspect my second
approach is actually the better approach anyway, so I'm going to stick
with it.

Thanks a lot for the help.

By the way, I noticed that if I open my mdi child it gets places at
Left=0, Top=0 as I specified in my code. However, if I then close my
child form and re-open it, it seems to be positioned lower and to the
right, as if the first form were still opened and the two forms were
being cascaded. My guess is that this is something fairly easy to fix
and I haven't actually looked around for an answer yet, but I thought
I'd ask in the hopes that you know offhand.

Thanks again,

Steve

Apr 15 '06 #12
glad to hear that :)

-tommaso

Private Sub LoadForm()
Dim frm As New frmParticipantS earch
With frm
.MdiParent = Me
.StartPosition = FormStartPositi on.Manual '<--
.Location = New Point(0, 0)
'.Left = 0
'.Top = 0
.Show()
End With
End Sub

Apr 15 '06 #13

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

Similar topics

4
2271
by: RobG | last post by:
I have a function whose parameter is a reference the element that called it: function someFunction(el) { ... } The function is assigned to the onclick event of some elements in the HTML source:
7
3263
by: Tim T | last post by:
Hi, I have the need to use dynamically loaded user controls in a webform page. I have the controls loading dynamically, and that part works fine. this is the code used in a webform to dynamically load one of several controls: private void btnCategory_Click(object sender, System.EventArgs e) { Control myControl = LoadControl(DropDownList1.SelectedItem.Text + ".ascx"); PlaceHolder1.Controls.Add(myControl);
1
1022
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a variable (targetId) in to the usercontrol (IntergySite.aspx) by calling its setter method. Currently, I am using if-then-else and hardcoded the User Control Object to do casting and call the setter method. Question: Is there any way I could load,...
5
9774
by: Angel | last post by:
Is there a way to create an IFRAME dynamically via VB.NET. In other words creating the HTML element in the server side code? thanks in advance....
7
6788
by: pmclinn | last post by:
I was wondering if it is possible to dynamically create a structure. Something like this: public sub main sql = "Select Col1, Col2 from Table a" dim al as new arraylist al = LoadOracleData(sql) '____Do amazing things
9
7043
by: netasp | last post by:
hi all, how can I populate one aspx form when page is loading based on page ID? for example: loading page A (to search for VB code) would display labels and texboxes, dropdown lists all related to VB, plus the address bar would show something like this: www.somethinghere?id=3 and if you change number 3 from the address bar to (for example) 34 or 71 you would get different page with the same formatting like I.e: www.somethinghere?id=34...
6
11083
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to how those properties are set. I want to be able to do two other things: a) add User control instances to my page, filling in the place of placeholder controls, and b) programmatically setting custom properties on those dynamically spawned...
7
2153
by: Nathan Sokalski | last post by:
I have a page which I dynamically add several usercontrols (*.ascx files) to using the following code: Public Sub Refresh() For Each section As DataRow In Me.GetSections().Rows CType(Me.FindControl("admin" & CStr(section("buttontext")).Replace(" ", "")), adminsection2).RefreshSection() Next End Sub
5
4455
by: Nathan Sokalski | last post by:
I have a custom control that I wrote (I inherit from System.Web.UI.WebControls.CompositeControl). I dynamically add this control to my Page, but I was told that dynamically added controls do not survive postback. This seems to be true. However, this seems to make dynamically adding controls rather pointless to me, since if you cannot retrieve the values of the controls when you perform a postback, why add the controls in the firstplace?...
7
6676
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a tabcontainer which has 1 panel already, however I want to try create the TabPanels dynamically. I followed the advice here: http://www.asp.net/learn/ajax-videos/video-156.aspx (3rd comment - Joe Stagner)
0
9703
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
10550
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10295
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
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
9125
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...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
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

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.