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 6904433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:03:38+00:00 2026-05-27T08:03:38+00:00

I am working on a custom button class for my XNA game. Consequently I

  • 0

I am working on a custom button class for my XNA game. Consequently I am developing the game in C#.

My button class is very basic, it provides the obligatory events like MouseOver, MouseOut, MouseDown etc… Furthermore it has some public properties which influence the overall appearance like Text, TextAlign, BackgroundColor, TextColor and Font.

Every button can be in 4 different states: Normal, Hovered, Pressed and Inactive. I would like to give the developers of my game the possibility to specify certain “overwrites” which will control the appearance of the button on a “per state basis”.

Unfortunately I can not come up with a fancy solution. Currently I simply create an array which can hold a separate Button instance for every state. Now if the user wants to create an overwrite for lets say the Hovered-state he simply has to create a new Button instance at the corresponding index position of the button array (I used an Enumeration for that mapping which will be cast to a byte value to retrieve the proper index position). Now a user is able to define an overwrite for every possible state<->property combination.

In the draw method I finally check what the currently active state of my button is and draw the proper button instance from my array collection.

This is not a very clean solution though, as it creates a lot of overhead in case I only want to overwrite the TextColor for a single state. I was wondering how this is generally solved in more professional solutions.

Does anyone have a few tips on design patterns which might be useful in that domain? I had problems searching for a solution as I was missing meaningful keywords.

  • 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-27T08:03:38+00:00Added an answer on May 27, 2026 at 8:03 am

    you can try to implement your own settings class

    EDIT

    public class ButtonSettings
    {
      private ButtonSettings parentSettings;
    
      public void ButtonSettings(ButtonSettings parent)
      {
        parentSettings = parent;
        if (parent == null)
        {
          // initialize default values
          TextAlign = TextAlign.Left;
          // ...
        }
      }
    
      private Alignement textAlign = null;
      public Alignement TextAlign
      {
        get { return textAlign != null ? textAlign : (parentSettings != null ? parentSettings.TextAlign : default(Alignement)); };
        set { textAlign = value; };
      }
    
      // do the same as TextAlign ...
      public Color BackgroundColor { get; set; }
      public Color TextColor { get; set; }
      public Font Font { get; set; }
    }
    
    
    public enum ButtonState
    {
      Normal,
      Hovered,
      Pressed
      Inactive
    }
    

    and use it at your button class

    public class CustomButton : Button
    {
      public CustomButton ()
      {
        // initialize your settings
        Normal = new ButtonSettings();
        Hovered = new ButtonSettings(Normal);
        Pressed = new ButtonSettings(Normal);
        Inactive = new ButtonSettings(Normal);
    
        State = ButtonState.Normal;
      }
    
      public ButtonSettings Normal { get; set; }
      public ButtonSettings Hovered { get; set; }
      public ButtonSettings Pressed { get; set; }
      public ButtonSettings Inactive { get; set; }
    
      public ButtonState State { get; set; }
    }
    

    now the user can use your custombutton and change the settings

    hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a user-defined button, this has two custom properties like this:
I am working on adding a custom accessory view, (a button) to a UITableViewCell,
I have a working custom UserNamePasswordValidator that calls into my Oracle DB. This class
I'm working up a custom Xcode template, and I'd like to change the way
I am using a custom class very similar to the Tweet Bot info panels
Currently, I'm working on a simple custom button that uses user supplied images as
I'm working on a custom ServerControl, I've created it like below : [ParseChildren(true), PersistChildren(true)]
I'm working on a custom implementation of UISegmentedControl. I'd like to create a component
I have the following problem / bug: I made a custom button-class (called CustomBlitButton)
I'm working on an app that uses a custom class with other custom classes

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.