Tạo Menu nhưng nó ko hiện hết button

Liên hệ QC

zazabovn

Thành viên mới
Tham gia
13/10/08
Bài viết
2
Được thích
0
untitled.JPG


Em tạo ra 14 nút nhưng khi hiển thị nó chỉ hiển thị 5 nút
vậy h pải làm sao các pro
Vẫn bắt được sự kiện click vào các nút
đây là code
Mã:
Public Class Sheet1
    'Private commandBar As Office.CommandBar
    'Private selectedBookmark As Microsoft.Office.Tools.Excel.b
    Private WithEvents menuCommand As Office.CommandBarButton
    Private menuTag_DuToan As String = "Menu Du Toan"
    Private menuTag_DuThau As String = "Menu Du Thau"
    Private menuTag_TienIch As String = "Menu Tien Ich"
    Private WithEvents menuDuToan_TaoMoi As Office.CommandBarButton
    Private WithEvents menuDuToan_MoFile As Office.CommandBarButton
    Private WithEvents menuDuToan_DoiTenConTrinh As Office.CommandBarButton
    Private WithEvents menuDuToan_CSDL As Office.CommandBarButton
    Private WithEvents menuDuToan_PhanTichVatTu As Office.CommandBarButton
    Private WithEvents menuDuToan_TongHopVatTu As Office.CommandBarButton
    Private WithEvents menuDuToan_TinhGiaTri As Office.CommandBarButton
    Private WithEvents menuDuToan_TinhChenhLech As Office.CommandBarButton
    Private WithEvents menuDuToan_TinhChiPhiVanChuyen As Office.CommandBarButton
    Private WithEvents menuDuToan_TinhDonGiaChiTiet As Office.CommandBarButton
    Private WithEvents menuDuToan_TinhDuToanDuThau As Office.CommandBarButton
    Private WithEvents menuDuToan_ChenPTVT As Office.CommandBarButton
    Private WithEvents menuDuToan_ChenPhanTichDGCT As Office.CommandBarButton
    Private WithEvents menuDuToan_GioiThieu As Office.CommandBarButton

    'add menu
    Private Sub CheckIfMenuBarExists()
        Try
Dim foundMenu_DuToan As Office.CommandBarPopup = Me.Application.CommandBars.ActiveMenuBar.FindControl(Office.MsoControlType.msoControlPopup, System.Type.Missing, menuTag_DuToan, True, True)

            If foundMenu_DuToan IsNot Nothing Then
                foundMenu_DuToan.Delete(True)
            End If
Dim foundMenu_DuThau As Office.CommandBarPopup = Me.Application.CommandBars.ActiveMenuBar.FindControl(Office.MsoControlType.msoControlPopup, System.Type.Missing, menuTag_DuThau, True, True)
            If foundMenu_DuThau IsNot Nothing Then
                foundMenu_DuThau.Delete(True)
            End If
Dim foundMenu_TienIch As Office.CommandBarPopup = Me.Application.CommandBars.ActiveMenuBar.FindControl(Office.MsoControlType.msoControlPopup, System.Type.Missing, menuTag_TienIch, True, True)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub
    Private Sub AddMenuDuToan()
        Try
            Dim menuDuToan As Office.CommandBar = Application.CommandBars.ActiveMenuBar
            Dim menuDuToanCaption As String = "Dự Toán GXD"
            If menuDuToan IsNot Nothing Then
                Dim cmdBarControlDuToan As Office.CommandBarPopup = Nothing
                Dim controlCountDuToan As Integer = menuDuToan.Controls.Count
cmdBarControlDuToan = CType(menuDuToan.Controls.Add(Office.MsoControlType.msoControlPopup, Before:=controlCountDuToan, Temporary:=True), Office.CommandBarPopup)
                cmdBarControlDuToan.Caption = menuDuToanCaption
                'add nut
menuDuToan_TaoMoi = CType(cmdBarControlDuToan.Controls.Add(Type:=Office.MsoControlType.msoControlButton, Temporary:=True), Office.CommandBarButton)
                With menuDuToan_TaoMoi
                    .Caption = "Tạo Hạng Mục Mới"
                    .Tag = "TaoHangMucMoi"
                    .FaceId = 66
                End With
menuDuToan_MoFile = CType(cmdBarControlDuToan.Controls.Add(Type:=Office.MsoControlType.msoControlButton, Temporary:=True), Office.CommandBarButton)
                With menuDuToan_MoFile
                    .Caption = "Mở File Dự Toán... "
                    .Tag = "MoFileDuToan"
                    .FaceId = 67
                End With
menuDuToan_DoiTenConTrinh = CType(cmdBarControlDuToan.Controls.Add(Type:=Office.MsoControlType.msoControlButton, Temporary:=True), Office.CommandBarButton)
                With menuDuToan_DoiTenConTrinh
                    .Caption = "Đổi Tên Công Trình/Hạng Muc..."
                    .Tag = "DoiTenCongTrinhHangMuc"
                    .FaceId = 68
                End With
menuDuToan_CSDL = CType(cmdBarControlDuToan.Controls.Add(Type:=Office.MsoControlType.msoControlButton, Temporary:=True), Office.CommandBarButton)
                With menuDuToan_CSDL
                    .Caption = "Lựa Chọn Cơ Sở Dữ Liệu"
                    .Tag = "LuaChonCoSoDuLieu"
                    .FaceId = 69
                End With
