Click here to Skip to main content
15,918,976 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi
It makes me crazy but I am working on this about one week and I could not achieved.
I have a class and this class has lots of boolean.

Ex: public bool1,
public bool2 etc.

Now I want to create a custom radio button with custom property.
In this custom property area I will chose one of the boolean of my class from dropdown list. After that If boolean is true, radio button will be checked.

I work on WindowsForm.
How can I do that?

What I have tried:

A screenshot what I need : example — Postimage.org[^]
Posted
Updated 30-Oct-16 3:58am
v4
Comments
Richard Deeming 28-Oct-16 12:00pm    
Were you planning on telling us which of the many UI frameworks you're using?
(Windows Forms, WPF, ASP.NET WebForms, ASP.NET MVC, ASP.NET Core, Xamarin, etc.)

They all have their own version of a RadioButton, and the process for writing a custom control will be totally different for each.
tebdilikiyafet 28-Oct-16 12:12pm    
Oh so sorry. I work on WindowsForm and using VisualStudio.
[no name] 28-Oct-16 13:05pm    
"I need an example code for this", gimme code is not a question. What I think you want to do from your convoluted description is called data binding.
tebdilikiyafet 29-Oct-16 7:35am    
How can I do that?
Is it a question? I said that I worked on this for one week. If I have a clue about how can it be, I would ask about this.
Ralf Meier 29-Oct-16 8:09am    
I don't understood your requirement.
Perhaps you should explain your control (that you want to create), it's property (or properties) and what should happen with them.
Also a Screenshot or some more code could be useful.
I'm very familiar with customizing controls but with your description I don't know what to do ...

1 solution

Of course you have to implement its own Checked/Unchecked Boolean Property in a custom Control, in this case a RadioButton. But the Checked Property must be implemented inside your custom UserControl not on different class.
You then can choose to use a Radibutton within your MyRadiButton control that derives from UserControl or you would do it using System.Drawing methods to paint a circle and draw text indicating the Text Property. This all is too difficult for a novice but you may find an example on Web.

Here is some code to start with:

VB.NET
Public Class MyRadioButton : Inherits UserControl

Private _Checked As Boolean
Property Checked As Boolean
 Get : Return _Checked : End Get
 Set(value As Boolean) 
   _Checked = value 
   EnableDisable(New PaintEventArgs(Me.CreateGraphics)) 
 End Set
End Property


Sub New()
  '//
End Sub

Protected Sub EnableDisable(e As PaintEventArgs)
   If Checked Then
    'e.graphics.fillellipse(draw/fill a circle)
   Else
    'e.graphics.drawellipse(draw circle)
   End If
   'e.graphics.drawstring(draw string of Me.Text Property)
End Sub

Protected Overrides Sub OnPaint(e As PaintEventArgs)
    EnableDisable(e)
End Sub
End Class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900