Advertisement
ledlight

FarbKnopf

Jun 25th, 2022
861
320 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class MyButton
  2.     Inherits Button
  3.  
  4.     Public WithEvents Measurement As New Button
  5.     Private Function GetFormImage(ByVal include_borders As _
  6.     Boolean) As Bitmap
  7.         ' Make the bitmap.
  8.         Dim wid As Integer = Me.Width
  9.         Dim hgt As Integer = Me.Height
  10.         Dim bm As New Bitmap(wid, hgt)
  11.  
  12.         ' Draw the form onto the bitmap.
  13.         Me.DrawToBitmap(bm, New Rectangle(0, 0, wid, hgt))
  14.  
  15.         ' If we want the borders, return the bitmap.
  16.         If include_borders Then Return bm
  17.  
  18.         ' Make a smaller bitmap without borders.
  19.         wid = Me.ClientSize.Width
  20.         hgt = Me.ClientSize.Height
  21.         Dim bm2 As New Bitmap(wid, hgt)
  22.  
  23.         ' Get the offset from the window's corner to its client
  24.         ' area's corner.
  25.         Dim pt As New Point(0, 0)
  26.         pt = PointToScreen(pt)
  27.         Dim dx As Integer = pt.X - Me.Left
  28.         Dim dy As Integer = pt.Y - Me.Top
  29.  
  30.         ' Copy the part of the original bitmap that we want
  31.         ' into the bitmap.
  32.         Dim gr As Graphics = Graphics.FromImage(bm2)
  33.         gr.DrawImage(bm, 0, 0, New Rectangle(dx, dy, wid, hgt),
  34.         GraphicsUnit.Pixel)
  35.         Return bm2
  36.     End Function
  37.     Sub Konzertkarte(Farn As Button)
  38.         With Farn
  39.             .Location = New Point(250, 250)
  40.             '.BackgroundImage = New Bitmap("C:\Temp\karu.bmp")
  41.             '.Size = Farn.BackgroundImage.Size
  42.         End With
  43.     End Sub
  44.  
  45.     Sub LockUnlockBitsExample(ByVal e As PaintEventArgs)
  46.  
  47.         'Create a new bitmap.
  48.         Dim bmp As New Bitmap("C:\Temp\karu.bmp")
  49.         Dim test_zeilenumbruch As Graphics = Graphics.FromImage(bmp)
  50.         test_zeilenumbruch.Dispose()
  51.  
  52.         'Lock the bitmap's bits.  
  53.         Dim rect As New Rectangle(0, 0, bmp.Width, bmp.Height)
  54.         Dim bmpData As System.Drawing.Imaging.BitmapData =
  55.             bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
  56.             bmp.PixelFormat)
  57.  
  58.         'Get the address of the first line.
  59.         Dim ptr As IntPtr = bmpData.Scan0
  60.  
  61.         'Declare an array to hold the bytes of the bitmap.
  62.         Dim bytes As Integer = Math.Abs(bmpData.Stride) * bmp.Height
  63.         Dim rgbValues(bytes) As Byte
  64.  
  65.         'Copy the RGB values into the array.
  66.         System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes)
  67.  
  68.         'Set every third value to 255. A 24bpp bitmap will look red.  
  69.         For counter As Integer = 2 To rgbValues.Length - 1 Step 3
  70.             rgbValues(counter) = 255
  71.         Next
  72.         'Copy the RGB values back to the bitmap
  73.         System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes)
  74.  
  75.         'Unlock the bits.
  76.         bmp.UnlockBits(bmpData)
  77.  
  78.         'Draw the modified image.
  79.         e.Graphics.DrawImage(bmp, 300, 200)
  80.  
  81.     End Sub
  82.     Public toggle As Integer
  83.     Public Pong As Boolean
  84.     Private Sub Measurement_Click(sender As Object, e As EventArgs) Handles Measurement.Click
  85.         If toggle Then
  86.             'Measurement.Text = "Status: ON"
  87.             Measurement.BackgroundImage = New Bitmap("C:\Temp\karu.bmp")
  88.             Measurement.Size = Measurement.BackgroundImage.Size
  89.  
  90.             Dim graph As Graphics
  91.             Dim frmleft As System.Drawing.Point = Me.Bounds.Location
  92.             Dim bmp As New Bitmap(48, 48) 'Me.Bounds.Width + 8, Me.Bounds.Height + 8
  93.             graph = Graphics.FromImage(bmp)
  94.             Dim screenx As Integer = frmleft.X
  95.             Dim screeny As Integer = frmleft.Y
  96.  
  97.             graph.CopyFromScreen(screenx + 58, screeny + 81, 0, 0, bmp.Size)
  98.             bmp.Save("C:\Temp\RaidThrough.bmp", System.Drawing.Imaging.ImageFormat.Jpeg)
  99.         Else
  100.             'Measurement.Text = "Status: OFF"
  101.             Measurement.BackgroundImage = New Bitmap("C:\Temp\DimSim.bmp")
  102.             Measurement.Size = Measurement.BackgroundImage.Size
  103.  
  104.             Pong = True
  105.             Form1.Invalidate()
  106.         End If
  107.         toggle = Not toggle
  108.     End Sub
  109. End Class
  110.  
Advertisement
RAW Paste Data Copied
Advertisement