menuDuToan_PhanTichVatTu = CType(cmdBarControlDuToan.Controls.Add(Type:=Office.MsoControlType.msoControlButton, Temporary:=True), Office.CommandBarButton)
                With menuDuToan_PhanTichVatTu
                    .Caption = "Phân tích vật tư"
                    .Tag = "PhanTichVatTu"
                    .FaceId = 70
                End With
menuDuToan_TongHopVatTu = CType(cmdBarControlDuToan.Controls.Add(Type:=Office.MsoControlType.msoControlButton, Temporary:=True), Office.CommandBarButton)
                With menuDuToan_PhanTichVatTu
                    .Caption = "2. Tổng hợp vật tư..."
                    .Tag = "TongHopVatTu"
                    .FaceId = 71
                End With
menuDuToan_TinhGiaTri = CType(cmdBarControlDuToan.Controls.Add(Type:=Office.MsoControlType.msoControlButton, Temporary:=True), Office.CommandBarButton)
                With menuDuToan_PhanTichVatTu
                    .Caption = "3. Tính giá trị vật tư..."
                    .Tag = "TinhGiaTriVatTu"
                    .FaceId = 72
                End With
menuDuToan_TinhChenhLech = CType(cmdBarControlDuToan.Controls.Add(Type:=Office.MsoControlType.msoControlButton, Temporary:=True), Office.CommandBarButton)
                With menuDuToan_PhanTichVatTu
                    .Caption = "4. Tính chênh lệch vật tư..."
                    .Tag = "TinhChenhLechVatTu"
                    .FaceId = 73
                End With
menuDuToan_TinhChiPhiVanChuyen = CType(cmdBarControlDuToan.Controls.Add(Type:=Office.MsoControlType.msoControlButton, Temporary:=True), Office.CommandBarButton)
                With menuDuToan_PhanTichVatTu
                    .Caption = "Tính chi phí vận chuyển..."
                    .Tag = "TinhChiPhiVanChuyen"
                    .FaceId = 74
                End With
menuDuToan_TinhDonGiaChiTiet = CType(cmdBarControlDuToan.Controls.Add(Type:=Office.MsoControlType.msoControlButton, Temporary:=True), Office.CommandBarButton)
                With menuDuToan_PhanTichVatTu
                    .Caption = "6. Tính đơn giá chi tiết..."
                    .Tag = "TinhDonGiaChiTiet"
                    .FaceId = 75
                End With
menuDuToan_TinhDuToanDuThau = CType(cmdBarControlDuToan.Controls.Add(Type:=Office.MsoControlType.msoControlButton, Temporary:=True), Office.CommandBarButton)
                With menuDuToan_PhanTichVatTu
                    .Caption = "7. Tính dự toán dự thầu"
                    .Tag = "TinhDuToanDuThau"
                    .FaceId = 76
                End With
menuDuToan_ChenPTVT = CType(cmdBarControlDuToan.Controls.Add(Type:=Office.MsoControlType.msoControlButton, Temporary:=True), Office.CommandBarButton)
                With menuDuToan_PhanTichVatTu
                    .Caption = "Chèn PTVT công việc vào bảng PTVT"
                    .Tag = "ChenPTVT"
                    .FaceId = 165
                End With
menuDuToan_ChenPhanTichDGCT = CType(cmdBarControlDuToan.Controls.Add(Type:=Office.MsoControlType.msoControlButton, Temporary:=True), Office.CommandBarButton)
                With menuDuToan_PhanTichVatTu
                    .Caption = "Chèn phân tích ĐGCT vào bảng ĐGCT"
                    .Tag = "ChenDGCT"
                    .FaceId = 78
                End With

menuDuToan_GioiThieu = CType(cmdBarControlDuToan.Controls.Add(Type:=Office.MsoControlType.msoControlButton, Temporary:=True), Office.CommandBarButton)
                With menuDuToan_PhanTichVatTu
                    .Caption = "Giới thiệu về chương trình..."
                    .Tag = "GioiThieuVeChuongTrinh"
                    .FaceId = 250
                End With
                

            End If
        Catch ex As Exception

        End Try
    End Sub
    
    Private Sub Sheet1_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
        CheckIfMenuBarExists()
        'AddMenuBar()
        AddMenuDuToan()
    End Sub

    Private Sub Sheet1_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown

    End Sub

    
Private Sub menuDuToan_TinhChiPhiVanChuyen_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles menuDuToan_TinhChiPhiVanChuyen.Click
        MsgBox("tính chi phí vận chuyển")
    End Sub

Private Sub menuDuToan_TinhChenhLech_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles menuDuToan_TinhChenhLech.Click
        MsgBox("tính chênh lệch")
    End Sub

Private Sub menuDuToan_TinhDonGiaChiTiet_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles menuDuToan_TinhDonGiaChiTiet.Click
        MsgBox("Tính Đơn Giá")
    End Sub

Private Sub menuDuToan_TongHopVatTu_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles menuDuToan_TongHopVatTu.Click
        MsgBox("Tong Hợp Vật Tư")
    End Sub
End Class
 
Chỉnh sửa lần cuối bởi điều hành viên:
To: zazabovn,
Sao mà phức tạp vậy nhỉ? Bạn tìm topic về vấn đề Menu trên diễn đàn. Áp dụng dạng Table-driven thì tốt hơn.

Lê Văn Duyệt
 
Bạn đã sử dụng Visual Basic 2008 thì cần gì viết code cho nó mệt? sử dụng thanh công cụ mà "vẽ" cho nó nhanh!
 
Web KT
Back
Top Bottom