读书人

写自制控件控件求教多谢!

发布时间: 2012-03-31 13:13:26 作者: rapoo

写自制控件控件求教各位高手,谢谢!!!
我想做一个图控件,调用时(有以下几个简单属性:1:能够改变背景色 2:改变控件大小时,里面图也改变大小 3:能改变里面绘制图的颜色 4:当鼠标移到上面时,能有提示(自定义提示能容))
请高手们给与帮助,谢谢!!!

VB.NET code
Public Class FM    Dim Controlvalve As Bitmap    Private Sub FM_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        Pi1.BackColor = Me.BackColor        Drawimge()    End Sub    Private Sub Drawimge()        Controlvalve = New Bitmap(Pi1.Width, Pi1.Height)        Using G As Graphics = Graphics.FromImage(Controlvalve)            Dim myColor As Color            Dim mPen As New Pen(myColor)            mPen.Color = Color.Red            mPen.Width = 2            Dim p1 As New Point(Pi1.Width * 0.01, Pi1.Height * 0.4)            Dim p2 As New Point(Pi1.Width * 0.01, Pi1.Height * 0.98)            Dim p3 As New Point(Pi1.Width * 0.98, Pi1.Height * 0.4)            Dim p4 As New Point(Pi1.Width * 0.98, Pi1.Height * 0.98)            Dim ps As Point() = {p1, p2, p3, p4}            G.DrawPolygon(mPen, ps)            G.DrawLine(mPen, CInt(Pi1.Width * 0.5), CInt(Pi1.Height * 0.3), CInt(Pi1.Width * 0.5), CInt(Pi1.Height * 0.69))            G.DrawLine(mPen, CInt(Pi1.Width * 0.2), CInt(Pi1.Height * 0.3), CInt(Pi1.Width * 0.8), CInt(Pi1.Height * 0.3))            Dim rect1 As New Rectangle(CInt(Pi1.Width * 0.2), CInt(Pi1.Height * 0.05), CInt(Pi1.Width * 0.6), CInt(Pi1.Height * 0.3))            G.DrawArc(mPen, rect1, 0, -180)            '   G.FillPolygon()            Pi1.Image = Controlvalve        End Using        Pi1.Refresh()    End Sub    Private Sub FM_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove        Drawimge()End Sub    End Class



[解决办法]
这样,画图,很耗资源的。
要分开来。那些是固定的。那些是经常变动的。分开几个部分。
[解决办法]
fm.loaction=new point( me.with* 0.3 ,me.height*0.3)
设置控件的位置。坐标x,y。
[解决办法]
已很多控件,而且功能都很大
[解决办法]
Me.Invalidate()
Me.Refresh()
都是会重绘啊。

读书人网 >VB Dotnet

热点推荐