请教自定义控件事件问题~~
不会做控件,真郁闷啊。。。。
想做一个picturebox显示曲线的控件,当中用到paint和mousedown事件,这些事件当中的数据都来自datatable,第一次paint时数据可以显示,但是当active一下,table里面的数据都没有了。并且mousedown事件始终不行。。。。。
Public Class mypic
Inherits System.Windows.Forms.UserControl
Public watertable As New DataTable
Public raintable As New DataTable
''''''''''''''''''''''''''''''
Public Property get_watertable()
Get
Return watertable
End Get
Set(ByVal Value)
watertable = Value
End Set
End Property
Public Property get_raintable()
Get
Return raintable
End Get
Set(ByVal Value)
raintable = Value
End Set
End Property
Public Property get_firstdate()
Get
Return firsttime
End Get
Set(ByVal Value)
firsttime = Value
End Set
End Property
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Dim linepen As New Pen(pic_line, 1)
Dim areapen As New Pen(pic_area, 2)
Dim drawfont As New Font(New FontFamily("宋体"), 8, FontStyle.Regular)
PictureBox1.BackColor = pic_backcolor
e.Graphics.Clear(pic_backcolor)
Dim waterpen As New Pen(pic_water)
Dim x1, x2, y1, y2 As Single
For water_i As Integer = 0 To watertable.Rows.Count - 2
Dim tempdate As Date = watertable.Rows(water_i)(2)
If tempdate.Hour >= 8 Then
x1 = (tempdate.Hour - 8) * p_i + (tempdate.Minute / 5) * p_space + leftheight
If IsDBNull(watertable.Rows(water_i)(3)) = False Then
y1 = (PictureBox1.Height - topheight - buttomheight) - (PictureBox1.Height - topheight - buttomheight) * (watertable.Rows(water_i)(3) - watermin) / (watermax - watermin)
End If
e.Graphics.FillEllipse(New SolidBrush(pic_water), x1, CSng(y1 - 1.5), 2, 2)
If water_i > 0 And x2 <> 0 Then
e.Graphics.DrawLine(waterpen, x1, y1, x2, y2)
End If
x2 = x1
y2 = y1
Else
x1 = (tempdate.Hour) * p_i + (tempdate.Minute / 5) * p_space + leftheight + 16 * p_i
If IsDBNull(watertable.Rows(water_i)(3)) = False Then
y1 = (PictureBox1.Height - topheight - buttomheight) - (PictureBox1.Height - topheight - buttomheight) * (watertable.Rows(water_i)(3) - watermin) / (watermax - watermin)
End If
e.Graphics.FillEllipse(New SolidBrush(pic_water), x1, CSng(y1 - 1.5), 2, 2)
If water_i > 0 And x2 <> 0 Then
e.Graphics.DrawLine(waterpen, x1, y1, x2, y2)
End If
x2 = x1
y2 = y1
End If
Next
End Sub
Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
If e.Button = MouseButtons.Left Then
If watertable.Rows.Count > 0 Then
''''处理事件
End If
end if
End Sub
Private Sub mypic_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If watermax = 0 Then
watermax = 100
End If
If watermin = 0 Then
watermin = 0
End If
If rainmax = 0 Then
rainmax = 100
End If
p_space = (PictureBox1.Width - leftheight - rightheight) / 288
End Sub
Private Sub mypic_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
PictureBox1.Refresh()
End Sub
End Class