引用 | 编辑
a894985459
2013-02-14 20:20 |
楼主
▼ |
||
|
引用 | 编辑
ebolaman
2013-08-07 22:37 |
1楼
▲ |
||||||||||
1.
.Net 的 Button 预设就是长那样,也改不了到哪去 想要做不规则形的按钮,或是图片的按钮,可以自己制作一个 Class 或 Usercontrol 参考 MSDN http://msdn.microsoft.com/en-us/library/ms172532(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 来帮助你轻松 读取/写入
x0 |