廣告廣告
  加入我的最愛 設為首頁 風格修改
首頁 首尾
 手機版   訂閱   地圖  簡體 
您是第 9047 個閱讀者
 
發表文章 發表投票 回覆文章
  可列印版   加為IE收藏   收藏主題   上一主題 | 下一主題   
a894985459
個人文章 個人相簿 個人日記 個人地圖
路人甲
級別: 路人甲 該用戶目前不上站
推文 x0 鮮花 x1
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片
推文 x0
[Basic][求助] VB2008 Button外觀 以及一些問題
如題 有沒有一些檔案或者是教學
可以改變Button的外觀 ..

訪客只能看到部份內容,免費 加入會員 或由臉書 Google 可以看到全部內容



獻花 x0 回到頂端 [樓 主] From:臺灣凱擘股份有限公司 | Posted:2013-02-14 20:20 |
ebolaman 手機 會員卡
個人文章 個人相簿 個人日記 個人地圖
特殊貢獻獎

級別: 副版主 該用戶目前不上站
版區: 程式設計
推文 x38 鮮花 x458
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

1.
.Net 的 Button 預設就是長那樣,也改不了到哪去
想要做不規則形的按鈕,或是圖片的按鈕,可以自己製作一個 Class 或 Usercontrol

參考 MSDN http://msdn.microsoft.com/en-us/l...(v=vs.90).aspx

這是我做的範例 UserControl: 一個簡單的圓型按鈕 (用 G D I + 畫的,沒有 PictureBox)

完整的專案 在附件

建立一個 .Net 3.5 專案,再新增一個 UserControl 取名 CustomButton.vb
代碼如下

先編譯過後,工具列才會出現 CustomButton 可加入到 Form1 表單



複製程式
Imports System.Windows
Imports System.Drawing.Drawing2D


Public Class CustomButton


    Private pow2 As Func(Of Double, Double) =
        Function(a As Double) As Double
            Return a * a
        End Function


    Private m_mouseOn As Boolean = False
    Private m_mouseDown As Boolean = False




    Private Property _MouseOn As Boolean
        Get
            Return m_mouseOn
        End Get
        Set(ByVal value As Boolean)
            If value <> m_mouseOn Then
                m_mouseOn = value
                ' redraw
                Me.Invalidate()
                Me.Update()
                ' cursor
                If m_mouseOn Then
                    Me.Cursor = Cursors.Hand
                Else
                    Me.Cursor = Cursors.Default
                End If
            Else
                m_mouseOn = value
            End If
        End Set
    End Property


    Private Property _MouseDown As Boolean
        Get
            Return m_mouseDown
        End Get
        Set(ByVal value As Boolean)
            If value <> m_mouseDown Then
                m_mouseDown = value
                ' redraw
                Me.Invalidate()
                Me.Update()
            Else
                m_mouseDown = value
            End If
        End Set
    End Property




    Private Sub Form_Load() Handles MyBase.Load
        'Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or
        '            ControlStyles.UserPaint Or
        '            ControlStyles.OptimizedDoubleBuffer Or
        '            ControlStyles.ResizeRedraw, True)
    End Sub


    Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
        Me.Size = New Size(101, 101)


        MyBase.OnResize(e)
    End Sub


    Protected Overrides Sub OnPaint(ByVal e As Forms.PaintEventArgs)
        Dim rect As New Rectangle(1, 1, 98, 98)
        Dim img As New Bitmap(Me.DisplayRectangle.Width,
                              Me.DisplayRectangle.Height)
        Dim gImg As Graphics = Graphics.FromImage(img)


        ' set smoothing mode
        gImg.SmoothingMode = SmoothingMode.HighQuality


        ' fill background
        Using b As New SolidBrush(Me.BackColor)
            gImg.FillRectangle(b, rect)
        End Using


        ' is mouse down?
        If m_mouseDown Then
            If m_mouseOn Then
                Using b As New SolidBrush(Color.Green)
                    gImg.FillEllipse(b, rect)
                End Using
            End If
        Else
            ' is mouse on?
            If m_mouseOn Then
                Using b As New SolidBrush(Color.LawnGreen)
                    gImg.FillEllipse(b, rect)
                End Using
            End If
        End If


        ' draw button border
        Using p As New Pen(Brushes.Black, 2)
            gImg.DrawEllipse(p, rect)
        End Using


        ' draw text
        Using f As New Font(SystemFonts.DefaultFont.FontFamily,
                            16.0F, FontStyle.Bold)
            Dim s As String = "ABC"
            Dim fSize As Size = gImg.MeasureString(s, f).ToSize


            gImg.DrawString(s, f,
                            Brushes.Black,
                            49 - fSize.Width \ 2,
                            49 - fSize.Height \ 2)
        End Using


        ' draw image
        e.Graphics.DrawImage(img, 0, 0)


        ' dispose
        img.Dispose()
        gImg.Dispose()


        MyBase.OnPaint(e)
    End Sub


    Protected Overrides Sub OnMouseMove(ByVal e As Forms.MouseEventArgs)
        Dim vecX As Double = CDbl(e.X) - 50.0
        Dim vecY As Double = CDbl(e.Y) - 50.0


        If Math.Sqrt(pow2(vecX) + pow2(vecY)) <= 50.0 Then
            _MouseOn = True
        Else
            _MouseOn = False
        End If


        MyBase.OnMouseMove(e)
    End Sub


    Protected Overrides Sub OnMouseDown(ByVal e As Forms.MouseEventArgs)
        If m_mouseOn Then
            _MouseDown = True
        End If


        MyBase.OnMouseDown(e)
    End Sub


    Protected Overrides Sub OnMouseUp(ByVal e As Forms.MouseEventArgs)
        _MouseDown = False


        MyBase.OnMouseUp(e)
    End Sub


    Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
        _MouseOn = False


        MyBase.OnMouseLeave(e)
    End Sub


End Class






2.
就我所知有 3 種方法讀取 DLL:
a. 專案屬性 -> References ,使用時用 Imports,最簡單的方法 (只限 Managed dlls)
b. DllImport, 有很多 PInvoke functions 可用
c. Assembly.LoadFrom("<file name>") 讀取一個 dll file

.net 甚至還可以從網路上下載 dll 來載入表單,達到自動更新的效果

3.
ini 檔網路上有些 讀取 ini 檔的 class
或是用 API GetPrivateProfileString, WritePrivateProfileString
或是自己寫一個 class,其實不難,簡單的 ini 格式都可以手動讀取

.net 大部分格式偏向 xml (.net 有內建 XML parser),我個人比較喜愛的是 json
不管哪種格式,網路上都有一大堆 class 來幫助你輕鬆 讀取/寫入


本帖包含附件
zip WindowsApplication1.rar   (2022-06-09 14:21 / 73 KB)   下載次數:0


[ 此文章被ebolaman在2013-08-07 22:54重新編輯 ]


My BOINC stats :

獻花 x0 回到頂端 [1 樓] From:台灣寬頻通訊顧問股份有限公司 | Posted:2013-08-07 22:37 |

首頁  發表文章 發表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.023127 second(s),query:16 Gzip disabled
本站由 瀛睿律師事務所 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言