7 Replies - 29223 Views - Last Post: 16 September 2008 - 08:36 AM Rate Topic: -----

#1 Damage  Icon User is online

  • Lord of Schwing
  • member icon

Reputation: 56
  • View blog
  • Posts: 1,205
  • Joined: 05-June 08

Pass parameter when opening a form

Posted 15 September 2008 - 04:01 PM

I've got a table that stores an image path and and image ID. Each path has it's own id which links up to a bunch of other tables etc.
When the user clicks on an image it opens a new form(thanks again magicmonkey) and i want to create a dataset based upon the image that is click. I know that i could declare this

Dim pb As PictureBox = DirectCast(sender, PictureBox)



as public and do it that way, is there a more direct way of passing a paramter to a form?

Is This A Good Question/Topic? 0
  • +

Replies To: Pass parameter when opening a form

#2 jacobjordan  Icon User is offline

  • class Me : Perfection
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,499
  • Joined: 11-June 08

Re: Pass parameter when opening a form

Posted 15 September 2008 - 04:06 PM

Simple, create a New sub for the form like so
Public GlobalWhatever as SomeType

Sub New(ByVal Whatever As SomeType)
     GlobalWhatever = Whatever
End Sub


Then when you call that overload of the New sub, you can pass it whatever you want, and the value will be stored in GlobalWhatever.
Was This Post Helpful? 0
  • +
  • -

#3 Damage  Icon User is online

  • Lord of Schwing
  • member icon

Reputation: 56
  • View blog
  • Posts: 1,205
  • Joined: 05-June 08

Re: Pass parameter when opening a form

Posted 15 September 2008 - 04:18 PM

sorry i don't think i made it clear, i'm looking for a way to reference a variable declared on one form from a another form, without declaring the variable public.
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Pass parameter when opening a form

Posted 15 September 2008 - 04:38 PM

Unless you follow jacodjordan's example you cant. You cannot access a private variable outside of it's scope (which means you cant access it from another form)
Was This Post Helpful? 0
  • +
  • -

#5 jacobjordan  Icon User is offline

  • class Me : Perfection
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,499
  • Joined: 11-June 08

Re: Pass parameter when opening a form

Posted 15 September 2008 - 04:52 PM

Well, you could make it a Friend variable, then it would be visible to your assembly, but not visible to .NET applications referencing yours.
Was This Post Helpful? 0
  • +
  • -

#6 Damage  Icon User is online

  • Lord of Schwing
  • member icon

Reputation: 56
  • View blog
  • Posts: 1,205
  • Joined: 05-June 08

Re: Pass parameter when opening a form

Posted 15 September 2008 - 05:19 PM

I thought as much. Thanks for the info.
Was This Post Helpful? 0
  • +
  • -

#7 Poppa Mintin  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 72
  • Joined: 13-September 08

Re: Pass parameter when opening a form

Posted 16 September 2008 - 08:03 AM

Just a suggestion… If you only need a small number of such parameters, why not put some textboxes or labels on your form and set their visible parameter to false, then from anywhere you could read and, or, change what’s in them. You wouldn’t even have to declare them anywhere. Worth a try I’d say…

Poppa
Was This Post Helpful? 0
  • +
  • -

#16 magicmonkey  Icon User is offline

  • D.I.C Regular

Reputation: 106
  • View blog
  • Posts: 484
  • Joined: 12-September 08

Re: Pass parameter when opening a form

Posted 16 September 2008 - 08:36 AM

View PostDamage, on 15 Sep, 2008 - 04:01 PM, said:

I've got a table that stores an image path and and image ID. Each path has it's own id which links up to a bunch of other tables etc.
When the user clicks on an image it opens a new form(thanks again magicmonkey) and i want to create a dataset based upon the image that is click. I know that i could declare this

Dim pb As PictureBox = DirectCast(sender, PictureBox)



as public and do it that way, is there a more direct way of passing a paramter to a form?


Create a public property in the form set the property before you show the form.

Public Class MyPopupForm

private _MyData as Object
Public Property MyData() as Object
	Get
		Return _MyData
	End Get
	Set (value as Object)
		_MyData = value
		PopulateForm()
	End Set
End Property

Private Sub PopulateForm()
	'Place code here to populate form
End Sub

End Class



Then before you show the form...
Dim f as New MyPopupForm
f.MyData = Data
f.Show


Was This Post Helpful? 1

Page 1 of 1