dat form o vi tri cho truoc

13 49 0
  • Loading ...
1/13 trang

Thông tin tài liệu

Ngày đăng: 13/04/2018, 11:46

1 Private Enum FormPosition FrmTopLeft = FrmTopRight = FrmCenter = FrmBottomLeft = FrmBottomRight = End Enum Private Type RECT 10 Left As Long 11 Top As Long 12 Right As Long 13 Bottom As Long 14 End Type 15 16 Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long 17 Private Const SPI_GETWORKAREA As Long = 48 18 19 Private Function MoveForm(Frm As Form, Optional sType As FormPosition = 2) As Long 20 Dim Area As RECT 21 If SystemParametersInfo(SPI_GETWORKAREA, 0, Area, 0) Then 22 Select Case sType 23 Case 24 Frm.Move 0, 25 Case 26 Frm.Move Frm.ScaleX(Area.Right, vbPixels, vbTwips) - Frm.Width, 27 Case 28 Frm.Move (Frm.ScaleX(Area.Right, vbPixels, vbTwips) - Frm.Width) \ 2, (Frm.ScaleY(Area.Bottom, vbPixels, vbTwips) - Frm.Height) \ 29 Case 30 Frm.Move 0, Frm.ScaleY(Area.Bottom, vbPixels, vbTwips) - Frm.Height 31 Case 32 Frm.Move Frm.ScaleX(Area.Right, vbPixels, vbTwips) - Frm.Width, Frm.ScaleY(Area.Bottom, vbPixels, vbTwips) - Frm.Height 33 End Select 34 End If 35 End Function 36 37 Private Sub Form_Load() 38 'MoveForm Me, FrmBottomLeft 39 'MoveForm Me, FrmBottomRight 40 MoveForm Me, FrmCenter 41 'MoveForm Me, FrmTopLeft 42 'MoveForm Me, FrmTopRight 43 End Sub  Top 2- Doc textbox theo tung dong Function TachDong(mStr As String) As Collection Dim cLt As New Collection Dim pos As Integer Dim mLine As String mStr = mStr + vbNewLine pos = InStr(mStr, Chr(13)) Do While pos mLine = Left(mStr, pos - 1) 10 cLt.Add mLine 11 mStr = Right(mStr, Len(mStr) - pos - 1) 12 pos = InStr(mStr, Chr(13)) 13 Loop 14 Set TachDong = cLt 15 End Function 16 Hàm tách dòng trả đối tượng kiểu Collection (cách sử dụng đối tượng giống y listbox) Cách dùng: Code: Chọn tất Private Sub Command1_Click() Dim cL As New Collection 'Tạo đối tượng Collection Set cL = TachDong(Text1.Text) 'Gán đối tượng đối tượng trả TachDong Dim I As Integer Dim nmLine For I = To cL.Count 'Duyệt tất item cL 10 nmLine = CStr(cL.Item(I)) 11 List1.AddItem nmLine 'add dòng cL vào listBox 12 Next 13 End Sub 14 3- Đọc Ghi Excel (xls) với TextBox chuẩn ta da quen với việc muốn đọc ghi file Excel (xls) buộc phải chèn thư viện Excel Bài viết kèm Project sau rình bày kỹ thuật Đọc Ghi Excel (xls) với TextBox chuẩn (Thực DDE [Dynamic Data Exchange] thực hiện, mà TextBox chuẩn MS thiết kế có kèm hoạt động DDE) * Code hoạt động XP SP2, cần Text1 vài command code Giao tiếp với file XLS (2003) Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long Const SW_SHOWNORMAL = Private Sub Command1_Click() ' Ðoc Sheet1 OpenExcel Text1.LinkMode = Text1.LinkTopic = "Excel|Book1.xls" Text1.LinkItem = "R1C1:R6C2" Text1.LinkMode = 10 Text1.LinkMode = 11 CloseExcel 12 End Sub 13 14 'truongphu 15 Private Sub Command2_Click() ' Ðoc Sheet2 16 OpenExcel 17 Text1.LinkMode = 18 Text1.LinkTopic = "Excel|Sheet2" 19 Text1.LinkItem = "R1C1:R6C2" 20 Text1.LinkMode = 21 Text1.LinkMode = 22 CloseExcel 23 End Sub 24 25 Private Sub Command3_Click() ' Ghi Sheet1 26 OpenExcel 27 Text1.LinkMode = 28 Text1.LinkTopic = "Excel|Sheet1" 29 Text1.LinkItem = "R1C4:R2C6" 30 Text1.LinkMode = 31 Text1 = "Ho" & vbTab & "Tên" & vbTab & "Tuôi" & vbCrLf & "Bùi" & vbTab & "Toàn" & vbTab & 22 32 Text1.LinkPoke 33 Text1.LinkMode = 34 'CloseExcel 35 End Sub 36 37 Private Sub Command4_Click() ' Font Cell 38 OpenExcel 39 Text1.LinkMode = 40 Text1.LinkTopic = "Excel|Sheet1" 41 Text1.LinkMode = 42 Text1.LinkExecute ("[SELECT(""R2C5"")]") 43 Text1.LinkExecute ("[FONT.PROPERTIES(""Times New Roman"",""Bold"",10)]") 44 Text1.LinkMode = 45 'CloseExcel 46 End Sub 47 48 Sub CloseExcel() ' not save 49 Set aaa = GetObject("winmgmts:\root\cimv2").ExecQuery _ 50 ("Select * from Win32_Process Where Name = 'Excel.exe'") 51 For Each a In aaa 52 a.Terminate 53 Next 54 End Sub 55 56 Sub OpenExcel() 57 If IsFileOpen(App.Path & "\qqq.xls") = False Then 58 ShellExecute Me.hwnd, vbNullString, App.Path & "\Book1.xls", _ 59 vbNullString, vbNullString, SW_SHOWNORMAL 60 End If 61 End Sub 62 63 Function IsFileOpen(FileName As String) As Boolean 64 Dim filenum As Integer 'truongphu 65 filenum = FreeFile() 66 On Error Resume Next 67 Open FileName For Input Lock Read As #filenum 68 Close filenum 69 Select Case Err 70 Case 71 IsFileOpen = False 72 Case 70 73 IsFileOpen = True 74 Case Else 75 End Select 76 End Function 77 4-Đóng ứng dụng phong cách Private Sub Form_Load() Form1.Height = 6400 Form1.Width = 10000 End Sub Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbRightButton Then coolCloseForm Me, 20 Else Dim a As New Form1 10 a.Height = a.Height / 11 a.Width = a.Width / 12 a.Show 13 14 15 16 End If End Sub Public Function coolCloseForm(closeForm As Form, speed As Integer) 17 18 19 20 21 22 23 24 25 26 27 28 If speed = Then MsgBox "Speed cannot zero" Exit Function End If On Error Resume Next closeForm.ScaleMode = closeForm.WindowState = Do Until closeForm.Height
- Xem thêm -

Xem thêm: dat form o vi tri cho truoc, dat form o vi tri cho truoc, Tạo ListBox và ComboBox... ngược

Từ khóa liên quan

Gợi ý tài liệu liên quan cho bạn

Nhận lời giải ngay chưa đến 10 phút Đăng bài tập ngay