Looking for C# Spin Control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stewart Berman

    #1

    Looking for C# Spin Control

    Is there a control equivalent to the old Spin control? The one with two hour heads and an optional
    textbox in the middle? The closest I can find is the NumericUpDown control and it's not the same as
    the Spin control. I just want a sizeable up/down arrow pair.
  • Stefan Hoffmann

    #2
    Re: Looking for C# Spin Control

    hi Stewart,

    Stewart Berman wrote:
    Is there a control equivalent to the old Spin control? The one with two hour heads and an optional
    textbox in the middle? The closest I can find is the NumericUpDown control and it's not the same as
    the Spin control. I just want a sizeable up/down arrow pair.
    You may google for

    c# spin control site:codeprojec t.com

    this gives you some hits.


    mfG
    --stefan <--

    Comment

    • Zhi-Xin Ye [MSFT]

      #3
      RE: Looking for C# Spin Control

      Hello Stewart,

      Thank you for using Microsoft Managed Newsgroup Service, my name is Zhi-Xin
      Ye, it's my pleasure to work with you on this issue.

      You can create an UserControl, put two buttons in it, one on the top and
      the other on the bottom. Handle the Paint event of the buttons and use
      ScrollBarRender er.DrawArrowBut ton() method to draw arrows on the buttons.

      For example:

      ========= Sample code for your information ==============

      public class SpinControl : UserControl
      {
      private Button _UpButton;
      private Button _DownButton;

      //Button status 0:Normal, 1:Pressed; 2:Hot(Mouse Hover)
      private int _UpButtonStatus = 0;
      private int _DownButtonStat us = 0;

      public SpinControl()
      {
      this._UpButton = new Button();
      this._DownButto n = new Button();
      this._UpButton. Paint += new PaintEventHandl er(UpButton_Pai nt);
      this._DownButto n.Paint += new PaintEventHandl er(DownButton_P aint);

      this._UpButton. MouseDown += new
      MouseEventHandl er(_UpButton_Mo useDown);
      this._UpButton. MouseUp += new MouseEventHandl er(_UpButton_Mo useUp);

      this._DownButto n.MouseDown += new
      MouseEventHandl er(_DownButton_ MouseDown);
      this._DownButto n.MouseUp += new
      MouseEventHandl er(_DownButton_ MouseUp);

      this._UpButton. MouseEnter += new EventHandler(_U pButton_MouseEn ter);
      this._DownButto n.MouseEnter += new
      EventHandler(_D ownButton_Mouse Enter);

      this._UpButton. MouseLeave += new EventHandler(_U pButton_MouseLe ave);
      this._DownButto n.MouseLeave += new
      EventHandler(_D ownButton_Mouse Leave);

      this.AjustArrow ButtonSize();
      this.Controls.A dd(this._UpButt on);
      this.Controls.A dd(this._DownBu tton);
      this.Width = 20;
      }

      void _UpButton_Mouse Leave(object sender, EventArgs e)
      {
      _UpButtonStatus = 0;
      }

      void _UpButton_Mouse Up(object sender, MouseEventArgs e)
      {
      _UpButtonStatus = 0;
      }

      void _UpButton_Mouse Down(object sender, MouseEventArgs e)
      {
      _UpButtonStatus = 1;
      }

      void _UpButton_Mouse Enter(object sender, EventArgs e)
      {
      _UpButtonStatus = 2;
      }

      void _DownButton_Mou seUp(object sender, MouseEventArgs e)
      {
      _DownButtonStat us = 0;
      }
      void _DownButton_Mou seLeave(object sender, EventArgs e)
      {
      _DownButtonStat us = 0;

      }
      void _DownButton_Mou seDown(object sender, MouseEventArgs e)
      {
      _DownButtonStat us = 1;
      }
      void _DownButton_Mou seEnter(object sender, EventArgs e)
      {
      _DownButtonStat us = 2;
      }

      protected override void OnResize(EventA rgs e)
      {
      this.AjustArrow ButtonSize();
      base.OnResize(e );
      }

      private void AjustArrowButto nSize()
      {
      this._UpButton. Size = this.Size;
      this._DownButto n.Size = this.Size;
      this._UpButton. Height /= 2;
      this._DownButto n.Height /= 2;
      this._DownButto n.Top = this._UpButton. Bottom;
      }

      void UpButton_Paint( object sender, PaintEventArgs e)
      {
      if (_UpButtonStatu s == 0 )
      {
      ScrollBarRender er.DrawArrowBut ton(e.Graphics,
      this._UpButton. ClientRectangle ,

      System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. UpNormal);
      }
      else if (_UpButtonStatu s == 1)
      {
      ScrollBarRender er.DrawArrowBut ton(e.Graphics,
      this._UpButton. ClientRectangle ,

      System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. UpPressed);
      }
      else
      {
      ScrollBarRender er.DrawArrowBut ton(e.Graphics,
      this._UpButton. ClientRectangle ,

      System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. UpHot);
      }

      }

      void DownButton_Pain t(object sender, PaintEventArgs e)
      {
      if (_DownButtonSta tus == 0)
      {
      ScrollBarRender er.DrawArrowBut ton(e.Graphics,
      this._UpButton. ClientRectangle ,

      System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. DownNormal);
      }
      else if (_DownButtonSta tus == 1)
      {
      ScrollBarRender er.DrawArrowBut ton(e.Graphics,
      this._UpButton. ClientRectangle ,

      System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. DownPressed);
      }
      else
      {
      ScrollBarRender er.DrawArrowBut ton(e.Graphics,
      this._UpButton. ClientRectangle ,

      System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. DownHot);
      }
      }
      }

      =============== ============

      If you have any questions or concerns, please feel free to let me know.

      Sincerely,
      Zhi-Xin Ye
      Microsoft Managed Newsgroup Support Team

      Delighting our customers is our #1 priority. We welcome your comments and
      suggestions about how we can improve the support we provide to you. Please
      feel free to let my manager know what you think of the level of service
      provided. You can send feedback directly to my manager at:
      msdnmg@microsof t.com.

      =============== =============== =============== =====
      Get notification to my posts through email? Please refer to
      http://msdn.microsoft.com/en-us/subs...#notifications.

      Note: MSDN Managed Newsgroup support offering is for non-urgent issues
      where an initial response from the community or a Microsoft Support
      Engineer within 2 business day is acceptable. Please note that each follow
      up response may take approximately 2 business days as the support
      professional working with you may need further investigation to reach the
      most efficient resolution. The offering is not appropriate for situations
      that require urgent, real-time or phone-based interactions. Issues of this
      nature are best handled working with a dedicated Microsoft Support Engineer
      by contacting Microsoft Customer Support Services (CSS) at
      http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
      =============== =============== =============== =====
      This posting is provided "AS IS" with no warranties, and confers no rights.

      Comment

      • Ben Voigt [C++ MVP]

        #4
        Re: Looking for C# Spin Control

        Zhi-Xin Ye [MSFT] wrote:
        Hello Stewart,
        >
        Thank you for using Microsoft Managed Newsgroup Service, my name is
        Zhi-Xin Ye, it's my pleasure to work with you on this issue.
        >
        You can create an UserControl, put two buttons in it, one on the top
        and the other on the bottom. Handle the Paint event of the buttons
        and use ScrollBarRender er.DrawArrowBut ton() method to draw arrows on
        the buttons.
        >
        For example:
        >
        ========= Sample code for your information ==============
        >
        public class SpinControl : UserControl
        {
        private Button _UpButton;
        private Button _DownButton;
        >
        //Button status 0:Normal, 1:Pressed; 2:Hot(Mouse Hover)
        private int _UpButtonStatus = 0;
        private int _DownButtonStat us = 0;
        Why create a new de facto enum type without even naming the constants? You
        already have the System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState
        enum which has exactly what you want, and you can avoid the if statements
        later on.
        >
        public SpinControl()
        {
        this._UpButton = new Button();
        this._DownButto n = new Button();
        this._UpButton. Paint += new PaintEventHandl er(UpButton_Pai nt);
        this._DownButto n.Paint += new
        PaintEventHandl er(DownButton_P aint);
        >
        this._UpButton. MouseDown += new
        MouseEventHandl er(_UpButton_Mo useDown);
        this._UpButton. MouseUp += new
        MouseEventHandl er(_UpButton_Mo useUp);
        >
        this._DownButto n.MouseDown += new
        MouseEventHandl er(_DownButton_ MouseDown);
        this._DownButto n.MouseUp += new
        MouseEventHandl er(_DownButton_ MouseUp);
        >
        this._UpButton. MouseEnter += new
        EventHandler(_U pButton_MouseEn ter);
        this._DownButto n.MouseEnter += new
        EventHandler(_D ownButton_Mouse Enter);
        >
        this._UpButton. MouseLeave += new
        EventHandler(_U pButton_MouseLe ave);
        this._DownButto n.MouseLeave += new
        EventHandler(_D ownButton_Mouse Leave);
        >
        this.AjustArrow ButtonSize();
        this.Controls.A dd(this._UpButt on);
        this.Controls.A dd(this._DownBu tton);
        this.Width = 20;
        }
        >
        void _UpButton_Mouse Leave(object sender, EventArgs e)
        {
        _UpButtonStatus = 0;
        }
        >
        void _UpButton_Mouse Up(object sender, MouseEventArgs e)
        {
        _UpButtonStatus = 0;
        }
        >
        void _UpButton_Mouse Down(object sender, MouseEventArgs e)
        {
        _UpButtonStatus = 1;
        }
        >
        void _UpButton_Mouse Enter(object sender, EventArgs e)
        {
        _UpButtonStatus = 2;
        }
        >
        void _DownButton_Mou seUp(object sender, MouseEventArgs e)
        {
        _DownButtonStat us = 0;
        }
        void _DownButton_Mou seLeave(object sender, EventArgs e)
        {
        _DownButtonStat us = 0;
        >
        }
        void _DownButton_Mou seDown(object sender, MouseEventArgs e)
        {
        _DownButtonStat us = 1;
        }
        void _DownButton_Mou seEnter(object sender, EventArgs e)
        {
        _DownButtonStat us = 2;
        }
        >
        protected override void OnResize(EventA rgs e)
        {
        this.AjustArrow ButtonSize();
        base.OnResize(e );
        }
        >
        private void AjustArrowButto nSize()
        {
        this._UpButton. Size = this.Size;
        this._DownButto n.Size = this.Size;
        this._UpButton. Height /= 2;
        this._DownButto n.Height /= 2;
        this._DownButto n.Top = this._UpButton. Bottom;
        }
        >
        void UpButton_Paint( object sender, PaintEventArgs e)
        {
        if (_UpButtonStatu s == 0 )
        {
        ScrollBarRender er.DrawArrowBut ton(e.Graphics,
        this._UpButton. ClientRectangle ,
        >
        System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. UpNormal);
        }
        else if (_UpButtonStatu s == 1)
        {
        ScrollBarRender er.DrawArrowBut ton(e.Graphics,
        this._UpButton. ClientRectangle ,
        >
        System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. UpPressed);
        }
        else
        {
        ScrollBarRender er.DrawArrowBut ton(e.Graphics,
        this._UpButton. ClientRectangle ,
        >
        System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. UpHot);
        }
        >
        }
        >
        void DownButton_Pain t(object sender, PaintEventArgs e)
        {
        if (_DownButtonSta tus == 0)
        {
        ScrollBarRender er.DrawArrowBut ton(e.Graphics,
        this._UpButton. ClientRectangle ,
        >
        System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. DownNormal);
        }
        else if (_DownButtonSta tus == 1)
        {
        ScrollBarRender er.DrawArrowBut ton(e.Graphics,
        this._UpButton. ClientRectangle ,
        >
        System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. DownPressed);
        }
        else
        {
        ScrollBarRender er.DrawArrowBut ton(e.Graphics,
        this._UpButton. ClientRectangle ,
        >
        System.Windows. Forms.VisualSty les.ScrollBarAr rowButtonState. DownHot);
        }
        }
        }
        >
        =============== ============
        >
        If you have any questions or concerns, please feel free to let me
        know.
        >
        Sincerely,
        Zhi-Xin Ye
        Microsoft Managed Newsgroup Support Team
        >
        Delighting our customers is our #1 priority. We welcome your comments
        and suggestions about how we can improve the support we provide to
        you. Please feel free to let my manager know what you think of the
        level of service provided. You can send feedback directly to my
        manager at: msdnmg@microsof t.com.
        >
        =============== =============== =============== =====
        Get notification to my posts through email? Please refer to
        http://msdn.microsoft.com/en-us/subs...#notifications.
        >
        Note: MSDN Managed Newsgroup support offering is for non-urgent issues
        where an initial response from the community or a Microsoft Support
        Engineer within 2 business day is acceptable. Please note that each
        follow up response may take approximately 2 business days as the
        support professional working with you may need further investigation
        to reach the most efficient resolution. The offering is not
        appropriate for situations that require urgent, real-time or
        phone-based interactions. Issues of this nature are best handled
        working with a dedicated Microsoft Support Engineer by contacting
        Microsoft Customer Support Services (CSS) at
        http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
        =============== =============== =============== =====
        This posting is provided "AS IS" with no warranties, and confers no
        rights.

        Comment

        • Zhi-Xin Ye [MSFT]

          #5
          Re: Looking for C# Spin Control

          Hi Ben,

          You're right, it's more concise to use the ScrollBarArrowB uttonState enum,
          I somehow ignore that.

          public class SpinControl : UserControl
          {
          private Button _UpButton;
          private Button _DownButton;

          private ScrollBarArrowB uttonState _UpButtonStatus ;
          private ScrollBarArrowB uttonState _DownButtonStat us;

          public SpinControl()
          {
          this._UpButton = new Button();
          this._DownButto n = new Button();
          this._UpButton. Paint += new PaintEventHandl er(UpButton_Pai nt);
          this._DownButto n.Paint += new PaintEventHandl er(DownButton_P aint);

          this._UpButton. MouseDown += new
          MouseEventHandl er(_UpButton_Mo useDown);
          this._UpButton. MouseUp += new MouseEventHandl er(_UpButton_Mo useUp);

          this._DownButto n.MouseDown += new
          MouseEventHandl er(_DownButton_ MouseDown);
          this._DownButto n.MouseUp += new
          MouseEventHandl er(_DownButton_ MouseUp);

          this._UpButton. MouseEnter += new EventHandler(_U pButton_MouseEn ter);
          this._DownButto n.MouseEnter += new
          EventHandler(_D ownButton_Mouse Enter);

          this._UpButton. MouseLeave += new EventHandler(_U pButton_MouseLe ave);
          this._DownButto n.MouseLeave += new
          EventHandler(_D ownButton_Mouse Leave);

          this.AjustArrow ButtonSize();
          this.Controls.A dd(this._UpButt on);
          this.Controls.A dd(this._DownBu tton);
          this.Width = 20;
          }

          void _UpButton_Mouse Leave(object sender, EventArgs e)
          {
          _UpButtonStatus = ScrollBarArrowB uttonState.UpNo rmal;
          }

          void _UpButton_Mouse Up(object sender, MouseEventArgs e)
          {
          _UpButtonStatus = ScrollBarArrowB uttonState.UpNo rmal;
          }

          void _UpButton_Mouse Down(object sender, MouseEventArgs e)
          {
          _UpButtonStatus = ScrollBarArrowB uttonState.UpPr essed;
          }

          void _UpButton_Mouse Enter(object sender, EventArgs e)
          {
          _UpButtonStatus = ScrollBarArrowB uttonState.UpHo t;
          }

          void _DownButton_Mou seUp(object sender, MouseEventArgs e)
          {
          _DownButtonStat us = ScrollBarArrowB uttonState.Down Normal;
          }
          void _DownButton_Mou seLeave(object sender, EventArgs e)
          {
          _DownButtonStat us = ScrollBarArrowB uttonState.Down Normal;

          }
          void _DownButton_Mou seDown(object sender, MouseEventArgs e)
          {
          _DownButtonStat us = ScrollBarArrowB uttonState.Down Pressed;
          }
          void _DownButton_Mou seEnter(object sender, EventArgs e)
          {
          _DownButtonStat us = ScrollBarArrowB uttonState.Down Hot;
          }

          protected override void OnResize(EventA rgs e)
          {
          this.AjustArrow ButtonSize();
          base.OnResize(e );
          }

          private void AjustArrowButto nSize()
          {
          this._UpButton. Size = this.Size;
          this._DownButto n.Size = this.Size;
          this._UpButton. Height /= 2;
          this._DownButto n.Height /= 2;
          this._DownButto n.Top = this._UpButton. Bottom;
          }

          void UpButton_Paint( object sender, PaintEventArgs e)
          {
          ScrollBarRender er.DrawArrowBut ton(e.Graphics,
          this._UpButton. ClientRectangle , _UpButtonStatus );
          }

          void DownButton_Pain t(object sender, PaintEventArgs e)
          {
          ScrollBarRender er.DrawArrowBut ton(e.Graphics,
          this._UpButton. ClientRectangle , _DownButtonStat us);
          }
          }


          Sincerely,
          Zhi-Xin Ye
          Microsoft Managed Newsgroup Support Team

          Delighting our customers is our #1 priority. We welcome your comments and
          suggestions about how we can improve the support we provide to you. Please
          feel free to let my manager know what you think of the level of service
          provided. You can send feedback directly to my manager at:
          msdnmg@microsof t.com.

          This posting is provided "AS IS" with no warranties, and confers no rights.

          Comment

          Working...