Convert VB Code into COBOL Code

[Migrated content. Thread originally posted on 08 March 2011]

Hi All,

Im trying to add an image to a tooltip and have found the following VB code and was just wondering if any one knows have to convert to Visual Cobol Code?

Code :-

ToolTip1.SetToolTip(dgv, " ")

1. Private Sub ToolTip1_Draw(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawToolTipEventArgs) Handles ToolTip1.Draw
2. e.DrawBackground()
3. e.DrawBorder()
4. e.DrawText()
5. e.Graphics.DrawImage(img, 0, 0)
6. End Sub
7.
8. Private Sub ToolTip1_Popup(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PopupEventArgs) Handles ToolTip1.Popup
9. e.ToolTipSize = New Size(img.Width, img.Height)
10. End Sub

Link to site:-

www.vbforums.com/showthread.php

Any help would be gratefully received.

Many thanks

neil.
  • I have got the following code (dont know if its right!) but cant seem to get the second bit to work, or indeed how to load an image on the fly.

    class-id. Form1 as "ToolTip.Form1" is partial
    inherits type "System.Windows.Forms.Form".

    environment division.
    configuration section.
    repository.
    class cImage as "System.Drawing.Image"
    .
    object.
    working-storage section.
    01 ws-cImage cImage.
    method-id. NEW.
    procedure division.
    invoke self::"InitializeComponent"
    goback.
    end method NEW.

    method-id. "Form1_Load" final private.
    procedure division using by value sender as object e as type "System.EventArgs".
    end method "Form1_Load".

    method-id. "toolTip1_Draw" final private.
    procedure division using by value sender as object e as type "System.Windows.Forms.DrawToolTipEventArgs".
    * e.DrawBackground()
    * e.DrawBorder()
    * e.DrawText()
    * e.Graphics.DrawImage(img, 0, 0)
    invoke e::"DrawBackground"()
    invoke e::"DrawBorder"()
    invoke e::"DrawText"()
    invoke e::"Graphics"::"DrawImage"(ws-cImage, 0, 0)
    end method "toolTip1_Draw".

    method-id. "toolTip1_Popup" final private.
    procedure division using by value sender as object e as type "System.Windows.Forms.PopupEventArgs".
    * e.ToolTipSize = New Size(img.Width, img.Height)
    end method "toolTip1_Popup".

    end object.
    end class Form1.




  • Hi!

    I have not really done any winform stuff for the last couple of years (I lead the language evolution team working on JVM COBOL). However, under Visual COBOL R3 (the current GA product) this all compiles:

           class-id WindowsFormsApplication2.Form1 is partial
                     inherits type System.Windows.Forms.Form.

           working-storage section.
              01 img type System.Drawing.Image value new System.Drawing.Bitmap(50 50).

           method-id. new.
            procedure division.
               invoke self::InitializeComponent
               goback.
            end method.

           method-id. Form1_Load final private.
               procedure division using by value sender as object e as type System.EventArgs.
           end method.

           method-id. "toolTip1_Draw" final private.
               01 img type System.Drawing.Image.
           procedure division using by value sender as object e as type System.Windows.Forms.DrawToolTipEventArgs.
               invoke e::DrawBackground()
               invoke e::DrawBorder()
               invoke e::DrawText()
               invoke e::Graphics::DrawImage(img 0 0)
           end method.

           method-id. toolTip1_Popup final private.
              procedure division using by value sender as object e as type "System.Windows.Forms.PopupEventArgs".
                set e::ToolTipSize to New Size(img::Width img::Height)
           end method.

           end class.


    I have reformatted the code to me more inline with current MF recommended format.

    Hope that helps :)

    Best wishes - AJ

    Dr Alexander J Turner

  • Hi!

    I have not really done any winform stuff for the last couple of years (I lead the language evolution team working on JVM COBOL). However, under Visual COBOL R3 (the current GA product) this all compiles:

           class-id WindowsFormsApplication2.Form1 is partial
                     inherits type System.Windows.Forms.Form.

           working-storage section.
              01 img type System.Drawing.Image value new System.Drawing.Bitmap(50 50).

           method-id. new.
            procedure division.
               invoke self::InitializeComponent
               goback.
            end method.

           method-id. Form1_Load final private.
               procedure division using by value sender as object e as type System.EventArgs.
           end method.

           method-id. "toolTip1_Draw" final private.
               01 img type System.Drawing.Image.
           procedure division using by value sender as object e as type System.Windows.Forms.DrawToolTipEventArgs.
               invoke e::DrawBackground()
               invoke e::DrawBorder()
               invoke e::DrawText()
               invoke e::Graphics::DrawImage(img 0 0)
           end method.

           method-id. toolTip1_Popup final private.
              procedure division using by value sender as object e as type "System.Windows.Forms.PopupEventArgs".
                set e::ToolTipSize to New Size(img::Width img::Height)
           end method.

           end class.


    I have reformatted the code to me more inline with current MF recommended format.

    Hope that helps :)

    Best wishes - AJ

    Dr Alexander J Turner

  • Many thanks for that but I dont see how I can "load" an image "on the fly" into the tooltip so when it hovers over a feature an image appears instead of some text.

    Could you pls advise.

    Many thanks for your help

    Kind regards

    Neil.
  • I have created a working sample of OwnerDrawn Tooltips which will show various methods of creating tooltips including loading an image.

    If you give me your e-mail address then I will send you the demo...
  • Hi Chris,

    Many thanks for info my email address is

    neil@eurorealm.co.uk

    Kind regards

    Neil.
  • Here you go Neil.

    Example sent by e-mail.

    The attachment is actually a zip file but my Outlook won’t let me send a zip file.
    Please rename it to .zip after downloading it.

    I think that this is self-explanatory but if you do have questions please let me know.

    Thanks.
  • Hi Chris,

    Many thanks for that, it works great and I have changed it so I can change the image on the fly for different buttons.

    One more thing, say I have 5 items in the data grid and I wanted to display a different image for each line as I hovered over it, is that possible?

    Kind regards

    Neil.

  • Hi Chris,

    I have also noticed that the images sizes on the screen are some times very large and vary quite a lot in pixel size and hide some controls required not to be hidden.

    My images vary in sizes from say 200x200 to 1024x768.

    So is it possible to some how create the "image" as a thumbnail of the original image or set the tooltip image size to say 400 x 400 and then make the image autofit?

    I know you can autofit when using the pictureBox control so just need to do the same sort of thing with the tooltip images.


    Many thanks

    Neil.
  • For the image sizing, this can be done using the Graphics.Drawing class and adding the size parameters of height and width in pixels after the location parameters.

    In the following it will resize the image to 50 x 50 pixels:


       if e::AssociatedControl = button3
          invoke e::DrawBackground
          invoke e::DrawBorder
          invoke e::DrawText
          invoke e::Graphics::DrawImage(wsImage, 0, 0, 50, 50)


    In the code for the PopupEventHandler you would also have to change the size of the tooltip itself.
    In the example I sent I was setting it to the size of the image.
    Change this as follows:


       if e::AssociatedControl = button3
       *>  set e::ToolTipSize to New Size(wsImage::Width, wsImage::Height)
           set e::ToolTipSize to New Size(50, 50)
       end-if


    For the dataGridView control you can easily set the ToolTip by row by handling the event DataGridViewCellToolTipTextNeeded as follows and setting the property VirtualMode to True:


       method-id CellToolTipNeeded final private.
       procedure division using by value sender as object e as type  System.Windows.Forms.DataGridViewCellToolTipTextNeededEventArgs.
           
          if e::RowIndex = 0
             set e::ToolTipText to "Grid Row 1"
          else
             if e::RowIndex = 1
                set e::ToolTipText to "Grid Row 2"
             else
                if e::RowIndex = 2
                   set e::ToolTipText to "Grid Row 3"
                end-if
             end-if
          end-if
             
       end method.



    This will allow you to change Tooltip text only.
    I could not find a method of displaying an image for a dataGridView Tooltip as it does not appear that owner drawn Tooltips are supported directly for this control.

    Perhaps someone else has a suggestion for doing this?