vs制作自定义控件有关问题
vs制作自定义控件问题

public void Init(int count)
参数count表示把长方形分为count个小长方形或者是count个小长方形合并为一个整体(分成count个小长方形在书写过程碰到一个划线的问题)
public void SetColor(int index, Color color, string name)
参数index表示索引,当索引到index时,选中的小长方形编程color颜色,并居中显示name
利用GDI+,请大牛来指导一下。
------解决方案--------------------
你难道不是循环画图么
在循环里,判断i==index,就填充并画文字,就行了啊
到底哪里不会?
------解决方案--------------------
给你简单写一个,没有怎么封装属性
public void Init(int count)
参数count表示把长方形分为count个小长方形或者是count个小长方形合并为一个整体(分成count个小长方形在书写过程碰到一个划线的问题)
public void SetColor(int index, Color color, string name)
参数index表示索引,当索引到index时,选中的小长方形编程color颜色,并居中显示name
利用GDI+,请大牛来指导一下。
------解决方案--------------------
你难道不是循环画图么
在循环里,判断i==index,就填充并画文字,就行了啊
到底哪里不会?
------解决方案--------------------
给你简单写一个,没有怎么封装属性
Public Class UserControl1
Inherits UserControl
Private _count As Integer = 4
Private _name As String
Private _index As Integer = 0
Private _color As Color = Color.Red
Sub New()
SetStyle(ControlStyles.AllPaintingInWmPaint + ControlStyles.OptimizedDoubleBuffer + ControlStyles.ResizeRedraw, True)
InitializeComponent()
End Sub
Property Count As Integer
Get
Return _count
End Get
Set(ByVal value As Integer)
_count = value
Me.Invalidate()
End Set
End Property
Public Sub test()
If _index = Count - 1 Then
_index = 0
Else
_index += 1
End If
Me.Invalidate()
End Sub
Public Sub Init(ByVal count As Integer)
Me.Count = count
End Sub
Public Sub SetColor(ByVal index As Integer, ByVal color As Color, ByVal name As String)
_name = name
_index = index
_color = color
Me.Invalidate()
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
Dim g As Graphics = e.Graphics
'计算方格宽度
Dim h As Integer
Dim w As Integer
If Count = 0 Then
w = Width
Else
w = Me.Width / Count
End If
h = Height
'绘制背景
Using sb As New SolidBrush(Color.White)
g.FillRectangle(sb, 0, 0, Width, Height)
End Using
'划分单元格
Dim pn As New Pen(Color.Black)
Dim verdanaFont As Font = New Font("Verdana", 10, FontStyle.Bold)
Dim strFormat1 As New StringFormat
With strFormat1
.Alignment = StringAlignment.Center
.LineAlignment = StringAlignment.Center
End With
For i As Integer = 0 To Count - 1
Dim pt1 As New Point(i * w, 0)
Dim pt2 As New Point(i * w, h)