vb.net生成Wince下的图片文字混编工具栏

Imports PictureButtonToolbar.PictureButtonToolbar
Public Class UserControl1
    Inherits System.Windows.Forms.UserControl
    ''' <summary>
    ''' 按钮的单击事件(供平台监听)
    ''' </summary>
    Public Event btnclick(ByVal id As Integer, ByVal AppName As String)
    '工具栏的横竖标志(false为横;true为竖)
    Public HorVerFlag As Boolean = True
    Public Property SetHorVerFlag() As Boolean
        Get
            Return HorVerFlag
        End Get
        Set(ByVal Value As Boolean)
            HorVerFlag = Value
        End Set
    End Property
    '工具栏中按钮的大小
    Public MaxBtnWidth As Integer = 0
    Public MaxBtnHeight As Integer = 0
    '整个控件的大小
    Public CWidth As Integer = 0
    Public CHeight As Integer = 0
    '当前控件中各个子控件的图像和文件的排列格式
    Public CurBtnLayout As Integer = 2
    ''' <summary>
    ''' 根据传入的用户菜单的参数动态创建工具栏按钮
    ''' </summary>
    ''' 生成工具栏
    ''' ListInfo中元素的组成是:菜单名,菜单快捷访问符,父菜单(true时表示为父菜单,false表示为子菜单;只提供两级菜单),父菜单名
    ''' 是否添加到工具栏显示(true为在工具栏中显示),Imagelist对象,Imagelist中的index
    Public Sub CreateToolbar(ByRef ListInfo As List(Of List(Of Object)), ByRef imagelist1 As System.Windows.Forms.ImageList, ByVal PicTextLayout As Integer)
        DisposeToolbar()
        Dim t As Integer = 0
        Dim i As Integer = 0
        CWidth = 0
        CHeight = 0
        MaxBtnWidth = 0
        MaxBtnHeight = 0
        If IsNothing(ListInfo) = False Then
            If ListInfo.Count > 0 Then
                For i = 0 To ListInfo.Count - 1
                    '是否父菜单
                    If CBool(ListInfo.Item(i).Item(3)) = False Then


                        '是否这个子菜单在工具栏上显示;是则生成工具栏
                        If CBool(ListInfo.Item(i).Item(5)) = True Then
                            '创建图片按钮
                            Me.Panel1.Controls.Add(New PictureButtonToolbar.PictureButtonToolbar)
                            '背景色
                            CType(Me.Panel1.Controls.Item(t), PictureButtonToolbar.PictureButtonToolbar).BackColor = System.Drawing.SystemColors.ControlLight
                            '边框样式
                            CType(Me.Panel1.Controls.Item(t), PictureButtonToolbar.PictureButtonToolbar).BorderStyle = Windows.Forms.BorderStyle.None
                            '是否自动适应大小
                            CType(Me.Panel1.Controls.Item(t), PictureButtonToolbar.PictureButtonToolbar).ControlSizeSetF = True
                            '图片按钮的图片文字排版格式
                            CType(Me.Panel1.Controls.Item(t), PictureButtonToolbar.PictureButtonToolbar).TextImageLayout = CType(PicTextLayout, PictureButtonToolbar.PictureButtonToolbar.Layout)
                            '添加图片按钮的图片
                            CType(Me.Panel1.Controls.Item(t), PictureButtonToolbar.PictureButtonToolbar).AddBmp(imagelist1.Images(CType(ListInfo.Item(i).Item(6), Integer)))
                            '记下当前按钮的外接应用程序名
                            CType(Me.Panel1.Controls.Item(t), PictureButtonToolbar.PictureButtonToolbar).SetAppName = ListInfo.Item(i).Item(7).ToString
                            '记下当前图片按钮的菜单号
                            CType(Me.Panel1.Controls.Item(t), PictureButtonToolbar.PictureButtonToolbar).SetTag = CType(ListInfo.Item(i).Item(1), Integer)
                            '按钮文本
                            CType(Me.Panel1.Controls.Item(t), PictureButtonToolbar.PictureButtonToolbar).Caption = CType(ListInfo.Item(i).Item(0), String)
                            '控件索引
                            CType(Me.Panel1.Controls.Item(t), PictureButtonToolbar.PictureButtonToolbar).Text = t.ToString
                            '重绘确定大小
                            CType(Me.Panel1.Controls.Item(t), PictureButtonToolbar.PictureButtonToolbar).RefreshPicBtn()
                            '是否自动适应大小
                            CType(Me.Panel1.Controls.Item(t), PictureButtonToolbar.PictureButtonToolbar).ControlSizeSetF = False
                            '获取最大值,以便于统一所有工具栏上按钮的大小
                            If CType(Me.Panel1.Controls.Item(t), PictureButtonToolbar.PictureButtonToolbar).Width > MaxBtnWidth Then
                                MaxBtnWidth = CType(Me.Panel1.Controls.Item(t), PictureButtonToolbar.PictureButtonToolbar).Width
                            End If
                            If CType(Me.Panel1.Controls.Item(t), PictureButtonToolbar.PictureButtonToolbar).Height > MaxBtnHeight Then
                                MaxBtnHeight = CType(Me.Panel1.Controls.Item(t), PictureButtonToolbar.PictureButtonToolbar).Height
                            End If
                            '绑定单击事件
                            AddHandler CType(Me.Panel1.Controls.Item(t), PictureButtonToolbar.PictureButtonToolbar).Click, AddressOf ActiveEvent
                            t = t + 1
                        End If
                    End If
                Next
                '工具栏背景色
                ' Me.Panel1.BackColor = Me.BackColor
                '工具栏整个的大小
                If HorVerFlag = False Then
                    Me.Width = Me.Panel1.Controls.Count * (MaxBtnWidth + 1) - 1
                    Me.Height = MaxBtnHeight
                Else
                    Me.Width = MaxBtnWidth
                    Me.Height = Me.Panel1.Controls.Count * (MaxBtnHeight + 1) - 1
                End If
                CWidth = Me.Width
                CHeight = Me.Height
                Me.Panel1.Size = New System.Drawing.Size(CWidth, CHeight)
                Me.Panel1.Location = New Point(0, 0)
                For j As Integer = 0 To Me.Panel1.Controls.Count - 1
                    '大小重新设置
                    CType(Me.Panel1.Controls.Item(j), PictureButtonToolbar.PictureButtonToolbar).Size = New System.Drawing.Size(MaxBtnWidth, MaxBtnHeight)
                Next


                '工具栏中控件重新排版
                Dim xzb As Integer = 0
                Dim yzb As Integer = 0
                For k As Integer = 0 To Me.Panel1.Controls.Count - 1
                    If HorVerFlag = False Then
                        CType(Me.Panel1.Controls.Item(k), PictureButtonToolbar.PictureButtonToolbar).Location = New Point(xzb, 0)
                        xzb = (CType(Me.Panel1.Controls.Item(k), PictureButtonToolbar.PictureButtonToolbar).Width + 1) + xzb
                    Else
                        CType(Me.Panel1.Controls.Item(k), PictureButtonToolbar.PictureButtonToolbar).Location = New Point(0, yzb)
                        yzb = (CType(Me.Panel1.Controls.Item(k), PictureButtonToolbar.PictureButtonToolbar).Height + 1) + yzb
                    End If
                Next
            End If
        End If
        Me.Panel1.Refresh()
        Me.CurBtnLayout = PicTextLayout
        Me.Refresh()
    End Sub
    ''' <summary>
    ''' 销毁控件,以便于释放控件占用的资源
    ''' </summary>
    ''' 销毁按钮
    ''' 销毁工具栏
    Public Sub DisposeToolbar()
        For i As Integer = Me.Panel1.Controls.Count - 1 To 0 Step -1
            '销毁
            RemoveHandler CType(Me.Panel1.Controls.Item(i), PictureButtonToolbar.PictureButtonToolbar).Click, AddressOf ActiveEvent
            CType(Me.Panel1.Controls.Item(i), PictureButtonToolbar.PictureButtonToolbar).DisposePictureButton()
            CType(Me.Panel1.Controls.Item(i), PictureButtonToolbar.PictureButtonToolbar).Dispose()
        Next
        Me.Panel1.Controls.Clear()
        Me.Panel1.Refresh()
        Me.Refresh()
    End Sub
    ''' <summary>
    ''' 对此工具栏控件的按下状态进行重置;同时激发按钮的按下自定义事件
    ''' </summary>
    ''' 激发事件处理函数
    Private Sub ActiveEvent(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim PicBtn As PictureButtonToolbar.PictureButtonToolbar
        PicBtn = CType(sender, PictureButtonToolbar.PictureButtonToolbar)
        RaiseEvent btnclick(CInt(PicBtn.Tag), CStr(PicBtn.BtnAppName))
    End Sub
   
    '重新排列工具栏图标
    Public Sub ReLayoutToolBar()
        '工具栏整个的大小
        If HorVerFlag = False Then
            Me.Width = Me.Panel1.Controls.Count * (MaxBtnWidth + 1) - 1
            Me.Height = MaxBtnHeight
        Else
            Me.Width = MaxBtnWidth
            Me.Height = Me.Panel1.Controls.Count * (MaxBtnHeight + 1) - 1
        End If
        CWidth = Me.Width
        CHeight = Me.Height
        Me.Panel1.Size = New System.Drawing.Size(CWidth, CHeight)
        Me.Panel1.Location = New Point(0, 0)
        '工具栏中控件重新排版
        Dim xzb As Integer = 0
        Dim yzb As Integer = 0
        For k As Integer = 0 To Me.Panel1.Controls.Count - 1
            If HorVerFlag = False Then
                CType(Me.Panel1.Controls.Item(k), PictureButtonToolbar.PictureButtonToolbar).Location = New Point(xzb, 0)
                xzb = (CType(Me.Panel1.Controls.Item(k), PictureButtonToolbar.PictureButtonToolbar).Width + 1) + xzb
            Else
                CType(Me.Panel1.Controls.Item(k), PictureButtonToolbar.PictureButtonToolbar).Location = New Point(0, yzb)
                yzb = (CType(Me.Panel1.Controls.Item(k), PictureButtonToolbar.PictureButtonToolbar).Height + 1) + yzb
            End If
        Next
    End Sub
End Class
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VB.Net生成光栅二维码可以使用第三方库,例如ZXing库。以下是使用ZXing库在VB.Net生成光栅二维码的步骤: 1. 首先,需要安装ZXing.Net扩展库。可以使用NuGet包管理器将ZXing.Net库添加到VB.Net项目中。 2. 导入ZXing库的命名空间,在需要生成二维码的代码文件中添加以下代码: ```vb Imports ZXing Imports ZXing.Common Public Sub GenerateQRCode(text As String, filePath As String) ' 创建二维码写入器对象 Dim writer As New BarcodeWriter ' 设置编码格式为QR码 writer.Format = BarcodeFormat.QR_CODE ' 设置二维码大小 writer.Options = New EncodingOptions With {.Width = 300, .Height = 300} ' 创建二维码矩阵 Dim matrix As BitMatrix = writer.Encode(text) ' 将二维码矩阵转换为图片 Dim qrCodeBitmap As New Bitmap(matrix.Width, matrix.Height) For y As Integer = 0 To matrix.Height - 1 For x As Integer = 0 To matrix.Width - 1 qrCodeBitmap.SetPixel(x, y, If(matrix(x, y), Color.Black, Color.White)) Next Next ' 保存二维码图片 qrCodeBitmap.Save(filePath, Imaging.ImageFormat.Png) End Sub ``` 3. 调用以上函数来生成二维码。将需要生成二维码的文本和保存路径传递给该函数即可: ```vb Dim text As String = "Hello World!" Dim filePath As String = "C:\path\to\save\qrcode.png" GenerateQRCode(text, filePath) ``` 以上代码将生成一个宽度和高度为300像素的二维码,保存在指定路径下。可以根据需要调整二维码大小和保存路径。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值