Desktop version

Main > Forum > 1C:Enterprise Platform > 1C:Enterprise. Mobile platform > How to change the picture on a button programmatically?

Forum

Search UsersRules
How to change the picture on a button programmatically?
#1
Active user
Points:: 0
Joined:: Feb 28, 2012

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?

Profile
#2
Active user
Points:: 0
Joined:: Nov 19, 2012

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

Profile
#3
Guest
Points::
Joined::

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

Profile
#4
Active user
Points:: 0
Joined:: Feb 28, 2012

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

Profile
#5
Guest
Points::
Joined::

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.

Profile
#6
Active user
Points:: 0
Joined:: Feb 28, 2012

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.

Profile
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)



© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.