07 ¦p¦ó·j´M¬Y¸ô®|¤Uªº©Ò¦³°ÆÀɦW(§t©Ò¦³¤l¥Ø¿ý)

¡@

'©ñ¤@­Ólistbox©Mbutton...

Public Class Form1
Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
Private FoundFile() As String
Private ntx As Long
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ntx = 0
Call GetDirPath("E:\¤u¨ã¸ê®Æ§¨\", "*.exe,*.zip") '¤w­×§ï¦¨¥i·j¦hºØ°ÆÀɦW
Me.Text = "ok"
For i As Integer = 0 To UBound(FoundFile)
ListBox1.Items.Add(FoundFile(i))
Next i
End Sub

Private Sub GetDirPath(ByVal CurrentPath As String, ByVal SearFile As String)
Dim nI As Integer, nDirectory As Integer, i As Long
Dim sFileName As String, sDirectoryList() As String
Dim searfiles() As String = Split(SearFile, ",") '¡¸¦hºØ°ÆÀɦW
Me.Text = "·j´M¤¤-" & CurrentPath
sFileName = Dir(CurrentPath, vbHidden Or vbDirectory Or vbReadOnly Or vbSystem)
Do While sFileName <> ""
For j As Integer = 0 To searfiles.Length - 1 '¡¸
If UCase(sFileName) Like UCase(searfiles(j)) Then
i = GetFileAttributes(CurrentPath + sFileName)
If (i And vbDirectory) = 0 Then
ReDim Preserve FoundFile(ntx)
FoundFile(ntx) = CurrentPath + sFileName
ntx = ntx + 1
End If
End If
Next j
If sFileName <> "." And sFileName <> ".." Then
If GetFileAttributes(CurrentPath & sFileName) _
And vbDirectory Then
nDirectory = nDirectory + 1
ReDim Preserve sDirectoryList(nDirectory)
sDirectoryList(nDirectory) = CurrentPath & sFileName
End If
End If
sFileName = Dir()

Loop
Application.DoEvents()
For nI = 1 To nDirectory
GetDirPath(sDirectoryList(nI) & "\", SearFile)
Next nI
End Sub

End Class

06 °½¤Ñ´«¤é-§âPropertyGrid¤¤ImageÄݩʪº[¡K]´«¦¨¦Û­qªº«ö¶s
¡@ '¥ÎAPI»\¦í image [...]ªº¤è¦¡
'PictureBox,PropertyGrid,Button,Timer ¦U¤@­Ó
Public Class Form1
Structure RECT
Public Left As Integer
Public Top As Integer
Public Right As Integer
Public Bottom As Integer
End Structure

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Integer,
ByRef lpRect As RECT) As Integer
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Integer) As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'­ì¥»¼g¦b³o¶}ÀÉ,¦ý·|³Qfocus¤Á´«¼vÅT...¬G§ï¦ÜMouseDown
End Sub
Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
Dim OPF As New OpenFileDialog
OPF.Filter = "¹ÏÀÉ|*.gif;*.jpg;*.bmp;*.png"
If OPF.ShowDialog = DialogResult.OK Then
PictureBox1.ImageLocation = OPF.FileName
'¸ü¤J¹Ï§Î
PropertyGrid1.SelectedObject = PictureBox1
'­«¸ü§ó·s (.refresh ¦n¹³¨S¥Î~@@)
End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True : Timer1.Interval = 100
With Button1
.Visible = False
.BackColor = Color.Red
.Size = New Size(17, 17)
.Text = "¡K"
End With
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim rect1 As RECT
Dim aWnd As Integer = Me.Handle
'ªí³æ
Static v As Integer
If PropertyGrid1.SelectedGridItem.Label = "Image" Then
'¦pªG¿ï¦b image ÄݩʤW
Dim bWnd As Integer = FindWindowEx(aWnd, 0, vbNullString, "PropertyGrid")
'§ä¨ìPropertyGrid
Dim cWnd As Integer = FindWindowEx(bWnd, 0, vbNullString, "PropertyGridView")
'§ä¨ìPropertyGrid¤º®e°Ï
Dim lpClassName As String = Space$(256)
GetClassName(cWnd, lpClassName, 256)
Dim lpClassName1 As String = Split(lpClassName, "app")(1)
'¨ú±oªí³æ«á½s¸¹...§ä[...]®É¦³¥Î¨ì!
Dim dWnd As Integer = FindWindowEx(cWnd, 0, "WindowsForms10.BUTTON.app" & lpClassName1, vbNullString)
If dWnd <> 0 Then

