本文介绍了.NET中的自定义控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨......
我在制作可自定义控件的电线"时陷入困境,该控件可以连接两个单选按钮(在窗体上),并且能够将第一个单选按钮的值发送到由该控件联合的下一个单选按钮....
plzz help ....
hi....
I am stuck while making a "wire like custom control" which can join two radio button (on a form), And able to send the value of first radio button to the next radio button which is joint by that control....
plzz help....
推荐答案
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Data
Imports System.Text
Imports System.Windows.Forms
Public Class RadioButtonPair
Inherits UserControl
Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Private Sub InitializeComponent()
Me.RadioButton1 = New System.Windows.Forms.RadioButton
Me.RadioButton2 = New System.Windows.Forms.RadioButton
Me.Label1 = New System.Windows.Forms.Label
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.GroupBox2 = New System.Windows.Forms.GroupBox
Me.GroupBox1.SuspendLayout()
Me.GroupBox2.SuspendLayout()
Me.SuspendLayout()
'
'RadioButton1
'
Me.RadioButton1.AutoSize = True
Me.RadioButton1.Location = New System.Drawing.Point(5, 10)
Me.RadioButton1.Name = "RadioButton1"
Me.RadioButton1.Size = New System.Drawing.Size(14, 13)
Me.RadioButton1.TabIndex = 0
Me.RadioButton1.TabStop = True
Me.RadioButton1.UseVisualStyleBackColor = True
'
'RadioButton2
'
Me.RadioButton2.AutoSize = True
Me.RadioButton2.Location = New System.Drawing.Point(5, 11)
Me.RadioButton2.Name = "RadioButton2"
Me.RadioButton2.Size = New System.Drawing.Size(14, 13)
Me.RadioButton2.TabIndex = 1
Me.RadioButton2.TabStop = True
Me.RadioButton2.UseVisualStyleBackColor = True
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(23, 11)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(64, 13)
Me.Label1.TabIndex = 2
Me.Label1.Text = "-------------------"
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.RadioButton1)
Me.GroupBox1.Location = New System.Drawing.Point(4, 2)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(22, 27)
Me.GroupBox1.TabIndex = 3
Me.GroupBox1.TabStop = False
'
'GroupBox2
'
Me.GroupBox2.Controls.Add(Me.RadioButton2)
Me.GroupBox2.Location = New System.Drawing.Point(80, 2)
Me.GroupBox2.Name = "GroupBox2"
Me.GroupBox2.Size = New System.Drawing.Size(22, 29)
Me.GroupBox2.TabIndex = 4
Me.GroupBox2.TabStop = False
'
'RadioButtonPair
'
Me.Controls.Add(Me.GroupBox2)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.Label1)
Me.Name = "RadioButtonPair"
Me.Size = New System.Drawing.Size(115, 35)
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox1.PerformLayout()
Me.GroupBox2.ResumeLayout(False)
Me.GroupBox2.PerformLayout()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Public Sub New()
InitializeComponent()
AddHandler Me.Click, AddressOf RadioButton_Cecked
AddHandler Me.Label1.Click, AddressOf RadioButton_Cecked
End Sub
Private Sub RadioButton_Cecked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If RadioButton1.Checked = True Then
RadioButton1.Checked = False
RadioButton2.Checked = False
Else
RadioButton1.Checked = True
RadioButton2.Checked = True
End If
End Sub
End Class
希望对您有帮助.如果是,那么给5分.
I hope it will help you.If so then give 5Points.
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
RadioButton2.Checked = true;
changeCustomControl();
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
RadioButton1.Checked = true;
changeCustomControl();
}
protected void changeCustomControl()
{
//Put code to change the custom control here
}
还请记住,单选按钮的GroupName属性必须不同,否则不能同时检查它们.
希望这会有所帮助!
-Erlend
Also remember that the GroupName property of the radio buttons has to differ or else they cannot both be checked at the same time.
Hope this helps!
-Erlend
这篇关于.NET中的自定义控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!