openfiledialog on a form

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
dcdelgado
Posts: 40
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Tue Mar 24, 2009 8:53 pm

openfiledialog on a form

Post by dcdelgado »

HA,

I have just purchased PrimalForms 2009, and i trying to get the openfiledialog control on the form so i can use to browse the network for files/folder, when i attempt to add the control to the form the only code that generated is the below,

$handler_openfiledialog1_FileOk=[System.ComponentModel.CancelEventHandler]{
#Event Argument: $_ = [System.ComponentModel.CancelEventArgs]
#TODO: Place custom script here

When i run the form no browse dialog is displayed, can anyone give me some example code that can be used in the above context, thanks.


jvierra
Posts: 14448
Joined: Tue May 22, 2007 9:57 am
Contact:

openfiledialog on a form

Post by jvierra »

Add a command button.
Double click on button.
Add code to script.

$openfiledialog1.ShowDialog()


The code you have aleady is inserted when you double click on the control in the designer. This is normal behavior in any tool that we use to build Windows Forms. Each control has a default event that gets implemeted as a result of the designer clicks. In th ecase of most dialogs it is teh 'Cancel" event. This code can be deleted as it will never be called.

When you run the form and click the button the file dialog will launch.

Dialogs need to be launched as they are not embedded objects like text boxes and command buttons. Dialogs are launched using the ShowDialog method. Properties and values can be set in the designer or in the launch code before calling ShowDialog.



jvierra2009-10-02 10:40:41

jvierra
Posts: 14448
Joined: Tue May 22, 2007 9:57 am
Contact:

openfiledialog on a form

Post by jvierra »

Yes - just display is where ever it is needed.

Here is one way using your default event handler and assuming the existence of a textbox control called textbox1.

Code: Select all

	

	$handler_openfiledialog1_FileOk=[System.ComponentModel.CancelEventHandler]{
	#Event Argument: $_ = [System.ComponentModel.CancelEventArgs]
	#TODO: Place custom script here
	$textbox1.Text = $openfiledialog1.FileName
	
}
	

User avatar
dcdelgado
Posts: 40
Joined: Tue Mar 24, 2009 8:53 pm

openfiledialog on a form

Post by dcdelgado »

Thanks i'll give that a try.

User avatar
dcdelgado
Posts: 40
Joined: Tue Mar 24, 2009 8:53 pm

openfiledialog on a form

Post by dcdelgado »

Thanks for the info.

Locked