If IsWindowVisible(dWnd) Then
'¬O¤£¬O¦b¥i¨£½d³ò¤º
Call GetWindowRect(dWnd, rect1)
'¨ú±o¦ì¸m½d³ò
Dim brd As Integer = (Me.Width - Me.ClientRectangle.Width) / 2
'­n¦©°£ªºªí³æÃ䮨
Button1.Location = New Point(rect1.Left - Me.Left - brd - 1, rect1.Top - Me.Top - (Me.Height - Me.ClientRectangle.Height - brd) - 1)
Button1.BringToFront()
Button1.Visible = True
v = 0
Else
v = v + 1
If v = 2 Then Button1.Visible = False : v = 0
'§PÂ_¨ì2¦¸ ¤~½T©wÁôÂÃ!(­ì¥»ªº[...]¦³ÂI¿ð¶w...­nµ¥¥¦¤@¤U!)
End If
Else
Button1.Visible = False
End If
Else
Button1.Visible = False
End If

End Sub

Private Sub PropertyGrid1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles PropertyGrid1.GotFocus
Timer1.Enabled = True
'±o¨ì¾nÂI¤~°Ê

End Sub
Private Sub PropertyGrid1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles PropertyGrid1.LostFocus
Timer1.Enabled = False
End Sub

End Class

05

¹Ï§Îªº±ÛÂà»PÁY©ñ

¡@

'·Æ°Ê·Æ¹«ºu½üÁY©ñ¤j¤p¡A«ö¦íF1¦A·Æºu½ü(¥i«e¡B«áºu)±ÛÂà¹Ï¤ù

Public Class Form1

Dim img1 As Image, imgS As Image

Const PI = 3.14159265

Dim k As Boolean

Dim ang As Integer '¥Ø«eªº¨¤«×

Dim dang As Integer = 5 '¨C¦¸±ÛÂ઺¨¤«×

Dim dsize As Integer = 1 '¨C¦¸ÁY©ñªº®t­È

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

If e.KeyCode = Keys.F1 Then k = True

End Sub

Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp

If e.KeyCode = Keys.F1 Then k = False

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.KeyPreview = True '±µ¦¬Áä½L

'PictureBox1 ¦Û¦æ¸ü¤J§A¦Û¤vªº¹Ï

PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage '³]¬°¥iÁY©ñ

imgS = PictureBox1.Image '¼È¦s­ì¹Ï

End Sub

Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel

'ÁY©ñ

If e.Delta > 0 And k = False Then PictureBox1.Size = PictureBox1.Size.Add(PictureBox1.Size, New Size(dsize, dsize))

If e.Delta < 0 And k = False Then PictureBox1.Size = PictureBox1.Size.Subtract(PictureBox1.Size, New Size(dsize, dsize))

'±ÛÂà

If e.Delta > 0 And k = True Then ang = (ang + dang) Mod 360 : PictureBox1.Image = Rotate(imgS, ang)

If e.Delta < 0 And k = True Then ang = (ang - dang) Mod 360 : PictureBox1.Image = Rotate(imgS, ang)

End Sub

Public Function Rotate(ByVal imgSource As Image, ByVal degree As Integer) As Image

degree = degree Mod 360

If degree < 0 Then degree = 360 + degree

If imgSource Is Nothing Then Return Nothing

Dim ImgTarget As Image = Nothing

Try

Select Case degree

Case 0 To 89

ImgTarget = Rotate0_90(imgSource, degree)

Case 90 To 179

