Public Class form1
Private WithEvents document As New System.Drawing.Printing.PrintDocument
Dim TreeView1 As New TreeView
' Initalize the dialog.
Dim btnprint As Boolean = False
Dim btncolor As Boolean = False
Dim instance As PageSetupDialog
Dim a, b, n1, n2, n3, i, kk, i2, clicknum As Integer
Dim dtextbox(n3) As RichTextBox
Dim myxls As Object
Dim mybooks As Object
Dim mybook As Object
Dim mySht As Object
Dim myRange, myRange2 As Object
Dim dtextboxA1, dtextboxA2, dtextboxA3 As New RichTextBox
'Dim a, b As Integer
'Dim btn As Object
Dim x As String
Dim FillErrorEventHandler As Object
Dim y As Integer
Private Sub Btnpath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpath.Click
Dim ofd As New OpenFileDialog
'If ofd.ShowDialog() = DialogResult.OK Then
'If ofd.FileName <> "" Then
'End If
'End If
ofd.ShowDialog()
Tetpath.Text = CStr(ofd.FileName)
End Sub
Public Sub startbtnClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startbtn.Click
' Me.ActiveMdiChild.Close()
'Form2.Show()
If Tetpath.Text = "" Then
MsgBox("請輸入正確的Excel檔.Xls路徑")
Exit Sub
End If
If Microsoft.VisualBasic.Right(Tetpath.Text, 3) = "xls" Then
GoTo 3
Else
MsgBox("你選的並非Excel檔,請重新選擇正確 Xls路徑")
Exit Sub
End If
'宣告Excel各種物件
3: '啟動Excel
myxls = CreateObject("Excel.Application")
' myxls.Visible = True '''顯示Excel
mybooks = myxls.workbooks
'開檔案
mybook = mybooks.open(Tetpath.Text)
'取得Sheet
mySht = mybook.sheets(1)
'mySht.Activate()
Dim c, d As String
'取得Cell
Dim i, kk As Integer
Dim myRange, myRange2 As Object
For kk = 1 To 100
c = "a" & CStr(kk)
myRange = mySht.range(c)
If IsNothing(myRange.value) = True Then
kk = kk - 1
GoTo 5
End If
Next
5:
n1 = NumericUpDown1.Value
n2 = NumericUpDown2.Value
n3 = n1 * n2
Dim dtextbox(n3) As RichTextBox
Dim w1, w2, h1, h2 As Integer
Dim jarray(kk) As Integer
'Location = New Point(10, 0)
'=============================
Select Case n1
Case n1 < 6
w1 = 80
w2 = 100
Case n1 = 6, 7
w1 = 80
w2 = 90
Case n1 > 7
w1 = 80
w2 = 85
End Select
Select Case n2
Case n2 < 7
h1 = 60
h2 = 80
Case n2 = 7, 8
h1 = 60
h2 = 70
Case n2 > 8
h1 = 60
h2 = 65
End Select
'MsgBox(w1, h1)
For i = 0 To n3 - 1
15:
Randomize()
Dim j As Integer = CInt(Int((kk * Rnd()) + 1))
If i >= kk Then
x = Nothing
GoTo 30
End If
'不重複
If jarray(j) = 0 Then
jarray(j) = 13
GoTo 20
Else
GoTo 15
End If
'''''''''
'''''''''
20:
a = j + 1
b = a + 1
c = "a" & CStr(j)
d = "b" & CStr(j)
myRange = mySht.range(c)
myRange2 = mySht.range(d)
x = myRange2.value & Chr(13) & Chr(10) & myRange.value()
30:
dtextbox(i) = New RichTextBox
dtextbox(i).Tag = i
dtextbox(i).Name = "dtextbox" & CStr(i)
dtextbox(i).Width = 90
dtextbox(i).Height = 60
'MsgBox(w1, h1)
dtextbox(i).Left = 100 * (i Mod n1 + 1)
dtextbox(i).Top = 80 * (i \ n1 + 1)
dtextbox(i).Text = x '"Btn" & i
dtextbox(i).SelectionFont = New Font("標楷體", 12, FontStyle.Bold)
dtextbox(i).ScrollBars = RichTextBoxScrollBars.None
Me.Controls.Add(dtextbox(i))
AddHandler dtextbox(i).Click, AddressOf dtextbox_Click
Next
'mybook.save()
mybook.close()
GC.Collect()
'mybooks.quit()
myRange = Nothing
myRange2 = Nothing
mySht = Nothing
mybooks = Nothing
End Sub
Private Sub dtextbox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If btncolor = True Then
CType(sender, RichTextBox).BackColor = Color.White
btncolor = False
GoTo 45
End If
If btnprint = True Then
GoTo 40
End If
clicknum = clicknum + 1
If clicknum > 2 Then
dtextboxA1.BackColor = Color.White
dtextboxA2.BackColor = Color.White
clicknum = 1
End If
Select Case clicknum
Case 1
'dtextboxA1.Name = CType(sender, RichTextBox).Name
i = CType(sender, RichTextBox).Tag
'MsgBox(CType(sender, RichTextBox).Name)
' i2 = i
dtextboxA1 = CType(sender, RichTextBox)
CType(sender, RichTextBox).BackColor = Color.Orange
'dtextbox(i).Name = "jjjjjj"
Case 2
'dtextboxA2.Name = CType(sender, RichTextBox).Name
i2 = CType(sender, RichTextBox).Tag
'MsgBox(CType(sender, RichTextBox).Name)
' i2 = i
dtextboxA2 = CType(sender, RichTextBox)
CType(sender, RichTextBox).BackColor = Color.Orchid
'dtextbox(i2) = dtextboxA2
End Select
40:
CType(sender, RichTextBox).BackColor = Color.Orchid
45: 'btnprint = True
End Sub
Private Sub exchangeBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exchangeBtn.Click
Dim dtextbox(n3) As RichTextBox
dtextboxA3.Text = dtextboxA1.Text
dtextboxA1.Text = dtextboxA2.Text
dtextboxA2.Text = dtextboxA3.Text
dtextboxA1.BackColor = System.Drawing.Color.White
dtextboxA2.BackColor = System.Drawing.Color.White
'CType(sender, RichTextBox).ForeColor = Color.Black
End Sub
Private Sub buttonprint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonprint.Click
Tetpath.Visible = False
Me.btnpath.Visible = False
Me.startbtn.Visible = False
Me.NumericUpDown1.Visible = False
Me.Label1.Visible = False
Me.NumericUpDown2.Visible = False
Me.Label2.Visible = False
Me.Label3.Visible = False
Me.exchangeBtn.Visible = False
Me.buttonprint.Visible = False
Me.Buttonfont.Visible = False
Me.Buttonclass.Visible = True
Buttoncolorreset.Visible = False
Dim PD As New PrintDialog
If PD.ShowDialog() = Windows.Forms.DialogResult.Cancel Then
Me.buttonprint.Visible = True
Me.Buttonfont.Visible = True
Exit Sub
End If
Dim PN = PD.PrinterSettings.PrinterName
PrintForm1.Form = Me
PrintForm1.PrinterSettings.PrinterName = PN
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
'PrintForm1.PrintAction = Printing.PrintAction.PrintToFile
PrintForm1.Print()
Me.buttonprint.Visible = True
Me.Buttonfont.Visible = True
End Sub
Private Sub Buttonfont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonfont.Click
btnprint = True
Tetpath.Visible = False
Me.btnpath.Visible = False
Me.startbtn.Visible = False
Me.NumericUpDown1.Visible = False
Me.Label1.Visible = False
Me.NumericUpDown2.Visible = False
Me.Label2.Visible = False
Me.Label3.Visible = False
Me.exchangeBtn.Visible = False
Me.buttonprint.Visible = True
Me.Buttonfont.Visible = False
Buttoncolorreset.Visible = True
FontDialog1.ShowColor = True
FontDialog1.Font = Me.Font
FontDialog1.Color = Me.ForeColor
'FontDialog1.ShowDialog()
If FontDialog1.ShowDialog() <> DialogResult.Cancel Then
Me.Font = FontDialog1.Font
Me.ForeColor = FontDialog1.Color
End If
End Sub
Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Buttoncolorreset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttoncolorreset.Click
btncolor = True
End Sub
End Class
沒有留言:
張貼留言