Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generic programming for creating a form that can be embedded on other modal forms to upload images. 4

Status
Not open for further replies.

A Beginner

Programmer
Apr 15, 2017
81
IN
I Want to Create a form programmatically(a generic program) that could be embedded on any other modal form having grid for uploading images.
How to deploy the idea in a very simplistic way?
The visual portion being Cool and light layout.

Thank you
 
Once I am done with this static way of making form I will definitely do the same with dynamic form.

 
Ok, Now when I am done with bringing the clicked image on to the canvas the problem I am facing is that the dimension of image is independent of the canvas boundary.
In what way can I confine the image within the boundary of canvas?
 
What I have done till now can be jotted down as follows:
1. Created the project with name AddImage.pjx,
2. Defined NewClass based on BaseClasses.
3. Created a new class AddImage.vcx as NewContainer.
4. Added 'Img1' with an image (to mimic to Canvas) into the Picture property of Img1.
5. Added 'Img2' with no image in it's picture property.
6. In the init of 'Img2' typed code-
Code:
IF EMPTY(This.Picture)
   This.Visible = .F.
ENDIF
7. Added a label 'lblPath' with autosize .T., to the container.
8. Added a textbox 'txtPath'
9. Added a command button 'cmdBw' with caption '...'
10. Added 'adddialog' AS _comdlg
11. In the click event of 'cmdBw. created cursor to store the path of image selected.
12. In the click event of 'cmdBw' copied the code mentioned on with some modification as under
Code:
  Procedure cmdbw.Click
  Crea Curs FILENAMES (filename C(254))
  With This.Parent.adddialog
    .ClearFilters() && Clear filters in case in loop
    .lAllowMultiSelect = .T. && Enable multiple file selection
    .cFileName = [] && Do not set an initial file name
    *.cInitialDirectory = [[C:\My Documents]
    .cInitialDirectory = [C:\Users\Aspire\Desktop\Don't Delete] && Start folder
    .cTitlebarText = [Select multiple files] && Dialog titlebar text
    *.aFilterList[1,1] = [Image Files (bmp,gif,jpg)] && First half of filter list
    *.aFilterList[1,2] = [*.bmp;*.gif;*.jpg;*.jpeg] && Second half of filter list
    .AddFilter([Image Files (bmp,gif,jpg)],[*.bmp;*.gif;*.jpg;*.jpeg])
    * Should you want additional filters you can add them with :-
    *.AddFilter([MS Office (doc,ppt,rtf,txt,wri,xls)],[*.doc;*.ppt;*.rtf;*.txt;*.wri;*.xls])
    .nFileCount = 0 && Reset file count value in case dialog in DO WHILE... loop
    .ShowDialog() && Show dialog

    If .nFileCount > 0 && File(s) selected
      For i = 1 To Alen(.aFileNames,1) && Loop through array created
        Insert Into FILENAMES (filename) Values (Addbs(.cFilepath);
          +Lower(.aFileNames[1,i])) && Insert path\filename.ext in cursor
      Endfor
    *Browse Last
    Else
      Messagebox([You have not made a selection],16,[No files],2000)
    Endif
    This.Parent.txtpath.Value = FILENAMES.filename
    This.Parent.img2.Picture = FILENAMES.filename
    This.Parent.img2.Visible = .T.
  Endwith
13. To show the path of the image in 'txtPath' and to open the picture as 'Img2' typed following code-
Code:
 This.Parent.txtPath.Value = FILENAMES.filename
  This.Parent.img2.Picture = FILENAMES.filename
  This.Parent.img2.Visible = .T.
14. Created a new form AddImage.Scx in the project itself and added the Addimage.vcx on it.
AddImage_pd9hr6.png

15. When run the form and select any image, it opens it but of the image's original dimension(large or small)
AddImage_4_miadq6.png

Please guide me on how to adjust the image's dimension dynamically?
 
Ok That too happened by setting the stretch property of Img2 to 2
 
When you set img2.Picture the img2 width and height get set to the picture dimensions, right. Setting stretch does not put the img2 dimensions back to how they were.
You have to set stretch before setting the picture, then the image control knows it should not resize itself to picture dimensions but should stretch the picture to fit.

Notice: Stretched pictures will look blurred, especially when they are graphical. What you show there would perhaps also look nice stretched. Ideally, you have pictures which are larger than the inner canvas, because downsizing a picture rather sharpens it.

Bye, Olaf.



 

Olaf said:
You have to set stretch before setting the picture, then the image control knows it should not resize itself to picture dimensions but should stretch the picture to fit.
Ok, Then I modified the code in the click event of 'cmdBw' as
Code:
This.Parent.Img2.Stretch = 2
and also after endwith typed
Code:
IF !Empty(This.Parent.txtPath.Value)
     This.Parent.img2.Visible = .T.
  ELSE  
     This.Parent.img2.Visible = .F.
     This.Parent.img2.Stretch = 0
  ENDIF

Running ok.

Olaf said:
Ideally, you have pictures which are larger than the inner canvas, because downsizing a picture rather sharpens it.
Thank you farsightedness. In what way should I recover it?
Should I not accept larger images or should I give cropping opetion? or what else?
 
I understood the opposite of what I said. Larger images are fine, they will look fine downsized. Notice stretch includes shrinking, if the image is larger.

Bye, Olaf.
 
As you want all pictures to stretch, you could set stretch to 2 in the property window and keep it that, no need to switch this setting just because there is no picture set.

Bye, Olaf.
 
Yes I had tested it was working fine but for the good practice I had modified the code.
 
What good practice says you set something, when no change is needed? Setting Stretch=2 once makes all pictures you set to the control.Picture stretch (or shrink), you define the automatic behavior of the image control, there is no need to do this repeatedly, as you always want to do the same.

Bye, Olaf.
 
Well, to grasp the concept of Class and other important concepts more deeply I am going through Advanced Object Oriented Programming with Visual FoxPro 6.0. Please give notions- Is it good to go with concepts dealt with version 6 when I am programming with version 9.0? Should I continue reading or any other easy to understand book?
The link is as follows.
 
That book should be fine. There are newer features, but the basics remain unchanged.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top