Click here to Skip to main content
15,914,444 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Generalgetting the correct location Pin
raulavi18-Jan-05 6:40
raulavi18-Jan-05 6:40 
GeneralRe: getting the correct location Pin
Amaterasuv18-Jan-05 7:17
Amaterasuv18-Jan-05 7:17 
GeneralRe: getting the correct location Pin
raulavi18-Jan-05 7:26
raulavi18-Jan-05 7:26 
GeneralRe: getting the correct location Pin
raulavi18-Jan-05 7:41
raulavi18-Jan-05 7:41 
GeneralRe: getting the correct location Pin
Jim Matthews18-Jan-05 7:49
Jim Matthews18-Jan-05 7:49 
GeneralRe: getting the correct location Pin
raulavi18-Jan-05 8:28
raulavi18-Jan-05 8:28 
GeneralRe: getting the correct location Pin
Amaterasuv18-Jan-05 8:48
Amaterasuv18-Jan-05 8:48 
GeneralRe: getting the correct location Pin
Jim Matthews18-Jan-05 9:58
Jim Matthews18-Jan-05 9:58 
well, the best way to do it depends on exactly what the relationship between these two forms is.

if form1 is the mdi parent of form2...

'in formTwo...
dim formOne as form1 = me.MdiParent

if form1 is set as the parent control of form2 through the .Show() procedure...

'in formTwo...
dim formOne as form1 = me.Parent


the above code will give you an instance of form1, which you'll then need to utilize to add your control.

my recommendation for doing this would be having a friend Sub to grant access for you to the controls property of the panel.

public class form1
inherits system.windows.forms.form

'--- windows generated code ---'

Friend Sub AddPanelControl(byval controlToAdd as Control, byval location as System.Drawing.Point)

   me.panel1.controls.add(controlToAdd)
   controlToAdd.Location = location

End Sub

End Class

public class form2
inherits System.Windows.Forms.Form

Private Sub button1_click(byval sender as object, byval e as buttonclickeventargs) handles button1.click

   dim formOne as form1 = me.mdiparent 'you may need to cast this return value using    ctype depending on whether or not you're using option strict on...

   dim newControl as New TextBox

   With newControl
      .Name = "myTextBox"
      .Text = ""
      'etc.
   End With

   formOne.AddPanelControl(newControl, new System.Drawing.Point(10, 10))

End Sub

End Class

This should work out for you. I haven't tested it out or anything, but let me know if there are problems.

I would still recommend setting your controls at design time and just worrying about managing their visibility, but if you can't then this would be another way...



-jim
GeneralRe: getting the correct location Pin
raulavi18-Jan-05 10:18
raulavi18-Jan-05 10:18 
GeneralRe: getting the correct location Pin
raulavi18-Jan-05 10:30
raulavi18-Jan-05 10:30 
GeneralRe: getting the correct location Pin
Jim Matthews18-Jan-05 10:46
Jim Matthews18-Jan-05 10:46 
GeneralRe: getting the correct location Pin
raulavi18-Jan-05 13:01
raulavi18-Jan-05 13:01 
GeneralAuthorization and profile application block Pin
tigertwareg18-Jan-05 6:33
tigertwareg18-Jan-05 6:33 
GeneralRe: Authorization and profile application block Pin
J4amieC19-Jan-05 5:44
J4amieC19-Jan-05 5:44 
GeneralRe: Authorization and profile application block Pin
Anonymous24-Jan-05 3:51
Anonymous24-Jan-05 3:51 
GeneralAccessing a Form from another Pin
raulavi18-Jan-05 5:58
raulavi18-Jan-05 5:58 
GeneralRe: Accessing a Form from another Pin
Amaterasuv18-Jan-05 7:23
Amaterasuv18-Jan-05 7:23 
GeneralRe: Accessing a Form from another Pin
raulavi18-Jan-05 7:32
raulavi18-Jan-05 7:32 
GeneralRe: Accessing a Form from another Pin
raulavi18-Jan-05 7:47
raulavi18-Jan-05 7:47 
GeneralModifying and adding controls to parentform Pin
Amaterasuv18-Jan-05 8:14
Amaterasuv18-Jan-05 8:14 
GeneralRe: Accessing a Form from another Pin
Dave Kreskowiak18-Jan-05 8:19
mveDave Kreskowiak18-Jan-05 8:19 
GeneralRe: Accessing a Form from another Pin
Rizwan Bashir19-Jan-05 0:37
Rizwan Bashir19-Jan-05 0:37 
GeneralLocalizing Crystal Reports Pin
Amaterasuv18-Jan-05 1:01
Amaterasuv18-Jan-05 1:01 
GeneralEditing MIDI File Pin
girijaa18-Jan-05 0:37
professionalgirijaa18-Jan-05 0:37 
Generalvb.net Pin
Anonymous17-Jan-05 23:51
Anonymous17-Jan-05 23:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.