ImgTarget = Rotate90_180(imgSource, degree)

Case 180 To 269

ImgTarget = Rotate180_270(imgSource, degree)

Case 270 To 359

ImgTarget = Rotate270_360(imgSource, degree)

End Select

Catch

End Try

Return ImgTarget

End Function

Private Function Rotate0_90(ByVal img As Image, ByVal degree As Integer) As Image

Dim ImgTarget As Bitmap

Dim alpha As Double = (degree / 180) * PI

Dim iWidth As Integer = img.Width * Math.Cos(alpha) + img.Height * Math.Sin(alpha)

Dim iHeight As Integer = img.Width * Math.Sin(alpha) + img.Height * Math.Cos(alpha)

ImgTarget = New Bitmap(iWidth, iHeight, Drawing.Imaging.PixelFormat.Format24bppRgb)

Dim g As Graphics

g = Graphics.FromImage(ImgTarget)

g.TranslateTransform(img.Height * Math.Sin(alpha), 0)

g.RotateTransform(degree)

g.DrawImage(img, New Rectangle(0, 0, img.Width, img.Height))

Return ImgTarget

End Function

Private Function Rotate90_180(ByVal img As Image, ByVal degree As Integer) As Image

Dim ImgTarget As Bitmap

Dim alpha As Double = ((degree - 90) / 180) * PI

Dim iHeight As Integer = img.Width * Math.Cos(alpha) + img.Height * Math.Sin(alpha)

Dim iWidth As Integer = img.Width * Math.Sin(alpha) + img.Height * Math.Cos(alpha)

ImgTarget = New Bitmap(iWidth, iHeight, Drawing.Imaging.PixelFormat.Format24bppRgb)

Dim g As Graphics

g = Graphics.FromImage(ImgTarget)

g.TranslateTransform(iWidth, img.Height * Math.Sin(alpha))

g.RotateTransform(degree)

g.DrawImage(img, New Rectangle(0, 0, img.Width, img.Height))

Return ImgTarget

End Function

Private Function Rotate180_270(ByVal img As Image, ByVal degree As Integer) As Image

Dim ImgTarget As Bitmap

Dim alpha As Double = ((degree - 180) / 180) * PI

Dim iWidth As Integer = img.Width * Math.Cos(alpha) + img.Height * Math.Sin(alpha)

Dim iHeight As Integer = img.Width * Math.Sin(alpha) + img.Height * Math.Cos(alpha)

ImgTarget = New Bitmap(iWidth, iHeight, Drawing.Imaging.PixelFormat.Format24bppRgb)

Dim g As Graphics

g = Graphics.FromImage(ImgTarget)

g.TranslateTransform(img.Width * Math.Cos(alpha), iHeight)

g.RotateTransform(degree)

g.DrawImage(img, New Rectangle(0, 0, img.Width, img.Height))

Return ImgTarget

End Function

Private Function Rotate270_360(ByVal img As Image, ByVal degree As Integer) As Image

Dim ImgTarget As Bitmap

Dim alpha As Double = ((degree - 270) / 180) * PI

Dim iHeight As Integer = img.Width * Math.Cos(alpha) + img.Height * Math.Sin(alpha)

Dim iWidth As Integer = img.Width * Math.Sin(alpha) + img.Height * Math.Cos(alpha)

ImgTarget = New Bitmap(iWidth, iHeight, Drawing.Imaging.PixelFormat.Format24bppRgb)

Dim g As Graphics

g = Graphics.FromImage(ImgTarget)

g.TranslateTransform(0, img.Width * Math.Cos(alpha))

g.RotateTransform(degree)

g.DrawImage(img, New Rectangle(0, 0, img.Width, img.Height))

Return ImgTarget

End Function

End Class

04

¦p¦ó°õ¦æTextBoxùتº¹Bºâ¦¡?

¡@

Public Class Form1
 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  TextBox1.Text = "100 + (200 + 300) /100"
  Dim sc =
CreateObject("ScriptControl")
  sc.language = "VBscript"
  MsgBox(sc.eval(TextBox1.Text))
  sc = Nothing
 End Sub
