2

I have designed the circular button list in web application using a jquery plugin and html. In this design user at a time select one day only like radio button list. The design is shown below:

enter image description here

How can I implement the the same design and functionality in windows form? Please help me, from where I am going to started to achieve this one.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
GOPAL YADAV
  • 1,181
  • 2
  • 9
  • 18

3 Answers3

7

There are multiple options to perform this in windows forms. As an option you can start with customizing RadioButton and Panel controls. You can create a new class derived from Panel and a new class derived from RadioButton, then override OnPaint method of those classes and draw the desired presentation.

Here is the result of a sample implementation which I shared in this post:

enter image description here

Custom Panel

public class MyPanel : Panel
{
    public MyPanel()
    {
        this.Padding = new Padding(2);
    }
    protected override void OnPaint(PaintEventArgs e)
    {
        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
        using (var path = new GraphicsPath())
        {
            var d = this.Padding.All;
            var r = this.Height - 2 * d;
            path.AddArc(d, d, r, r, 90, 180);
            path.AddArc(this.Width - r - d, d, r, r, -90, 180);
            path.CloseFigure();
            using (var pen = new Pen(Color.Silver, d))
                e.Graphics.DrawPath(pen, path);
        }
    }
}

Custom Radio Button

public class MyRadioButton : RadioButton
{
    public MyRadioButton()
    {
        this.Appearance = System.Windows.Forms.Appearance.Button;
        this.BackColor = Color.Transparent;
        this.TextAlign = ContentAlignment.MiddleCenter;
        this.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
        this.FlatAppearance.BorderColor = Color.RoyalBlue;
        this.FlatAppearance.BorderSize = 2;
    }
    protected override void OnPaint(PaintEventArgs e)
    {
        this.OnPaintBackground(e);
        using (var path = new GraphicsPath())
        {
            var c = e.Graphics.ClipBounds;
            var r = this.ClientRectangle;
            r.Inflate(-FlatAppearance.BorderSize, -FlatAppearance.BorderSize);
            path.AddEllipse(r);
            e.Graphics.SetClip(path);
            base.OnPaint(e);
            e.Graphics.SetClip(c);
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            if (this.Checked)
            {
                using (var p = new Pen(FlatAppearance.BorderColor, 
                                       FlatAppearance.BorderSize))
                {
                    e.Graphics.DrawEllipse(p, r);
                }
            }
        }
    }
}

