Highlighted
Absent Member.
Absent Member.
1004 views

Visual Cobol: Gradient Coloring a Tabpage

Jump to solution

I want to color my tabpages using gradient colors. I got this example in Visual Basic:
Public Class Form1
    Dim a As Integer
    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.DoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)
    End Sub
    Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim formGraphics As Graphics = e.Graphics
        Dim GD As Drawing2D.LinearGradientBrush
        If a = 1 Then
            GD = New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(Width, Height), Color.White, Color.FromArgb(0, 0, 222))
        ElseIf a = 2 Then
            GD = New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(Width, 0), Color.White, Color.FromArgb(0, 222, 0))
        ElseIf a = 3 Then
            GD = New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, Height), Color.White, Color.FromArgb(222, 0, 0))
        Else
            GD = New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, Height), Color.White, Color.FromArgb(0, 0, 0))
            a = 1
        End If
        formGraphics.FillRectangle(GD, ClientRectangle)
        GD.Dispose()
    End Sub
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        a = a + 1
        Refresh()
    End Sub
End Class 

the example colors the whole form; changes color when button1 is pushed. I am not aquainted to VB. Is there an example in Visual Cobol?

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Visual Cobol: Gradient Coloring a Tabpage

Jump to solution

I have attached an example Visual COBOL solution that demonstrates this.

The following is the COBOL equivalent to the VB code that you posted:

     $set ilusing"System.Drawing"
     $set ilusing"System.Drawing.Drawing2D"
      class-id testgradientcolor.Form1 is partial
                inherits type System.Windows.Forms.Form.
      working-storage section.
      01 a binary-long.
      method-id NEW.
      procedure division.
          invoke self::InitializeComponent
          goback.
      end method.
      method-id Form1_Paint final private.
      01 formGraphics type Graphics.
      01 GD type System.Drawing.Drawing2D.LinearGradientBrush.
      procedure division using by value sender as object e as type System.Windows.Forms.PaintEventArgs.
         set formGraphics to e::Graphics
         if a = 1
           set GD to New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(self::Width, self::Height),
              type Color::White, type Color::FromArgb(0, 0, 222))
         else
            if a = 2
               set GD to New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(self::Width, 0),
                  type Color::White, type Color::FromArgb(0, 222, 0))
            else
               if a = 3
                  set GD to New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, self::Height),
                     type Color::White, type Color::FromArgb(222, 0, 0))
               else
                  set GD to New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, self::Height),
                     type Color::White, type Color::FromArgb(0, 0, 0))
                  set a to 1
               end-if
            end-if
         end-if
         invoke formGraphics::FillRectangle(GD, self::ClientRectangle)
         invoke GD::Dispose
         exit method.
      end method.
      method-id button1_Click final private.
      procedure division using by value sender as object e as type System.EventArgs.
          set a to a + 1
          invoke self::Refresh
          exit method.
      end method.
      method-id Form1_Load final private.
      procedure division using by value sender as object e as type System.EventArgs.
         invoke self::SetStyle(type ControlStyles::AllPaintingInWmPaint B-Or type ControlStyles::DoubleBuffer
            B-Or type ControlStyles::ResizeRedraw B-Or type ControlStyles::UserPaint, True)
         exit method.
      end method.
      end class.

View solution in original post

0 Likes
1 Reply
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Visual Cobol: Gradient Coloring a Tabpage

Jump to solution

I have attached an example Visual COBOL solution that demonstrates this.

The following is the COBOL equivalent to the VB code that you posted:

     $set ilusing"System.Drawing"
     $set ilusing"System.Drawing.Drawing2D"
      class-id testgradientcolor.Form1 is partial
                inherits type System.Windows.Forms.Form.
      working-storage section.
      01 a binary-long.
      method-id NEW.
      procedure division.
          invoke self::InitializeComponent
          goback.
      end method.
      method-id Form1_Paint final private.
      01 formGraphics type Graphics.
      01 GD type System.Drawing.Drawing2D.LinearGradientBrush.
      procedure division using by value sender as object e as type System.Windows.Forms.PaintEventArgs.
         set formGraphics to e::Graphics
         if a = 1
           set GD to New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(self::Width, self::Height),
              type Color::White, type Color::FromArgb(0, 0, 222))
         else
            if a = 2
               set GD to New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(self::Width, 0),
                  type Color::White, type Color::FromArgb(0, 222, 0))
            else
               if a = 3
                  set GD to New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, self::Height),
                     type Color::White, type Color::FromArgb(222, 0, 0))
               else
                  set GD to New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, self::Height),
                     type Color::White, type Color::FromArgb(0, 0, 0))
                  set a to 1
               end-if
            end-if
         end-if
         invoke formGraphics::FillRectangle(GD, self::ClientRectangle)
         invoke GD::Dispose
         exit method.
      end method.
      method-id button1_Click final private.
      procedure division using by value sender as object e as type System.EventArgs.
          set a to a + 1
          invoke self::Refresh
          exit method.
      end method.
      method-id Form1_Load final private.
      procedure division using by value sender as object e as type System.EventArgs.
         invoke self::SetStyle(type ControlStyles::AllPaintingInWmPaint B-Or type ControlStyles::DoubleBuffer
            B-Or type ControlStyles::ResizeRedraw B-Or type ControlStyles::UserPaint, True)
         exit method.
      end method.
      end class.

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.