Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 641775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:05:57+00:00 2026-05-13T21:05:57+00:00

the Text property of control on winform is always string type, so if i

  • 0

the Text property of control on winform is always string type, so if i wanna expose property of other type for custom control, i have to do the conversion as following, if i have dozens of properties to expose, it will be such pain for me.

  public int ImageGroupLength
    {
        get
        {
            return int.Parse(this.imageGroupLength.Text);
        }
        set
        {
            this.imageGroupLength.Text = value.ToString();
        }
    }

so, is there any elegant way to do the conversion?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:05:58+00:00Added an answer on May 13, 2026 at 9:05 pm

    Creating your own control is the way to go here. Add a new class to your project and paste the code shown below. Compile. The new control shows up on the top of your toolbox. You’ll want to implement the BadValue event to warn the user that the entered text isn’t suitable. And the ValueChanged is available to get an event when the Value property changes.

    using System;
    using System.Windows.Forms;
    
    class ValueBox : TextBox {
      public event EventHandler BadValue;
      public event EventHandler ValueChanged;
    
      private int mValue;
      public int Value {
        get { return mValue; }
        set {
          if (value != mValue) {
            mValue = value;
            OnValueChanged(EventArgs.Empty);
            base.Text = mValue.ToString();
          }
        }
      }
      protected void OnValueChanged(EventArgs e) {
        EventHandler handler = ValueChanged;
        if (handler != null) handler(this, e);
      }
      protected void OnBadValue(EventArgs e) {
        EventHandler handler = BadValue;
        if (handler != null) handler(this, e);
      }
      protected override void OnHandleCreated(EventArgs e) {
        base.OnHandleCreated(e);
        base.Text = mValue.ToString();
      }
      protected override void OnValidating(System.ComponentModel.CancelEventArgs e) {
        int value;
        if (!int.TryParse(base.Text, out value)) {
          SelectionStart = 0;
          SelectionLength = base.Text.Length;
          e.Cancel = true;
          OnBadValue(EventArgs.Empty);
        }
        else base.OnValidating(e);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know which property sets the text color for disabled control? I have
how to set text property assigned to the control created dynamically usiong reflection? Type
I have a TextBlock control and I am declaratively setting the Text property to
I have a custom user control and have overridden its Font property. When I
How can I update a textbox or label (specfically an asp.net control) text property
Is there a way to set the .Text property of the Wpf ComboBox control
I wanted to create a control with a TextBox and to bind TextBox.Text property
The TextBox control offers a MaxLength property, which allows the insertable text into that
I have a textbox with the Text property bound to a dataset column with
I have to compare 2 values which are the text property of 2 textbox

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.