Main Form with Panel & Other Dialog Forms

GornHorse

Well-known member
Joined
May 27, 2003
Messages
105
Location
Australia
Hi There,

What i have is a Main Form which holds the Main Menu etc. It has 1 Panel that i wish to have the subsequent dialog forms to open up in.

Is there a way to programmatically set the Dialog forms to appear in cascade within the bounds of the Panel on my Main Form?

If this is possible, please provide a VB.NET example.

Thanks for that!


Regards,
Michelle
 
You cant put any top level controls (forms) in normal controls. But you can make it look like its here with the location property, set it to where the panel is.
 
Hi,

Thanks for the reply.

I tried doing this:

dim myFrmSearchFile_Key as new SearchFileRecord()
dim templocationx as integer
dim templocationy as integer
templocationx = me.Panel_DialogArea.Location.X
templocationy = me.Panel_DialogArea.Location.Y
myFrmSearchFile_Key.Location.X = templocationx
myFrmSearchFile_Key.Location.Y = templocationy
myFrmSearchFile_Key.Show()


But, the lines where i try to assign the integer value to the location settings for the form chucks a stink saying "Expression is a value and therefore cannot be the target of an assignment."

How can i assign these values to the location settings of the form?

Thanks,
Michelle
 
Hi,

Thanks for the code. However, it doesnt seem to be opening the form in the specified location, though.

Are there some particular settings that i need to have set on the dialog form in order for the location setting to work properly?

Thanks,
Michelle
 
Hi,

I thought Id post back an alternative solution that ive figured out.

Let me know your thoughts and improvements on this approach.

What ive done, is modified my Dialog form into a class, and I declare all my components as public, and those that handle events, such as my textboxes and buttons as WithEvents in that class.

Then, when I would want to open that dialog form, i assign the components that are declared from the class into my Panel on my main form, so that they appear nice and neat within that panel.

When something happens with that Panel, such as clicking a button, or typing the text into the textbox, the original class still picks up the event, and it can be handled there, rather than trying to add hundreds of components into the main form.

Below is a snippet of the code i used.

within the main form

Dim myFrmSearchFile_Key As New SearchFile_Key_InitializeComponents()

Sub SearchFile_Key()
Me.Panel_DialogArea.Controls.AddRange(New System.Windows.Forms.Control() {myFrmSearchFile_Key.lbFileFolderNo, myFrmSearchFile_Key.lbPartNo, myFrmSearchFile_Key.tbInputFileFolderNo, myFrmSearchFile_Key.tbInputPartNo, myFrmSearchFile_Key.BOTHERSDataGrid_Files})
End Sub


within the class
Public WithEvents lbFileFolderNo As New System.Windows.Forms.Label()
Public lbPartNo = New System.Windows.Forms.Label()
Public WithEvents tbInputFileFolderNo As New System.Windows.Forms.TextBox()
Public WithEvents tbInputPartNo as New System.Windows.Forms.TextBox()
Public BOTHERSDataGrid_Files = New System.Windows.Forms.DataGrid()

Public Sub New()
MyBase.New()
InitializeComponent()
End Sub

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

lbFileFolderNo

lbFileFolderNo.ImageAlign = System.Drawing.ContentAlignment.BottomRight
lbFileFolderNo.Location = New System.Drawing.Point(8, 24)
lbFileFolderNo.Name = "lbFileFolderNo"
lbFileFolderNo.Size = New System.Drawing.Size(80, 16)
lbFileFolderNo.TabIndex = 0
lbFileFolderNo.Text = "File Folder No:"
lbFileFolderNo.TextAlign = System.Drawing.ContentAlignment.MiddleRight

lbPartNo

lbPartNo.ImageAlign = System.Drawing.ContentAlignment.BottomRight
lbPartNo.Location = New System.Drawing.Point(24, 48)
lbPartNo.Name = "lbPartNo"
lbPartNo.Size = New System.Drawing.Size(64, 16)
lbPartNo.TabIndex = 1
lbPartNo.Text = "Part No:"
lbPartNo.TextAlign = System.Drawing.ContentAlignment.MiddleRight

tbInputFileFolderNo

tbInputFileFolderNo.Location = New System.Drawing.Point(96, 24)
tbInputFileFolderNo.Name = "tbInputFileFolderNo"
tbInputFileFolderNo.Size = New System.Drawing.Size(96, 20)
tbInputFileFolderNo.TabIndex = 2
tbInputFileFolderNo.Text = ""

tbInputPartNo

tbInputPartNo.Location = New System.Drawing.Point(96, 48)
tbInputPartNo.Name = "tbInputPartNo"
tbInputPartNo.Size = New System.Drawing.Size(96, 20)
tbInputPartNo.TabIndex = 3
tbInputPartNo.Text = ""

BOTHERSDataGrid_Files

CType(BOTHERSDataGrid_Files, System.ComponentModel.ISupportInitialize).BeginInit()
BOTHERSDataGrid_Files.AlternatingBackColor = System.Drawing.Color.Cornsilk
BOTHERSDataGrid_Files.BackgroundColor = System.Drawing.Color.Azure
BOTHERSDataGrid_Files.CaptionBackColor = System.Drawing.Color.RoyalBlue
BOTHERSDataGrid_Files.CaptionForeColor = System.Drawing.Color.White
BOTHERSDataGrid_Files.CaptionText = "Files List ..."
BOTHERSDataGrid_Files.DataMember = ""
BOTHERSDataGrid_Files.HeaderForeColor = System.Drawing.SystemColors.ControlText
BOTHERSDataGrid_Files.Location = New System.Drawing.Point(8, 80)
BOTHERSDataGrid_Files.Name = "BOTHERSDataGrid_Files"
BOTHERSDataGrid_Files.Size = New System.Drawing.Size(312, 184)
BOTHERSDataGrid_Files.TabIndex = 4
End Sub


NB, even though the textbox appears to be a part of the main form, this class still picks up this
event when the text is changed in it!
Private Sub tbInputFileFolderNo_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbInputFileFolderNo.TextChanged
aliasBothersConnect.BOTHERS_Connect()
BOTHERS_DataDisplay_Files()
aliasBothersConnect.BOTHERS_Close()
BOTHERSDataGrid_Files.ReadOnly = True
End Sub




Let me know what you think??
 
Back
Top