How to change the picture on a button programmatically?

Discussions regarding 1C:Enterprise for mobile devices with Android, iOS, or Windows Phone.

#1
People who like this:0Yes/0No
Active user
Rating: 3
Joined: Feb 28, 2012
Company:

I am trying to change the picture on a button programmatically on managed mode for a mobile platform application.
I am using this code that should work on ordinary module:

Code
Items.Command1.Picture = new Picture("C:\index.jpg");

i tried the code AtClient  and AtServer and i get an Invalid value error.

What is the correct way to do this on managed mode?

 
#2
People who like this:1Yes/0No
Active user
Rating: 4
Joined: Nov 19, 2012
Company:

Constantinos Anastasiou,
Picture should be placed inside configuration as metadata object.
And you can access it through PictureLib collection.

 
#3
People who like this:0Yes/0No
Timofey Bugaevsky
Guest

Joined:
Company:

Hello, Constantinos Anastasiou!

Depending on your task it might be better to change visibility of two commands, one of them will perform one action and hide itself then show another, which will perform another action.

The other way is to change the picture index, having a picture library with several states of your button attached as a picture.

If you want to display a picture on a form, for example if you edit a picture or perform some actions on it, you need to put it to the temp storage, get its address and attach as a picture after that to the string attribute, displayed as a picture.

For form buttons the Picture value can be either Empty or from the picture library of your application.

Here is a code sample for you, the configuration dump is attached to this message as well.

Code
&AtClient
Procedure ShowPicture(Command)
   
   FileDialog = New FileDialog(FileDialogMode.Open);
   FileDialog.Filter = NStr("en = 'All pictures (*.bmp;*.dib;*.rle;*.jpg;*.jpeg;*.tif;*.gif;*.png;*.ico;*.wmf;*.emf)|*.bmp;*.dib;*.rle;*.jpg;*.jpeg;*.tif;*.gif;*.png;*.ico;*.wmf;*.emf|'");
   FileDialog.Show(New NotifyDescription("AfterChooseFile", ThisForm));
   
EndProcedure

&AtClient
Procedure AfterChooseFile(SelectedFiles, AdditionalParameters) Export
   
   If ValueIsFilled(SelectedFiles) And SelectedFiles.Count() > 0 Then
      PictureBinaryData = New BinaryData(SelectedFiles[0]);
      PictureAddress = PutToTempStorage(PictureBinaryData);
      Items.FormShowPicture.Picture = PictureLib.Back;
   EndIf;
   
EndProcedure

Download 1Cv8.cf (8.15 KB)
 
#4
People who like this:0Yes/0No
Active user
Rating: 3
Joined: Feb 28, 2012
Company:

Hello and thanks for the reply.

The show method was not working so i modified it a bit and it did the job:

Code
&AtClient
Procedure ShowPicture(Command)
   
   FileDialog = New FileDialog(FileDialogMode.Open);
   FileDialog.Filter = NStr("en = 'All pictures (*.bmp;*.dib;*.rle;*.jpg;*.jpeg;*.tif;*.gif;*.png;*.ico;*.wmf;*.emf)|*.bmp;*.dib;*.rle;*.jpg;*.jpeg;*.tif;*.gif;*.png;*.ico;*.wmf;*.emf|'");
   
   if FileDialog.Choose() then
      
      PictureBinaryData = New BinaryData(FileDialog.FullFileName);
      PictureAddress = PutToTempStorage(PictureBinaryData);
      
   endif
   
EndProcedure



What i was missing was the PictureAddress and TempStorage way of loading a picture.

Thanks again

 
#5
People who like this:0Yes/0No
Timofey Bugaevsky
Guest

Joined:
Company:

Constantinos Anastasiou, think, you are using older version of 1C:Enterprise platform. Choose() method produces a modal window and this will be a problem if you are using Chrome browser, as they prohibited use of modal windows.

 
#6
People who like this:0Yes/0No
Active user
Rating: 3
Joined: Feb 28, 2012
Company:

Yes i was testing in 8.3.4

Anyway i need this for a mobile application so i will not be using a dialog at all.

 
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)
Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.