Required usings

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • @Phani Thank you, it's not perfect, but it's a good start point :) – Reza Aghaei Jul 15 '16 at 07:32
  • hi @Reza Aghaei, thank u so much.its working awesome. – GOPAL YADAV Jul 15 '16 at 07:38
  • hi @Reza Aghaei, we getting yash color when mouseover to the circle. i want yashcolor to circle during button click only.can u suggest me. – GOPAL YADAV Jul 15 '16 at 07:40
  • You're welcome :) If I understand your question correctly, if you don't need highlight color on mouse over, you can set `FlatAppearace.MouseOverBackColor` to `Color.Transparent`. This way it's better to set the `Cursor` to `Cursors.Hand` to let the user know when the mouse is over the radio button. – Reza Aghaei Jul 15 '16 at 07:45
  • hi @RezaAghaei, thank u once again, if i have any doubt please suggest me. – GOPAL YADAV Jul 15 '16 at 07:51
  • hi @RezaAghaei, hi have one more doubt like this can we implement toogle switch cotrol like the shown in below link http://www.jqueryscript.net/demo/Material-Design-Toggle-Switch-Plugin-with-jQuery-ToggleSwitch/. is it possible can u suggest me. – GOPAL YADAV Jul 16 '16 at 06:26
  • Everything is possible, for example you can use the same techniques used in this answer to draw circular shapes for a checkbox. You can do it in Windows Forms the same way this answer created round radio buttons. But probably using WPF and Universal Windows Apps is a better option. – Reza Aghaei Jul 16 '16 at 11:20
  • Take a look at [Toggle Switches](https://msdn.microsoft.com/en-us/windows/uwp/controls-and-patterns/toggles) or read more about [Universal Windows App Components](https://msdn.microsoft.com/en-us/windows/uwp/controls-and-patterns/index). – Reza Aghaei Jul 16 '16 at 11:22
  • Another important note is such questions requesting the whole code for a component is off-topic in stackoverflow and users should write their codes and if they had a problem in code ask their question. Usually you get downvote for such questions and your question will be closed if you ask for such questions. Such users will be considered as [Help Vampires](http://meta.stackoverflow.com/questions/258206/what-is-a-help-vampire) which is not acceptable. – Reza Aghaei Jul 16 '16 at 11:27
  • Another important note, it's better to use only a single user in site. Take a look at this post for more information: [What's the policy about having multiple user accounts?](http://meta.stackexchange.com/questions/35593/whats-the-policy-about-having-multiple-user-accounts) I hope my comments help you to use site better and help you to receive high quality answers from users :) – Reza Aghaei Jul 16 '16 at 11:32
  • Ask a new question containing a code, a MyCheckBox which derived from CheckBox and try to draw the round background like I did in MyPanel control. And ask what is the problem now and what is the goal. Then I'll post an answer for you :) – Reza Aghaei Jul 16 '16 at 12:05
  • hi @RezaAghaei thank u so much for urs suggestion.i can do the same wt u say. – GOPAL YADAV Jul 17 '16 at 09:05
  • You're welcome, let me know if you asked a new question about that. – Reza Aghaei Jul 17 '16 at 19:31
  • hi @RezaAghaei, here is my question http://stackoverflow.com/questions/38431674/unable-to-getting-the-toggle-switch-functionality-in-winforms. – GOPAL YADAV Jul 18 '16 at 08:15
  • hi @RezaAghaei, how are u, i am urs follower,i have one doubt in Windows services in .net. can u help me. – GOPAL YADAV Aug 18 '16 at 09:12
  • hi @RezaAghaei, can u sugget me sir ,for completing my task related to windows service. – GOPAL YADAV Aug 18 '16 at 10:03
  • Hi @GOPALYADAV I took a look at the new question and unfortunately I had no idea about the solution. – Reza Aghaei Aug 18 '16 at 10:41
  • hi @RezaAghaei, here is my question link – GOPAL YADAV Aug 18 '16 at 10:43
  • hi @RezaAghaei,here is my question http://stackoverflow.com/questions/39014736/windows-service-doesnt-run-at-regular-intervals?noredirect=1#comment65380515_39014736, if u have any answer, suggest me please. – GOPAL YADAV Aug 18 '16 at 10:44
  • No need to the link. I found [it](http://stackoverflow.com/questions/39014736/windows-service-doesnt-run-at-regular-intervals) at top of list of your questions. As I said, unfortunately I have no idea about the solution, hope other users help you to find the solution :) – Reza Aghaei Aug 18 '16 at 10:44
0

Hii Gopal you can achive this functionality using custom control.Goodluck please refer these links

  1. How to customize Button Control like this one?

  2. https://msdn.microsoft.com/en-us/library/h4te2zh2(v=vs.90).aspx

  3. How do I create button with rounded corners/edges on Winform C#?

Community
  • 1
  • 1
Lier
  • 308
  • 3
  • 16
-1

You can start with a list view or list box Change the item template as a button and add style to your button as you need. Make the selection mode of the list view as Single.

Joseph
  • 1,054
  • 1
  • 11
  • 25
  • Windows Forms ListView or ListBox doesn't have such `ItemTemplate` property. – Reza Aghaei Jul 14 '16 at 19:53
  • hi @Reza Aghaei, i want this in winform. – GOPAL YADAV Jul 15 '16 at 04:49
  • I don't really think this is possible with winforms listview. – Joseph Jul 15 '16 at 05:15
  • hi @Joseph is it possible in wpf – GOPAL YADAV Jul 15 '16 at 07:03
  • @ Gopal obviously you can do that in wpf.You have the flexibility to edit the item template and control template of listview, this way you can achieve this.Try with my answer. – Joseph Jul 15 '16 at 07:16
  • @Joseph While I believe it's completely possible in WPF too, but I edited the tags based on OP comment and removed WPF. I hope it's not the reason for downvoter and hope it doesn't make a misunderstanding :) I posted a WinForms answer, hope you find it useful. – Reza Aghaei Jul 15 '16 at 08:21