End Class

03

¦p¦ó¨ú±o©Ò¦³°õ¦æ¤¤ªºµ{§Ç?

¡@

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 For Each i As Process In Process.GetProcesses '¨ú±o©Ò¦³°õ¦æ¤¤ªºµ{§Ç

  Debug.Print(i.ProcessName & vbTab & i.Id)

  'If i.ProcessName = "notepad" Then i.Kill() '¦pªG¦³µ§°O¥»«hÃö³¬¥¦

 Next

End Sub

End Class

02

¦p¦ó§ì·í¤U®y¼Ðªº­I´ºÃC¦â?

¡@

Public Class Form1

  Dim g As Graphics, b As Bitmap

  Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove

  b = PictureBox1.BackgroundImage

  Debug.Print(Hex(b.GetPixel(e.X, e.Y).R) & " " & Hex(b.GetPixel(e.X, e.Y).G) & " " & Hex(b.GetPixel(e.X, e.Y).B))

 End Sub

 Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove

  b = Me.BackgroundImage

  Debug.Print(Hex(b.GetPixel(e.X, e.Y).R) & " " & Hex(b.GetPixel(e.X, e.Y).G) & " " & Hex(b.GetPixel(e.X, e.Y).B))

 End Sub

¡@

'¥H¤U¯Â¬°µe¤@¨ÇªFªF¦n´ú¸Õ...®M¥Î®É½Ð¦Û©¿²¤~

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

  PictureBox1.BackColor = Color.Black : PictureBox1.Location = New Point(100, 100)

  PictureBox1.Size = New Size(100, 100) : PictureBox1.BackgroundImage = New Bitmap(100, 100)

  g = System.Drawing.Graphics.FromImage(PictureBox1.BackgroundImage)

  g.DrawLine(Pens.Blue, 0, 0, 50, 50) : g.DrawLine(Pens.Red, 100, 0, 0, 100)

  Me.BackgroundImage = New Bitmap(1024, 768)

  g = System.Drawing.Graphics.FromImage(Me.BackgroundImage)

  g.FillRectangle(Brushes.Yellow, New Rectangle(0, 0, 100, 100))

  g.FillRectangle(Brushes.Green, New Rectangle(0, 0, 50, 50))

 End Sub

End Class

01

¼³§JµP¶Ã¼ÆµoµP-§tªá¦â

¡@

Public Class Form1
 Dim poker(0 To 51) As String
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  Dim i As Integer
  For i = 0 To 51 : poker(i) = ((i Mod 13 + 1) & Mid("♠♣♥♦", (i \ 13) + 1, 1)) : Next
  Randomize()
  For i = 1 To 100 : swap(Int(Rnd() * 52), Int(Rnd() * 52)) : Next
  For i = 1 To 4 : Me.Controls("textbox" & i).Text = "" : Next
  For i = 0 To 51 : Me.Controls("textbox" & (i \ 13) + 1).Text += poker(i) & IIf(poker(i).Length = 2, " ", " ") : Next
  For i = 1 To 4 : Debug.Print(Me.Controls("textbox" & i).Text) : Next
 End Sub

 Sub swap(ByVal p1, ByVal p2)
  Dim t As String = poker(p1)
  poker(p1) = poker(p2) : poker(p2) = t
 End Sub
End Class
¡@

µ²ªG:

12♦ 11♦ 6♣ 1♣ 13♠ 3♦ 9♠ 10♥ 4♣ 10♠ 8♠ 5♦ 5♣
3♥ 9♦ 3♠ 7♠ 3♣ 4♠ 12♣ 13♣ 10♦ 1♠ 8♦ 2♦ 12♠
7♦ 4♥ 9♣ 2♣ 6♦ 10♣ 12♥ 7♥ 6♥ 11♣ 2♥ 5♥ 13♦
11♠ 11♥ 4♦ 7♣ 1♦ 6♠ 13♥ 9♥ 8♥ 2♠ 8♣ 1♥ 5♠

¡@