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

  • Home
  • SEARCH
  • 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 7158019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T12:59:30+00:00 2026-05-28T12:59:30+00:00

I have my own control: public class newControl : Control { } There is

  • 0

I have my own control:

public class newControl : Control
{
}

There is a Text property, but there is not a TextAlign property. For example, I need this property similar to the TextAlign property of a Button, but I don’t want inherit it from a button class.

So can I inherit only TextAlign property? If yes, how?

  • 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-28T12:59:31+00:00Added an answer on May 28, 2026 at 12:59 pm

    Yes, you can just add it. The built in enumeration is called ContentAlignment:

    using System.ComponentModel;
    using System.Windows.Forms;
    
    public class newControl : Control {
    
      private ContentAlignment _TextAlign = ContentAlignment.MiddleCenter;
    
      [Description("The alignment of the text that will be displayed on the control.")]
      [DefaultValue(typeof(ContentAlignment), "MiddleCenter")]
      public ContentAlignment TextAlign {
        get { return _TextAlign; }
        set { _TextAlign = value; }
      }
    }
    

    What you do with this property is up to you now.

    Note that I added some attributes for how the control is used in the PropertyGrid. The DefaultValue attribute does not set the value of the property, it just determines whether or not the property is displayed in bold or not.

    To display the text using your TextAlign property, you would have to override the OnPaint method and draw it:

    protected override void OnPaint(PaintEventArgs e) {
      switch (_TextAlign) {
        case ContentAlignment.MiddleCenter: {
            TextRenderer.DrawText(e.Graphics, this.Text, this.Font, this.ClientRectangle, this.ForeColor, Color.Empty, 
                                  TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
            break;
          }
        case ContentAlignment.MiddleLeft: {
            TextRenderer.DrawText(e.Graphics, this.Text, this.Font, this.ClientRectangle, this.ForeColor, Color.Empty,
                                  TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
            break;
          }
        // more case statements here for all alignments, etc.
    
      }
      base.OnPaint(e);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently using System.Web.UI.WebControls.FileUpload wrapped in our own control. We have licenses for Telerik. I
I am trying to make my own user control and have almost finished it,
I'm trying to hide window after its startup. I have own window-class which is
I have my own game engine using C++ and OpenGL, but I have models
I have my own asp.net cookie created like this: var authTicket = new FormsAuthenticationTicket(
I have implemented my own usercontrol based on listboxes. It has a dependency property
I have a single spring bean similar to the following: public class MyServiceImpl {
This is probably a lark, but for the recaptcha control as it sometimes takes
This is a rather simple question, I have a base class which implements common
In C#, if you have multiple constructors, you can do something like this: public

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.