• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 492
  • Last Modified:

How to make a self-made Control visible

Hello experts!

I have a Windows Forms application with a number of screen masks, having a menu comprised of buttons at the bottom. Whenever a button is pressed, it becomes inactive and the corresponding menu is opened. Each menu displayed with the screen mask (always full screen) corresponds to one of the menu buttons.

This C# .NET Framework 4.0 WinForms application is my first C# & .NET project. I use Microsoft Visual Studio 2010.

I created this design by having a so-called BaseForm : Form, from which the real screen masks are derived. The BaseForm had in it's original form a GroupBox with all the Button's as the so-called ButtonMenu, but I now decided to put the ButtonMenu into a separate class having it's own controls. So, what I want to do is to make out of a ButtonMenu class that was controlling the buttons in the BaseForm a separate class that gives its instance as a singleton. I decided to use a singleton, as I want that all screen masks have one and the same ButtonMenu to access.

The code compiles, but I have obviously missed something:

Question
What should I do to get the ButtonMenu visible after adding it to the BaseForm?

Please note that I was creating my screen masks by hand before. This time, I add the ButtonMenu that is created on run-time to the BaseForm.

Below, you can see parts of the code...

Thank you for your reply!
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Threading;
using System.Windows.Forms;
using Thyripol;

namespace Thyripol
{
    public class BaseForm : Form
    {
	 […]

        /// <summary>
        ///     Menu object
        /// </summary>
        protected static ButtonMenu m_ButtonMenu = null;
        /// <summary>
        ///     Currently active culture.
        /// </summary>
        protected static Culture.ORDER m_CurrentCulture = Culture.ORDER.NONE;
	 […]
        /// <summary>
        ///     Font used for the header line
        /// </summary>
        protected Font m_LargeFont = null;
        /// <summary>
        ///     Font used for text fields
        /// </summary>
        protected Font m_NormalFont = null;
        /// <summary>
        ///     Font used for text fields
        /// </summary>
        protected Font m_SmallFont = null;
 	 […]

        /// <summary>
        ///     Standard constructor
        /// </summary>
        public BaseForm()
        {
            m_CurrentCulture = Culture.ORDER.de_DE;

            m_LargeFont = new Font("Arial", 12f, FontStyle.Bold);
            m_NormalFont = new Font("Arial", 10f, FontStyle.Bold);
            m_SmallFont = new Font("Arial", 8f, FontStyle.Bold | FontStyle.Italic);

            InitializeComponent();		// Generated by Microsoft Visual Studio 2010

	     […]

            InitializeWidgets();
        }
	 [...]

        /// <summary>
        ///     Initialises all widget elements.
        ///     See also: UpdateWidgets()
        /// </summary>
        protected virtual void InitializeWidgets()
        {
            const string strMETHOD = "BaseForm:InitializeWidgets: ";
            Rectangle rectangle = new Rectangle(Location, Size);

            m_ButtonMenu = ButtonMenu.GetInstance(m_CurrentCulture, ml_Culture,
                pictureBoxBase, rectangle);

            this.SuspendLayout();
            this.Controls.Add(m_ButtonMenu);
            this.ResumeLayout();

            try
            {
                m_ButtonMenu.SetCountryFlag(
                    ReadImage(ml_Culture[(int)m_CurrentCulture].FlagFileName));
                m_ButtonMenu.Deactivate(Tuple.LABEL.MENU_01);
                    m_ButtonMenu.ActivateAll();
            }
            catch (ArgumentOutOfRangeException aaore)
            {
                MessageBox.Show(strMETHOD + "argument-out-of-range exception: " + aaore);
                throw aaore;
            }
            catch (NullReferenceException nre)
            {
                MessageBox.Show(strMETHOD + "null-reference exception: " + nre);
                throw nre;
            }
            catch (Exception ex)
            {
                MessageBox.Show(strMETHOD + "unexpected exception: " + ex);
                throw ex;
            }

            // Format all the texts in this screen mask:
            FormatTextWidgets();
	     [...]
        }

	 [...]
    }
}

Open in new window

0
Ahmet Ekrem SABAN
Asked:
Ahmet Ekrem SABAN
  • 9
  • 5
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Is line #67 setting the size and position of your control?

If so, try adding some debugging output to make sure those values make sense:

    Console.WriteLine("rectangle = " + rectangle.ToString());

You may want to use the Load() or Shown() event of the Form instead of the constructor.
0
 
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Yes, line 67 is getting the Location and Size of the control. I corrected it. Thank you!

You write "instead of the constructor". Which constructor do you mean? The ButtonMenu has only a visible GetInstance() method.
protected virtual void InitializeWidgets()
        {
            const string strMETHOD = "BaseForm:InitializeWidgets: ";
            Point buttonMenuLocation = Location;
            Size buttonMenuSize = Size;

            buttonMenuSize.Height /= 10;

            buttonMenuLocation.Y = Size.Height - buttonMenuSize.Height;

            Rectangle rectangle = new Rectangle(buttonMenuLocation, buttonMenuSize);

            m_ButtonMenu = ButtonMenu.GetInstance(m_CurrentCulture,
                ml_Culture, pictureBoxBase, rectangle);

            this.SuspendLayout();
            this.Controls.Add(m_ButtonMenu);
            this.ResumeLayout();
            […]
        }

Open in new window

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You're using the Constructor of the Form:

    public partial class BaseForm : Form
    {
        public BaseForm()
        {
            // This is the Default Constructor
            InitializeComponent();
        }

        private void BaseForm_Load(object sender, EventArgs e)
        {
            // The Load() Event (wired up thru the IDE)
        }

        private void BaseForm_Shown(object sender, EventArgs e)
        {
            // The Shown() Event (wired up thru the IDE)
        }

    }
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Yes, I added both methods and to the event handler of the form. But to be honest, I do not know how I can make the button menu visible. I checked the location. It is at (0, 0). So, it should appear at the top left, but nothing happens. Obviously, I have to add some additional code.
private void InitializeComponent()
        {
            [...]
            this.Load += new EventHandler(BaseForm_Load);
            this.Shown += new EventHandler(BaseForm_Shown);
            [...]
        }

        private void BaseForm_Load(object sender, EventArgs eas)
        {
            m_ButtonMenu.Visible = true;
        }

        private void BaseForm_Shown(object sender, EventArgs eas)
        {
            ;// The Shown() Event (wired up thru the IDE)
        }

Open in new window

0
 
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
I recently took notice of a warning that appears with my code. It is something like "Cannot access the discarded object. Object name: ButtonMenu." (originally in German:
"Auf das verworfene Objekt kann nicht zugegriffen werden. Objektname: ButtonMenu".)

This warning comes during compile time, but it is not located in any file (see image).
Warnung--verworfenes-Objekt.PNG
0
 
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
To find out the reason of the warning, I commented all lines with ButtonMenu in the project. The warning continued. Then, I removed the ButtonMenu class from the project. Still, the warning persisted. I removed at last the file, closed and reopened the project. This time, the warning did not appear.

Then, I added the ButtonMenu class again to the project and recompiled. Then, I removed line by line the comments from the commented lines and recompiled each time. The warning never returned. But still the menu is invisible.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
What if you start with a new project and a blank form, and then add ButtonMenu?
0
 
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
I tried that a few days ago, but I cannot see anything either.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Can you post the code for ButtonMenu so I can test it in a bare bones project?
0
 
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
OK, here you go! Some classes are needed, which I also partly simplified...

ButtonMenu:
 
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Thyripol
{
    public class ButtonMenu : Control
    {
        ///// <summary>
        /////     Button for the administration menu
        /////     (MENU_08).
        ///// </summary>
        //private Button btnAdministration = null;
        ///// <summary>
        /////     Button for the analogue menu
        /////     (MENU_03).
        ///// </summary>
        //private Button btnAnalogue = null;
        ///// <summary>
        /////     Button for the culture menu that
        /////     switches from one culture to another
        /////     (MENU_09).
        ///// </summary>
        //private Button btnCulture = null;
        ///// <summary>
        /////     Button for the messages menu
        /////     (MENU_07).
        ///// </summary>
        //private Button btnMessages = null;
        ///// <summary>
        /////     Button for the SFC menu
        /////     (MENU_04).
        ///// </summary>
        //private Button btnPQ = null;
        ///// <summary>
        /////     Button for the Q/cos f menu
        /////     (MENU_05).
        ///// </summary>
        //private Button btnQCosPhi = null;
        ///// <summary>
        /////     Button for the P-Q menu
        /////     (MENU_06).
        ///// </summary>
        //private Button btnSFC = null;
        /// <summary>
        ///     Button for the start menu
        ///     (MENU_01).
        /// </summary>
        private Button btnStart = null;
        ///// <summary>
        /////     Button for the trend menu
        /////     (MENU_06).
        ///// </summary>
        //private Button btnTrend = null;
        ///// <summary>
        /////     Button for the values menu
        /////     (MENU_02).
        ///// </summary>
        //private Button btnValues = null;
        /// <summary>
        ///     Current culture
        /// </summary>
        private Culture.TYPE m_CurrentCulture;
        /// <summary>
        ///     Group box for all the menu buttons.
        /// </summary>
        private GroupBox m_GroupBox = null;
        /// <summary>
        ///     The only ButtonMenu that can exist in the project.
        /// </summary>
        private static ButtonMenu m_ButtonMenu = null;
        /// <summary>
        ///     All the cultures used in this project.
        /// </summary>
        private static List<Culture> ml_Culture = new List<Culture>();

        public enum MENU
        {
            NR01, NR02, NR03, NR04, NR05,
            NR06, NR07, NR08, NR09, NR10
        }

        /// <summary>
        ///     Constructor of the so-called button menu that
        ///     is nothing but a wrapping class around the 
        ///     GroupBox that holds the real button menu that 
        ///     is part of the BaseForm.
        /// </summary>
        /// <param name="groupBox">
        ///     Group box containing the menu buttons.
        /// </param>
        /// <param name="l_Culture">
        ///     List of cultures
        /// </param>
        /// <param name="culture">
        ///     Current selected culture
        /// </param>
        private ButtonMenu(Culture.TYPE culture,
            List<Culture> l_Culture, Rectangle rectangle)
        {
            m_CurrentCulture = culture;
            ml_Culture = l_Culture;

            InitializeComponent();

            SetLocation(rectangle.Location);
            SetHeight(rectangle.Height);
            SetWidth(rectangle.Width);

            AdaptButtons(culture, l_Culture);
        }

        /// <summary>
        ///     Factory method for the only ButtonMenu.
        /// </summary>
        /// <param name="culture">
        ///     Current culture
        /// </param>
        /// <param name="l_Culture">
        ///     Information about all cultures.
        /// </param>
        /// <param name="pictureBox">
        ///     PictoreBox instance where the ButtonMenu is to be placed.
        /// </param>
        /// <param name="rectangle">
        ///     Location and size information for this menu.
        /// </param>
        /// <returns>
        ///     The only ButtonMenu instance.
        /// </returns>
        public static ButtonMenu GetInstance(Culture.TYPE culture,
            List<Culture> l_Culture, PictureBox pictureBox, Rectangle rectangle)
        {
            if (m_ButtonMenu == null)
                m_ButtonMenu = new ButtonMenu(culture, l_Culture, rectangle);

            m_ButtonMenu.GetGroupBox().Location = rectangle.Location;
            m_ButtonMenu.GetGroupBox().Size = rectangle.Size;
            m_ButtonMenu.Visible = true;

            return m_ButtonMenu;
        }

        /// <summary>
        ///     Is called when the Culture button is clicked on.
        ///     This is the button that opens MENU_09.
        /// </summary>
        /// <param name="sender">
        ///     Sender object requested by the event.
        /// <param name="eas">
        ///     <c>EventArgs</c> is the second argument requested by the event.
        /// </param>
        private void btnCulture_Click(object sender, EventArgs eas)
        {
            SwitchCulture();

            //DetermineResourceManager();

            AdaptButtons(m_CurrentCulture, ml_Culture);
        }

        /// <summary>
        ///     Determines what happens when this button is clicked.
        ///     This is the button that opens MENU_01.
        /// </summary>
        /// <param name="sender">
        ///     Sending object
        /// </param>
        /// <param name="eas">
        ///     Event information
        /// </param>
        private void btnStart_Click(object sender, EventArgs eas)
        {
            Deactivate(Tuple.LABEL.MENU_01);
            Forms.startForm.ShowDialog();
            ActivateAll();
        }

        /// <summary>
        ///     Initialises all components
        /// </summary>
        private void InitializeComponent()
        {
            this.btnStart = new System.Windows.Forms.Button();
            //this.btnValues = new System.Windows.Forms.Button();
            //this.btnAnalogue = new System.Windows.Forms.Button();
            //this.btnSFC = new System.Windows.Forms.Button();
            //this.btnPQ = new System.Windows.Forms.Button();
            //this.btnQCosPhi = new System.Windows.Forms.Button();
            //this.btnTrend = new System.Windows.Forms.Button();
            //this.btnMessages = new System.Windows.Forms.Button();
            //this.btnAdministration = new System.Windows.Forms.Button();
            //this.btnCulture = new System.Windows.Forms.Button();
            this.m_GroupBox = new System.Windows.Forms.GroupBox();

            this.m_GroupBox.SuspendLayout();
            //((System.ComponentModel.ISupportInitialize)(pictureBox)).BeginInit();
            //this.SuspendLayout();
            // 
            // m_GroupBox
            // 
            this.m_GroupBox.Controls.Add(this.btnStart);
            this.m_GroupBox.Location = new System.Drawing.Point(0, 664);
            this.m_GroupBox.Name = "m_GroupBox";
            this.m_GroupBox.Size = new System.Drawing.Size(1273, 68);
            this.m_GroupBox.TabIndex = 12;
            this.m_GroupBox.TabStop = false;

            this.m_GroupBox.ResumeLayout(false);

            // 
            // btnStart
            // 
            this.btnStart.ImeMode = System.Windows.Forms.ImeMode.NoControl;
            this.btnStart.Location = new System.Drawing.Point(22, 19);
            this.btnStart.Name = "btnStart";
            this.btnStart.Size = new System.Drawing.Size(100, 40);
            this.btnStart.TabIndex = 0;
            this.btnStart.Text = "Start";
            this.btnStart.UseVisualStyleBackColor = true;
            this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
        }

        /// <summary>
        ///     Modified handling of the return key.
        /// </summary>
        //protected virtual void OnPressReturnKey()
        //{
        //    EventArgs eas = new EventArgs();

        //    if (ActiveControl == this.btnValues)
        //        btnValues_Click(this, eas);
        //    else if (ActiveControl == this.btnTrend)
        //        btnTrend_Click(this, eas);
        //}

        /// <summary>
        ///     Switches from one culture to another in the preset (CULTURE_ID alphabetic) order.
        /// </summary>
        protected void SwitchCulture()
        {
            if ((int)++m_CurrentCulture >= ml_Culture.Count)
                m_CurrentCulture = Culture.TYPE.ar_SA;

            //UpdateWidgets();
        }

        /// <summary>
        ///     Adapts the button text to current culture.
        /// </summary>
        /// <param name="culture">
        ///     Current culture order number
        /// </param>
        /// <param name="l_Culture">
        ///     Culture information
        /// </param>
        public void AdaptButtons(Culture.TYPE culture, List<Culture> l_Culture)
        {
            for (ushort usButton = 0; usButton < m_GroupBox.Controls.Count; usButton++)
            {
                Button button = (Button) m_GroupBox.Controls[usButton];

                // Define button texts according to current culture:
                switch (button.Name)
                {
                    case "btnAdministration":   // 9th button
                        button.Text = l_Culture[(int)culture].GetMenu(ButtonMenu.MENU.NR09);
                        break;
                    case "btnAnalogue":         // 3rd button
                        button.Text = l_Culture[(int)culture].GetMenu(ButtonMenu.MENU.NR03);
                        break;
                    case "btnCulture":          // 10th button
                        button.Text = l_Culture[(int)culture].GetCountryCode();
                        break;
                    case "btnMessages":         // 8th button
                        button.Text = l_Culture[(int)culture].GetMenu(ButtonMenu.MENU.NR08);
                        break;
                    case "btnPQ":               // 6th button
                        button.Text = l_Culture[(int)culture].RealPowerSymbol +
                            Constants.m_cDASH + l_Culture[(int)culture].ReactivePowerSymbol;
                        break;
                    case "btnQCosPhi":          // 5th button
                        button.Text = l_Culture[(int)culture].ReactivePowerSymbol +
                            Constants.m_cSLASH + l_Culture[(int)culture].CosPhi;
                        break;
                    case "btnSFC":              // 4th button
                        button.Text = l_Culture[(int)culture].GetMenu(ButtonMenu.MENU.NR04);
                        break;
                    case "btnStart":            // 1st button
                        button.Text = l_Culture[(int)culture].GetMenu(ButtonMenu.MENU.NR01);
                        break;
                    case "btnTrend":            // 7th button
                        button.Text = l_Culture[(int)culture].GetMenu(ButtonMenu.MENU.NR07);
                        break;
                    case "btnValues":           // 2nd button
                        button.Text = l_Culture[(int)culture].GetMenu(ButtonMenu.MENU.NR02);
                        break;
                    default:                    // Unknown button
                        Exception e = new Exception("unexpected button encountered");

                        throw e;
                }
            }
        }

        /// <summary>
        ///     Getter for the visibility of the menu.
        /// </summary>
        /// <returns>
        ///     Returns current visibility state.
        /// </returns>
        public bool GetVisibility()
        {
            return m_GroupBox.Visible;
        }

        /// <summary>
        ///     Getter for the height of the menu.
        /// </summary>
        /// <returns>
        ///     Current height of the menu
        /// </returns>
        public int GetHeight()
        {
            return m_GroupBox.Height;
        }

        /// <summary>
        ///     Getter for the width of the menu.
        /// </summary>
        /// <returns>
        ///     Current width of the menu
        /// </returns>
        public int GetWidth()
        {
            return m_GroupBox.Width;
        }

        /// <summary>
        ///     Color of active menu
        /// </summary>
        public static Color GetActiveColor()
        {
            return Color.LightGray;
        }

        /// <summary>
        ///     Color of inactive menu
        /// </summary>
        public static Color GetInactiveColor()
        {
            return Color.Yellow;
        }

        /// <summary>
        ///     Indexer for the ButtonMenu.
        /// </summary>
        /// <param name="usIndex">
        ///     Requested elements index
        /// </param>
        /// <returns>
        ///     The requested button.
        /// </returns>
        public Button this[ushort usIndex]
        {
            get { return (Button) m_GroupBox.Controls[usIndex]; }
        }

        /// <summary>
        ///     Activates a menu.
        /// </summary>
        public void ActivateAll()
        {
            // The button menu consists of buttons inside a group box:
            for (ushort usMenu = 0; usMenu < m_GroupBox.Controls.Count; usMenu++)
            {
                m_GroupBox.Controls[usMenu].BackColor = GetActiveColor();
                m_GroupBox.Controls[usMenu].Enabled = true;
            }
        }

        /// <summary>
        ///     Dectivates a menu.
        /// </summary>
        /// <param name="menu">
        ///     This menu will be deactivated.
        /// </param>
        public void Deactivate(Tuple.LABEL menu)
        {
            // The button menu consists of buttons inside a group box:
            for (ushort usMenu = 0; usMenu < m_GroupBox.Controls.Count; usMenu++)
            {
                ushort us = DetermineMenuNumber(menu);

                if (usMenu != DetermineMenuNumber(menu) - 1)
                {
                    m_GroupBox.Controls[usMenu].BackColor = GetActiveColor();
                    m_GroupBox.Controls[usMenu].Enabled = true;
                }
                else
                {
                    m_GroupBox.Controls[usMenu].BackColor = GetInactiveColor();
                    m_GroupBox.Controls[usMenu].Enabled = false;
                }
            }
        }

        /// <summary>
        ///     Determines the order number of the menu.
        /// </summary>
        /// <param name="menu">
        ///     Menu to be scrutinized
        /// </param>
        /// <returns>
        ///     Returns the menu order number
        /// </returns>
        private ushort DetermineMenuNumber(Tuple.LABEL menu)
        {
            string str = menu.ToString();

            return (ushort) Convert.ToInt16(
                str.Substring(str.IndexOf(Constants.m_cUNDERSCORE) + 1, 2));
        }

        /// <summary>
        ///     Setter for the country flag image
        /// </summary>
        /// <param name="countryFlag">
        ///     The image with the country flag
        /// </param>
        public void SetCountryFlag(Image countryFlag)
        {
            //btnCulture.Image = countryFlag;
        }

        /// <summary>
        ///     Places the menu at its default location.
        /// </summary>
        /// <param name="iHeigtOfForm">
        ///     Height of the calling form.
        /// </param>
        public void SetDefaultLocation(int iHeigtOfForm)
        {
            Point topLeftPoint = new Point(0, (int)(.95*iHeigtOfForm));

            m_GroupBox.Location = topLeftPoint;
        }

        /// <summary>
        ///     Setter for the height property of the menu.
        /// </summary>
        /// <param name="iHeight">
        ///     New height of the menu.
        /// </param>
        public void SetHeight(int iHeight)
        {
            m_GroupBox.Height = iHeight;
        }

        /// <summary>
        ///     Setter for the menu location on the screen
        /// </summary>
        /// <param name="topLeftPoint">
        ///     The new top-left point of the menu.
        /// </param>
        public void SetLocation(Point topLeftPoint)
        {
            m_GroupBox.Location = topLeftPoint;
        }

        /// <summary>
        ///     Setter method for the visibility.
        /// </summary>
        /// <param name="bIsVisible">
        ///     New visibility state.
        /// </param>
        public void SetVisibility(bool bIsVisible)
        {
            m_GroupBox.Visible = bIsVisible;
        }

        /// <summary>
        ///     Setter for the width property of the menu.
        /// </summary>
        /// <param name="iWidth">
        ///     New width of the menu.
        /// </param>
        public void SetWidth(int iWidth)
        {
            m_GroupBox.Width = iWidth;
        }

        /// <summary>
        ///     Getter for the group box that holds all menu buttons.
        /// </summary>
        /// <returns>
        ///     The group box
        /// </returns>
        public GroupBox GetGroupBox()
        {
            return m_GroupBox;
        }
    }
}

Open in new window

Constants
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace Thyripol
{
    public static class Constants
    {
        public static char m_cBLANK = ' ';
        public static char m_cCOMMA = ',';
        public static char m_cDASH = '-';
        public static char m_cPERCENT = '%';
        public static char m_cPOINT = '.';
        public static char m_cSLASH = '/';
        public static char m_cUNDERSCORE = '_';
        /// <summary>
        /// Maximal top2bottom value on the Y axis (A, V, VA, ...)
        /// </summary>
        public const float m_fEXTREMUM_Y = 20000;
        /// <summary>
        ///     Maximum float value
        /// </summary>
        public const float m_fMAXIMUM = (float)3.402823e38;
        /// <summary>
        ///     Minimum float value
        /// </summary>
        public const float m_fMINIMUM = -m_fMAXIMUM;
        /// <summary>
        ///     The signals file name.
        /// </summary>
        public const string m_strSIGNALS_FILE_NAME = "Signals.csv";
        /// <summary>
        ///     The signal info file name.
        /// </summary>
        public const string m_strSIGNAL_INFO_FILE_NAME = "Signal info.csv";
        /// <summary>
        ///     Used physical units
        /// </summary>
        public enum UNIT
        {
            AMPERE,
            CAPACITIVE,
            COS_PHI,
            HERTZ,
            INDUCTIVE,
            KILO_AMPERE,
            KILO_VOLT,
            MEGAVOLTAMPERE,
            MEGAWATT,
            MEGAVOLTAMPERE_REACTIVE,
            MILLISECOND,
            PERCENT,
            PERCENT_CAPACITIVE,
            PERCENT_INDUCTIVE,
            SECOND,
            VOLT
        }
        /// <summary>
        ///     The culture order information initialised to "NONE".
        /// </summary>
        //public static Culture.TYPE m_CurrentCulture = Culture.TYPE.NONE;
        /// <summary>
        ///     The default culture is en-GB (English, United Kingdom)
        /// </summary>
        //public static Culture.TYPE m_DefaultCulture = Culture.TYPE.en_GB;

        /// <summary>
        /// Trims all spaces inside and outside the string.
        /// </summary>
        /// <param name="str">
        /// String to be cleansed of spaces.
        /// </param>
        /// <returns>
        /// str without any spaces.
        /// </returns>
        public static string TrimAll(string str)
        {
            int iIndex = -1;
            StringBuilder trimmed = new StringBuilder(str.Trim());

            while ((iIndex = trimmed.ToString().IndexOf(Constants.m_cBLANK)) >= 0)
                trimmed.Remove(iIndex, 1);

            return trimmed.ToString();
        }
    }
}

Open in new window


Culture:
 
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;

namespace Thyripol
{
    public class Culture
    {
        /// <summary>
        ///     Defined order of the cultures
        /// </summary>
        public enum TYPE
        {
            NONE = -1, ar_SA, de_DE, en_GB, no, sv_SE, tr, zh_CN
        };

        /// <summary>
        ///     The words "absolute value"
        /// </summary>
        private string m_strAbsoluteValues = null;

        /// <summary>
        ///     Abbreviation for the automatic state
        /// </summary>
        private string m_strAutoAVR = null;
        /// <summary>
        ///     The word "automatic"
        /// </summary>
        private string m_strAutomaticState = null;
        /// <summary>
        ///     Initialism for the automatic state
        /// </summary>
        private string m_strAVR = null;

        private string m_strCapacitiveUnit = null;
        /// <summary>
        ///     Caption of the menu.
        /// </summary>
        private string m_strCaption = null;
        /// <summary>
        ///     The word "channel"
        /// </summary>
        private string m_strChannel = null;
        /// <summary>
        ///     The words "channel changeover"
        /// </summary>
        private string m_strChannelChangeover = null;
        /// <summary>
        ///     The words "changeover blocking"
        /// </summary>
        private string m_strChangeoverBlocking = null;
        /// <summary>
        ///     The words "collective fault"
        /// </summary>
        private string m_strCollectiveFault = null;
        /// <summary>
        ///     The words "cos f"
        /// </summary>
        private string m_strCosPhi = null;
        /// <summary>
        ///     English name of the country.
        /// </summary>
        private string m_strCountry = null;

        private string m_strCurrentSymbol = null;
        /// <summary>
        ///     Initialism for the manual state
        /// </summary>
        private string m_strECR = null;
        /// <summary>
        ///     The word "excitation"
        /// </summary>
        private string m_strExcitation = null;
        /// <summary>
        ///     The words "excitation current"
        /// </summary>
        private string m_strExcitationCurrent = null;

        /// <summary>
        ///     Name of the file containing the flag of this country.
        /// </summary>
        private string m_strFlagFileName = null;

        private string m_strExcitationCurrentSymbol = null;
        /// <summary>
        ///     The words "generator circuit breake off"
        /// </summary>
        private string m_strGeneratorCircuitBreakerOff = null;
        /// <summary>
        ///     The words "generator circuit breake on"
        /// </summary>
        private string m_strGeneratorCircuitBreakerOn = null;
        /// <summary>
        ///     The words "generator revolution greater than
        ///     90 %" of the nominal value.
        /// </summary>
        private string m_strGeneratorRevolutionGT90 = null;
        /// <summary>
        ///     The words "generator revolution less than or
        ///     equal to 90 %" of the nominal value.
        /// </summary>
        private string m_strGeneratorRevolutionLE90 = null;

        private string m_strGeneratorSymbol = null;
        /// <summary>
        ///     The words "generation voltage"
        /// </summary>
        private string m_strGeneratorVoltage = null;

        private string m_strInductiveUnit = null;
        /// <summary>
        ///     The words "is switched off"
        /// </summary>
        private string m_strIsSwitchedOff = null;
        /// <summary>
        ///     The words "is switched on"
        /// </summary>
        private string m_strIsSwitchedOn = null;
        /// <summary>
        ///     Language spoken in this culture.
        /// </summary>
        private string m_strLanguage = null;
        /// <summary>
        ///     The words "limiter active"
        /// </summary>
        private string m_strLimiterActive = null;
        /// <summary>
        ///     The words "limiter inactive"
        /// </summary>
        private string m_strLimiterInactive = null;

        /// <summary>
        ///     The word "manual"
        /// </summary>
        private string m_strManualECR = null;
        /// <summary>
        ///     The word "manual"
        /// </summary>
        private string m_strManualState = null;
        /// <summary>
        ///     Start menu.
        /// </summary>
        private string[] ma_strMenu = new string[10];
        ///// <summary>
        /////     Start menu.
        ///// </summary>
        //private string m_strMenu01 = null;
        ///// <summary>
        /////     Values menu.
        ///// </summary>
        //private string m_strMenu02 = null;
        ///// <summary>
        /////     Analogue gadgets menu.
        ///// </summary>
        //private string m_strMenu03 = null;
        ///// <summary>
        /////     SFC menu.
        ///// </summary>
        //private string m_strMenu04 = null;
        ///// <summary>
        /////     Q/cos f menu.
        /////     Combination of "ReactivePowerSymbol", a slash, and "cos f".
        ///// </summary>
        ////private string m_strMenu05 = null;
        ///// <summary>
        /////     P-Q menu.
        /////     Combination of "RealPowerSymbol", a dash, and "ReactivePowerSymbol"
        ///// </summary>
        ////private string m_strMenu06 = null;
        ///// <summary>
        /////     Trend menu.
        ///// </summary>
        //private string m_strMenu07 = null;
        ///// <summary>
        /////     Messages menu.
        ///// </summary>
        //private string m_strMenu08 = null;
        ///// <summary>
        /////     Administration menu.
        ///// </summary>
        //private string m_strMenu09 = null;

        private string m_strMessageInfoCaption = null;
        /// <summary>
        ///     The words "no collective fault"
        /// </summary>
        private string m_strNoCollectiveFault = null;

        private string m_strNominalValueSymbol = null;
        /// <summary>
        ///     The words "no redundancy"
        /// </summary>
        private string m_strNoRedundancy = null;
        /// <summary>
        ///     The words "nominal value"
        /// </summary>
        private string m_strNominalValue = null;
        /// <summary>
        ///     The words "reference setter"
        /// </summary>
        private string m_strReferenceSetter = null;
        /// <summary>
        ///     The words "not ready to switch on"
        /// </summary>
        private string m_strNotReady2SwitchOn = null;
        /// <summary>
        ///     The word switch "off"
        /// </summary>
        private string m_strOff = null;
        /// <summary>
        ///     The word switch "on"
        /// </summary>
        private string m_strOn = null;
        /// <summary>
        ///     The words "percent value"
        /// </summary>
        private string m_strPercentValues = null;
        /// <summary>
        ///     The words "protection off"
        /// </summary>
        private string m_strProtectionOff = null;
        /// <summary>
        ///     The words "protection on"
        /// </summary>
        private string m_strProtectionOn = null;
        /// <summary>
        ///     Initialism for "Power Stability System"
        /// </summary>
        private string m_strPSS = null;
        /// <summary>
        ///     Parameter of reactive power
        /// </summary>
        private string m_strReactivePowerSymbol = null;
        /// <summary>
        ///     The words "ready to switch on"
        /// </summary>
        private string m_strReady2SwitchOn = null;
        /// <summary>
        ///     Parameter of active power
        /// </summary>
        private string m_strRealPowerSymbol = null;
        /// <summary>
        ///     The words "real value"
        /// </summary>
        private string m_strRealValue = null;

        private string m_strRealValueSymbol = null;
        /// <summary>
        ///     The words "redundancy exists"
        /// </summary>
        private string m_strRedundancyExists = null;
        /// <summary>
        ///     The words "scope local"
        /// </summary>
        private string m_strScopeLocal = null;
        /// <summary>
        ///     The words "scope remote"
        /// </summary>
        private string m_strScopeRemote = null;
        /// <summary>
        ///     Screen header of each form.
        /// </summary>
        private string m_strScreenHeader = null;
        /// <summary>
        ///     Name of the element for the list boxes 
        ///     of the selection menu. Elements 01-20
        /// </summary>
        private string[] ma_strSource = new string[21];
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_01 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_02 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_03 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_04 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_05 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_06 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_07 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_08 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_09 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_10 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_11 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_12 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_13 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_14 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_15 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_16 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_17 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_18 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_19 = null;
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //private string m_strSource_20 = null;

        /// <summary>
        ///     Text of the source elements list box.
        /// </summary>
        private string m_strSourceListBox = null;
        /// <summary>
        ///     Text of the target elements list box.
        /// </summary>
        private string m_strTargetListBox = null;

        private string m_strVoltageSymbol = null;
        /// <summary>
        ///     International identification of the l_m_Culture,
        ///     consisting of two-character abbreviations of 
        ///     the language and the country, separated by a dash.
        /// </summary>
        private TYPE m_CultureID = TYPE.NONE;

        /// <summary>
        ///     Constructor
        /// </summary>
        /// <param name="strCultureID">
        ///     Identification of the culture.
        /// </param>
        public Culture(string strCultureID)
        {
            m_CultureID = GetCultureID(strCultureID);
            //m_strMenuName = new string[m_usORDER_ELEMENTS];
        }

        /// <summary>
        ///     Getter for the culture-specific decimal point
        /// </summary>
        /// <param name="cultureID">
        ///     Culture identification
        /// </param>
        /// <returns>
        ///     The decimal point or its culture-equivalent
        /// </returns>
        public static char GetDecimalPoint(TYPE cultureID)
        {
            if (cultureID == TYPE.de_DE)
                return Constants.m_cCOMMA;
            else
                return Constants.m_cPOINT;
        }

        /// <summary>
        ///     Converts the TYPE to the international language identifier.
        /// </summary>
        /// <param name="cultureID">
        ///     Culture of which the international language identifier is requested.
        /// </param>
        /// <returns>
        ///     The language identifier.
        /// </returns>
        public static string GetCultureID(TYPE cultureID)
        {
            return cultureID.ToString().Replace(Constants.m_cUNDERSCORE, Constants.m_cDASH);
        }

        /// <summary>
        ///     Getter for the international language identifier.
        /// </summary>
        /// <returns>
        ///     The language identifier.
        /// </returns>
        public string GetLanguageID()
        {
            short sStart = (short) m_CultureID.ToString().IndexOf(Constants.m_cUNDERSCORE);

            return (sStart >= 0) ? m_CultureID.ToString().Substring(0, sStart)
                                 : m_CultureID.ToString().Substring(0, 2);
        }

        /// <summary>
        ///     Returns current timestamp.
        /// </summary>
        /// <returns>
        ///     Current timestamp according to the Gregorian calendar,
        ///     formatted according this culture.
        /// </returns>
        public static string GetTimeStamp(TYPE cultureID)
        {
            string str = DateTime.Now.ToString("u",
                CultureInfo.CreateSpecificCulture(GetCultureID(cultureID)));

            return str.Substring(0, str.Length - 1);
        }

        /// <summary>
        ///     Converts a (valid) string into the international language identifier TYPE.
        /// </summary>
        /// <param name="strCultureID">
        ///     Culture of which the international language identifier is requested.
        /// </param>
        /// <returns>
        ///     The language identifier of type TYPE.
        /// </returns>
        public static TYPE GetCultureID(string strCultureID)
        {
            const string strMETHOD = "Culture:GetCultureID(…): ";

            switch (strCultureID)
            {
                case "ar-SA":
                    return TYPE.ar_SA;
                case "de-DE":
                    return TYPE.de_DE;
                case "en-GB":
                    return TYPE.en_GB;
                case "no":
                    return TYPE.no;
                case "sv-SE":
                    return TYPE.sv_SE;
                case "tr":
                    return TYPE.tr;
                case "zh-CN":
                    return TYPE.zh_CN;
                default:    // NONE
                    Exception e =
                        new Exception("undefined culture \"" + strCultureID + "\".");

                    MessageBox.Show(strMETHOD + e);
                    throw e;
            }
        }

        /// <summary>
        ///     The words "absolute value"
        /// </summary>
        public string AbsoluteValues
        {
            get
            {
                return m_strAbsoluteValues;
            }
            set
            {
                m_strAbsoluteValues = value;
            }
        }

        /// <summary>
        ///     Abbreviation for the automatic state
        /// </summary>
        public string AutoAVR { get { return m_strAutoAVR; } set { m_strAutoAVR = value; } }
        /// <summary>
        ///     The word "automatic"
        /// </summary>
        public string AutomaticState { get { return m_strAutomaticState; } set { m_strAutomaticState = value; } }
        /// <summary>
        ///     Initialism for the automatic state
        /// </summary>
        public string AVR { get { return m_strAVR; } set { m_strAVR = value; } }

        /// <summary>
        ///     Capacitive unit
        /// </summary>
        public string CapacitiveUnit { get { return m_strCapacitiveUnit; } set { m_strCapacitiveUnit = value; } }

        /// <summary>
        ///     Caption of the menu.
        /// </summary>
        public string Caption { get { return m_strCaption; } set { m_strCaption = value; } }
        /// <summary>
        ///     The word "channel"
        /// </summary>
        public string Channel { get { return m_strChannel; } set { m_strChannel = value; } }
        /// <summary>
        ///     The words "channel changeover"
        /// </summary>
        public string ChannelChangeover { get { return m_strChannelChangeover; } set { m_strChannelChangeover = value; } }
        /// <summary>
        ///     The words "changeover blocking"
        /// </summary>
        public string ChangeoverBlocking { get { return m_strChangeoverBlocking; } set { m_strChangeoverBlocking = value; } }

        /// <summary>
        ///     The words "collective fault"
        /// </summary>
        public string CollectiveFault { get { return m_strCollectiveFault; } set { m_strCollectiveFault = value; } }
        /// <summary>
        ///     The words "cos f"
        /// </summary>
        public string CosPhi { get { return m_strCosPhi; } set { m_strCosPhi = value; } }
        /// <summary>
        ///     English name of the country.
        /// </summary>
        public string Country { get { return m_strCountry; } set { m_strCountry = value; } }

        public string CurrentSymbol { get { return m_strCurrentSymbol; } set { m_strCurrentSymbol = value; } }

        /// <summary>
        ///     Initialism for the manual state
        /// </summary>
        public string ECR { get { return m_strECR; } set { m_strECR = value; } }
        /// <summary>
        ///     The word "excitation"
        /// </summary>
        public string Excitation { get { return m_strExcitation; } set { m_strExcitation = value; } }
        public string ExcitationCurrent { get { return m_strExcitationCurrent; } set { m_strExcitationCurrent = value; } }

        public string ExcitationCurrentSymbol { get { return m_strExcitationCurrentSymbol; } set { m_strExcitationCurrentSymbol = value; } }

        /// <summary>
        ///     Name of the file containing the flag of this country.
        /// </summary>
        public string FlagFileName { get { return m_strFlagFileName; } set { m_strFlagFileName = value; } }
        /// <summary>
        ///     The words "generator circuit breake off"
        /// </summary>
        public string GeneratorCircuitBreakerOff { get { return m_strGeneratorCircuitBreakerOff; } set { m_strGeneratorCircuitBreakerOff = value; } }
        /// <summary>
        ///     The words "generator circuit breake on"
        /// </summary>
        public string GeneratorCircuitBreakerOn { get { return m_strGeneratorCircuitBreakerOn; } set { m_strGeneratorCircuitBreakerOn = value; } }
        /// <summary>
        ///     The words "generator revolution greater than
        ///     90 %" of the nominal value.
        /// </summary>
        public string GeneratorRevolutionGT90 { get { return m_strGeneratorRevolutionGT90; } set { m_strGeneratorRevolutionGT90 = value; } }
        /// <summary>
        ///     The words "generator revolution less than or
        ///     equal to 90 %" of the nominal value.
        /// </summary>
        public string GeneratorRevolutionLE90 { get { return m_strGeneratorRevolutionLE90; } set { m_strGeneratorRevolutionLE90 = value; } }

        public string GeneratorSymbol { get { return m_strGeneratorSymbol; } set { m_strGeneratorSymbol = value; } }
        public string GeneratorVoltage { get { return m_strGeneratorVoltage; } set { m_strGeneratorVoltage = value; } }

        /// <summary>
        ///     Getter for the international language identifier.
        /// </summary>
        /// <returns>
        ///     The language identifier.
        /// </returns>
        public string GetCountryCode()
        {
            short sStart = (short) m_CultureID.ToString().IndexOf(Constants.m_cUNDERSCORE);

            return (sStart >= 0) ? m_CultureID.ToString().Substring(++sStart, 2)
                : GetLanguageID().ToUpper();
        }

        /// <summary>
        ///     Getter for requested menu.
        /// <param name="index">
        ///     Requested menu index
        /// </param>
        /// <returns>
        ///     The language identifier.
        /// </returns>
        /// </summary>
        public string GetMenu(ButtonMenu.MENU index) 
        {
            return ma_strMenu[(ushort)index];
        }

        public string InductiveUnit { get { return m_strInductiveUnit; } set { m_strInductiveUnit = value; } }

        public string MessageInfoCaption { get { return m_strMessageInfoCaption; } set { m_strMessageInfoCaption = value; } }

        public string NominalValueSymbol { get { return m_strNominalValueSymbol; } set { m_strNominalValueSymbol = value; } }

        public string RealValueSymbol { get { return m_strRealValueSymbol; } set { m_strRealValueSymbol = value; } }

        public string VoltageSymbol { get { return m_strVoltageSymbol; } set { m_strVoltageSymbol = value; } }

        public string ManualECR { get { return m_strManualECR; } set { m_strManualECR = value; } }
        /// <summary>
        ///     The words "is switched off"
        /// </summary>
        public string IsSwitchedOff { get { return m_strIsSwitchedOff; } set { m_strIsSwitchedOff = value; } }
        /// <summary>
        ///     The words "is switched on"
        /// </summary>
        public string IsSwitchedOn { get { return m_strIsSwitchedOn; } set { m_strIsSwitchedOn = value; } }
        /// <summary>
        ///     Language spoken in this culture.
        /// </summary>
        public string Language { get { return m_strLanguage; } set { m_strLanguage = value; } }
        /// <summary>
        ///     The words "limiter active"
        /// </summary>
        public string LimiterActive { get { return m_strLimiterActive; } set { m_strLimiterActive = value; } }
        /// <summary>
        ///     The words "limiter inactive"
        /// </summary>
        public string LimiterInactive { get { return m_strLimiterInactive; } set { m_strLimiterInactive = value; } }
        /// <summary>
        ///     The word "manual"
        /// </summary>
        public string ManualState { get { return m_strManualState; } set { m_strManualState = value; } }
        ///// <summary>
        /////     Start menu.
        ///// </summary>
        //public string Menu01 { get { return ma_strMenu[0]; } set { ma_strMenu[0] = value; } }
        ///// <summary>
        /////     Values menu.
        ///// </summary>
        //public string Menu02 { get { return m_strMenu02; } set { m_strMenu02 = value; } }
        ///// <summary>
        /////     Analogue gadgets menu.
        ///// </summary>
        //public string Menu03 { get { return m_strMenu03; } set { m_strMenu03 = value; } }
        ///// <summary>
        /////     SFC menu.
        ///// </summary>
        //public string Menu04 { get { return m_strMenu04; } set { m_strMenu04 = value; } }
        ///// <summary>
        /////     Q/cos f menu.
        /////     Combination of "ReactivePowerSymbol", a slash, and "cos f".
        ///// </summary>
        ////public string Menu05 { get { return m_strMenu05; } set { m_strMenu05 = value; } }
        ///// <summary>
        /////     P-Q menu.
        /////     Combination of "RealPowerSymbol", a dash, and "ReactivePowerSymbol"
        ///// </summary>
        ////public string Menu06 { get { return m_strMenu06; } set { m_strMenu06 = value; } }
        ///// <summary>
        /////     Trend menu.
        ///// </summary>
        //public string Menu07 { get { return m_strMenu07; } set { m_strMenu07 = value; } }
        ///// <summary>
        /////     Messages menu.
        ///// </summary>
        //public string Menu08 { get { return m_strMenu08; } set { m_strMenu08 = value; } }
        ///// <summary>
        /////     Administration menu.
        ///// </summary>
        //public string Menu09 { get { return m_strMenu09; } set { m_strMenu09 = value; } }
        /// <summary>
        ///     The words "no collective fault"
        /// </summary>
        public string NoCollectiveFault { get { return m_strNoCollectiveFault; } set { m_strNoCollectiveFault = value; } }
        /// <summary>
        ///     The words "no redundancy"
        /// </summary>
        public string NoRedundancy { get { return m_strNoRedundancy; } set { m_strNoRedundancy = value; } }
        public string NominalValue { get { return m_strNominalValue; } set { m_strNominalValue = value; } }
        public string ReferenceSetter { get { return m_strReferenceSetter; } set { m_strReferenceSetter = value; } }
        /// <summary>
        ///     The words "not ready to switch on"
        /// </summary>
        public string NotReady2SwitchOn { get { return m_strNotReady2SwitchOn; } set { m_strNotReady2SwitchOn = value; } }
        /// <summary>
        ///     The word switch "off"
        /// </summary>
        public string Off { get { return m_strOff; } set { m_strOff = value; } }
        /// <summary>
        ///     The word switch "on"
        /// </summary>
        public string On { get { return m_strOn; } set { m_strOn = value; } }
        /// <summary>
        ///     Parameter of active power
        /// </summary>
        public string RealPowerSymbol { get { return m_strRealPowerSymbol; } set { m_strRealPowerSymbol = value; } }
        /// <summary>
        ///     The words "percent value"
        /// </summary>
        public string PercentValues { get { return m_strPercentValues; } set { m_strPercentValues = value; } }
        /// <summary>
        ///     The words "protection off"
        /// </summary>
        public string ProtectionOff { get { return m_strProtectionOff; } set { m_strProtectionOff = value; } }
        /// <summary>
        ///     The words "protection on"
        /// </summary>
        public string ProtectionOn { get { return m_strProtectionOn; } set { m_strProtectionOn = value; } }
        /// <summary>
        ///     Initialism for "Power Stability System"
        /// </summary>
        public string PSS { get { return m_strPSS; } set { m_strPSS = value; } }
        /// <summary>
        ///     Parameter of reactive power
        /// </summary>
        public string ReactivePowerSymbol { get { return m_strReactivePowerSymbol; } set { m_strReactivePowerSymbol = value; } }
        public string RealValue { get { return m_strRealValue; } set { m_strRealValue = value; } }
        /// <summary>
        ///     The words "ready to switch on"
        /// </summary>
        public string Ready2SwitchOn { get { return m_strReady2SwitchOn; } set { m_strReady2SwitchOn = value; } }
        /// <summary>
        ///     The words "redundancy exists"
        /// </summary>
        public string RedundancyExists { get { return m_strRedundancyExists; } set { m_strRedundancyExists = value; } }
        /// <summary>
        ///     The words "scope local"
        /// </summary>
        public string ScopeLocal { get { return m_strScopeLocal; } set { m_strScopeLocal = value; } }
        /// <summary>
        ///     The words "scope remote"
        /// </summary>
        public string ScopeRemote { get { return m_strScopeRemote; } set { m_strScopeRemote = value; } }
        /// <summary>
        ///     Screen header of each form.
        /// </summary>
        public string ScreenHeader { get { return m_strScreenHeader; } set { m_strScreenHeader = value; } }
        /// <summary>
        ///     Name of the element for the 
        ///     list boxes of the selection menu.
        /// </summary>
        public string GetSource(ushort usIndex)
        {
            return "empty"; // ma_strSource[usIndex];
        }

        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_01 { get { return m_strSource_01; } set { m_strSource_01 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_02 { get { return m_strSource_02; } set { m_strSource_02 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_03 { get { return m_strSource_03; } set { m_strSource_03 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_04 { get { return m_strSource_04; } set { m_strSource_04 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_05 { get { return m_strSource_05; } set { m_strSource_05 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_06 { get { return m_strSource_06; } set { m_strSource_06 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_07 { get { return m_strSource_07; } set { m_strSource_07 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_08 { get { return m_strSource_08; } set { m_strSource_08 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_09 { get { return m_strSource_09; } set { m_strSource_09 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_10 { get { return m_strSource_10; } set { m_strSource_10 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_11 { get { return m_strSource_11; } set { m_strSource_11 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_12 { get { return m_strSource_12; } set { m_strSource_12 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_13 { get { return m_strSource_13; } set { m_strSource_13 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_14 { get { return m_strSource_14; } set { m_strSource_14 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_15 { get { return m_strSource_15; } set { m_strSource_15 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_16 { get { return m_strSource_16; } set { m_strSource_16 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_17 { get { return m_strSource_17; } set { m_strSource_17 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_18 { get { return m_strSource_18; } set { m_strSource_18 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_19 { get { return m_strSource_19; } set { m_strSource_19 = value; } }
        ///// <summary>
        /////     Name of the element for the 
        /////     list boxes of the selection menu.
        ///// </summary>
        //public string Source_20 { get { return m_strSource_20; } set { m_strSource_20 = value; } }

        /// <summary>
        ///     Text of the source elements list box.
        /// </summary>
        public string SourceListBox { get { return m_strSourceListBox; } set { m_strSourceListBox = value; } }
        /// <summary>
        ///     Text of the target elements list box.
        /// </summary>
        public string TargetListBox { get { return m_strTargetListBox; } set { m_strTargetListBox = value; } }
        /// <summary>
        ///     International identification of the l_m_Culture,
        ///     consisting of two-character abbreviations of 
        ///     the language and the country, separated by a dash.
        /// </summary>
        public TYPE CultureID { get { return m_CultureID; } set { m_CultureID = value; } }

        /// <summary>
        ///     Setter for requested menu.
        /// </summary>
        /// <param name="strName">
        ///     Value to be set
        /// </param>
        /// <param name="index">
        ///     Menu index
        /// </param>
        public void SetMenu(string strName, ButtonMenu.MENU index)
        {
            ma_strMenu[(ushort)index] = strName;
        }

        /// <summary>
        ///     Setter for requested source.
        /// </summary>
        /// <param name="strValue">
        ///     Value to be set
        /// </param>
        /// <param name="usIndex">
        ///     Source index
        /// </param>
        public void SetSource(string strValue, ushort usIndex)
        {
            ma_strSource[usIndex] = strValue;
        }
    }
}

Open in new window


StartForm:
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace WindowsFormTestButtonMenu
{
    public class StartForm : Form
    {
    }
}

Open in new window


Tuple:
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Thyripol
{
    public class Tuple
    {
        /// <summary>
        ///     The culture ID comes first, followed by the resx file content.
        /// </summary>
        public enum LABEL
        {
            /// <summary>
            ///     Label for the words "absolute value"
            /// </summary>
            ABSOLUTE_VALUES,
            /// <summary>
            ///     Label for the long form of AVR
            /// </summary>
            AUTO_AVR,
            /// <summary>
            ///     Automatic state
            /// </summary>
            AUTOMATIC_STATE,
            /// <summary>
            ///     Label for initialism for automatic state
            /// </summary>
            AVR,
            /// <summary>
            ///     Label for the unit of capacitive cos f
            /// </summary>
            CAPACITIVE,
            /// <summary>
            ///     Caption of the menu
            /// </summary>
            CAPTION,
            /// <summary>
            ///     Label for the words "changeover blocking"
            /// </summary>
            CHANGEOVER_BLOCKING,
            /// <summary>
            ///     Label for the word "channel"
            /// </summary>
            CHANNEL,
            /// <summary>
            ///     Label for the words "channel changeover"
            /// </summary>
            CHANNEL_CHANGEOVER,
            /// <summary>
            ///     Label for the words "collective fault exists"
            /// </summary>
            COLLECTIVE_FAULT_EXISTS,
            /// <summary>
            ///     Label for the text "cos f"
            /// </summary>
            COS_PHI,
            /// <summary>
            ///     Country of the culture
            /// </summary>
            COUNTRY,
            /// <summary>
            ///     Identification of the culture
            /// </summary>
            CULTURE_ID,
            /// <summary>
            ///     Label for the current symbol
            /// </summary>
            CURRENT_SYMBOL,
            /// <summary>
            ///     Label for initialism for manual state
            /// </summary>
            ECR,
            /// <summary>
            ///     Label for the word "excitation"
            /// </summary>
            EXCITATION,
            /// <summary>
            ///     Label for the words "excitation current"
            /// </summary>
            EXCITATION_CURRENT,
            /// <summary>
            ///     Label for the excitation symbol
            /// </summary>
            EXCITATION_CURRENT_SYMBOL,
            /// <summary>
            ///     Name of the flag file resource
            /// </summary>
            FLAG_FILE_NAME,
            /// <summary>
            ///     Label for the words "generator circuit breaker off"
            /// </summary>
            GENERATOR_CIRCUIT_BREAKER_OFF,
            /// <summary>
            ///     Label for the words "generator circuit breaker on"
            /// </summary>
            GENERATOR_CIRCUIT_BREAKER_ON,
            /// <summary>
            ///     Label for the words "generator revolution greater than 90%"
            ///     of the nominal value.
            /// </summary>
            GENERATOR_REVOLUTION_GT_90,
            /// <summary>
            ///     Label for the words "generator revolution less than or
            ///     equal to 90%" of the nominal value.
            /// </summary>
            GENERATOR_REVOLUTION_LE_90,
            /// <summary>
            ///     Label for the generator symbol
            /// </summary>
            GENERATOR_SYMBOL,
            /// <summary>
            ///     Label for the words "generator voltage"
            /// </summary>
            GENERATOR_VOLTAGE,
            /// <summary>
            ///     Label for the long form of ECR
            /// </summary>
            HAND_ECR,
            /// <summary>
            ///     Label for the unit of inductive cos f
            /// </summary>
            INDUCTIVE,
            /// <summary>
            ///     Label for the words "is switched off"
            /// </summary>
            IS_SWITCHED_OFF,
            /// <summary>
            ///     Label for the words "is switched on"
            /// </summary>
            IS_SWITCHED_ON,
            /// <summary>
            ///     Language of the culture
            /// </summary>
            LANGUAGE,
            /// <summary>
            ///     Label for the words "limiter active"
            /// </summary>
            LIMITER_ACTIVE,
            /// <summary>
            ///     Label for the words "limiter inactive"
            /// </summary>
            LIMITER_INACTIVE,
            /// <summary>
            ///     Manual (ECR)
            /// </summary>
            MANUAL_ECR,
            /// <summary>
            ///     The manual state
            /// </summary>
            MANUAL_STATE,
            /// <summary>
            ///     Start menu
            /// </summary>
            MENU_01,
            /// <summary>
            ///     Values menu
            /// </summary>
            MENU_02,
            /// <summary>
            ///     Analogue menu
            /// </summary>
            MENU_03,
            /// <summary>
            ///     SFC menu
            /// </summary>
            MENU_04,
            /// <summary>
            ///     Q/cos f menu
            /// </summary>
            MENU_05,
            /// <summary>
            ///     P-Q menu
            /// </summary>
            MENU_06,
            /// <summary>
            ///     Trend menu
            /// </summary>
            MENU_07,
            /// <summary>
            ///     Messages menu
            /// </summary>
            MENU_08,
            /// <summary>
            ///     Administration menu
            /// </summary>
            MENU_09,
            /// <summary>
            ///     Culture selection menu
            /// </summary>
            MENU_10,
            /// <summary>
            ///     Name of current menu displayed to the top right
            /// </summary>
            MENU_NAME,
            MESSAGE_INFO_CAPTION,
            /// <summary>
            ///     Label for the words "no collective fault"
            /// </summary>
            NO_COLLECTIVE_FAULT,
            /// <summary>
            ///     Label for the words "no redundancy"
            /// </summary>
            NO_REDUNDANCY,
            /// <summary>
            ///     Label for the words "nominal value"
            /// </summary>
            NOMINAL_VALUE,
            NOMINAL_VALUE_SYMBOL,
            /// <summary>
            ///     Label for the words "not ready to switch on"
            /// </summary>
            NOT_READY2SWITCH_ON,
            /// <summary>
            ///     Label for the word "off"
            /// </summary>
            OFF,
            /// <summary>
            ///     Label for the word "on"
            /// </summary>
            ON,
            /// <summary>
            ///     Label for the words "percent value"
            /// </summary>
            PERCENT_VALUES,
            /// <summary>
            ///     Label for the words "protection off"
            /// </summary>
            PROTECTION_OFF,
            /// <summary>
            ///     Label for the words "protection on"
            /// </summary>
            PROTECTION_ON,
            /// <summary>
            ///     Label for initialism "PSS" (Power Stabilizer System)
            /// </summary>
            PSS,
            /// <summary>
            ///     Label for parameter "ReactivePowerSymbol" for reactive power
            /// </summary>
            REACTIVE_POWER_SYMBOL,
            /// <summary>
            ///     Label for parameter "RealPowerSymbol" for active power
            /// </summary>
            REAL_POWER_SYMBOL,
            /// <summary>
            ///     Label for the words "ready to switch on"
            /// </summary>
            READY2SWITCH_ON,
            /// <summary>
            ///     Label for the words "real value"
            /// </summary>
            REAL_VALUE,
            REAL_VALUE_SYMBOL,
            /// <summary>
            ///     Label for the words "redundancy exists"
            /// </summary>
            REDUNDANCY_EXISTS,
            /// <summary>
            ///     Label for the words "reference setter"
            /// </summary>
            REFERENCE_SETTER,
            /// <summary>
            ///     Label for the words "scope local"
            /// </summary>
            SCOPE_LOCAL,
            /// <summary>
            ///     Label for the words "scope remote"
            /// </summary>
            SCOPE_REMOTE,
            /// <summary>
            ///     Label for the words "screen header"
            /// </summary>
            SCREEN_HEADER,
            /// <summary>
            ///     Text for the words "Source 01"
            /// </summary>
            SOURCE_01,
            /// <summary>
            ///     Text for the words "Source 02"
            /// </summary>
            SOURCE_02,
            /// <summary>
            ///     Text for the words "Source 03"
            /// </summary>
            SOURCE_03,
            /// <summary>
            ///     Text for the words "Source 04"
            /// </summary>
            SOURCE_04,
            /// <summary>
            ///     Text for the words "Source 05"
            /// </summary>
            SOURCE_05,
            /// <summary>
            ///     Text for the words "Source 06"
            /// </summary>
            SOURCE_06,
            /// <summary>
            ///     Text for the words "Source 07"
            /// </summary>
            SOURCE_07,
            /// <summary>
            ///     Text for the words "Source 08"
            /// </summary>
            SOURCE_08,
            /// <summary>
            ///     Text for the words "Source 09"
            /// </summary>
            SOURCE_09,
            /// <summary>
            ///     Text for the words "Source 10"
            /// </summary>
            SOURCE_10,
            /// <summary>
            ///     Text for the words "Source 11"
            /// </summary>
            SOURCE_11,
            /// <summary>
            ///     Text for the words "Source 12"
            /// </summary>
            SOURCE_12,
            /// <summary>
            ///     Text for the words "Source 13"
            /// </summary>
            SOURCE_13,
            /// <summary>
            ///     Text for the words "Source 14"
            /// </summary>
            SOURCE_14,
            /// <summary>
            ///     Text for the words "Source 15"
            /// </summary>
            SOURCE_15,
            /// <summary>
            ///     Text for the words "Source 16"
            /// </summary>
            SOURCE_16,
            /// <summary>
            ///     Text for the words "Source 17"
            /// </summary>
            SOURCE_17,
            /// <summary>
            ///     Text for the words "Source 18"
            /// </summary>
            SOURCE_18,
            /// <summary>
            ///     Text for the words "Source 19"
            /// </summary>
            SOURCE_19,
            /// <summary>
            ///     Text for the words "Source 20"
            /// </summary>
            SOURCE_20,
            /// <summary>
            ///     Name of the source list box
            /// </summary>
            SOURCE_LIST_BOX,
            /// <summary>
            ///     Name of the target list box
            /// </summary>
            TARGET_LIST_BOX,
            /// <summary>
            ///     Label for the word "timestamp"
            /// </summary>
            TIMESTAMP,
            VOLTAGE_SYMBOL,
        };

        /// <summary>
        ///     The first element of the tuple is this label.
        /// </summary>
        public LABEL Label { get; set; }
        /// <summary>
        ///     The second element of the tuple is this value.
        /// </summary>
        public string Value { get; set; }

        /// <summary>
        ///     Constructor
        /// </summary>
        /// <param name="label">
        ///     Label order information
        /// </param>
        /// <param name="strValue">
        ///     Value of this label
        /// </param>
        public Tuple(LABEL label, string strValue)
        {
            Label = label;
            Value = strValue;
        }

        /// <summary>
        ///     Override method for ToString that returns the Value instead.
        /// </summary>
        /// <returns>
        ///     Returns the Value.
        /// </returns>
        public override string ToString()
        {
            return Value;
        }
    }
}

Open in new window

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
In ButtonMenu, I don't see where you set the size of the Control itself...nor do I see where you add the GroupBox to the Control.

At the bottom of InitializeComponent(), you could do something like:

            // The ButtonMenu itself!
            this.Size = this.m_GroupBox.Size;
            this.Controls.Add(this.m_GroupBox);
0
 
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Thank you! I added a simple TextBox to the controls to be displayed, ending the InitializeComponents() with the lines

            //
            // Define its own dimension:
            //
            this.Size = m_GroupBox.Size;
            Controls.AddRange(new Control[] {textBox, m_GroupBox});
            ResumeLayout();

Open in new window


I can see the TextBox, but the GroupBox remains invisible, although its Visible property is true. I made its background colour to red to see it better.
/// <summary>
        ///     Initialises all components
        /// </summary>
        private void InitializeComponent()
        {
            this.btnCulture = new Button();
            this.m_GroupBox = new GroupBox();

            TextBox textBox = new TextBox();

            textBox.Text = "This works!";
            this.SuspendLayout();
            m_GroupBox.SuspendLayout();
            //// 
            //// m_GroupBox
            //// 
            this.m_GroupBox.Controls.Add(textBox);
            this.m_GroupBox.Controls.Add(this.btnCulture);
            this.m_GroupBox.Location = new System.Drawing.Point(0, 664);
            this.m_GroupBox.Name = "m_GroupBox";
            this.m_GroupBox.Size = new System.Drawing.Size(1273, 68);
            this.m_GroupBox.TabIndex = 12;
            this.m_GroupBox.TabStop = false;

            this.m_GroupBox.ResumeLayout(false);
            m_GroupBox.BackColor = Color.Red;
            // 
            // btnCulture
            // 
            this.btnCulture.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btnCulture.ImeMode = System.Windows.Forms.ImeMode.NoControl;
            this.btnCulture.Location = new System.Drawing.Point(1156, 19);
            this.btnCulture.Name = "btnCulture";
            this.btnCulture.Size = new System.Drawing.Size(100, 40);
            this.btnCulture.TabIndex = 9;
            this.btnCulture.Text = "EN";
            this.btnCulture.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btnCulture.UseVisualStyleBackColor = true;
            this.btnCulture.Click += new System.EventHandler(this.btnCulture_Click);
            //
            // Define its own dimension:
            //
            this.Size = m_GroupBox.Size;
            Controls.AddRange(new Control[] {textBox, m_GroupBox});
            ResumeLayout();
        }

Open in new window

0
 
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
Thank you for your support!

I finally managed to get it work without using a GroupBox. Origianally, the GroupBox itself was part of BaseForm that is the parent of all my custom forms, and it was the physical boundary of the so-called ButtonMenu that was a kind of wrapper class. But now, ButtonMenu itself is a Control, and there is actually no need for a GroupBox anymore.
0
 
Ahmet Ekrem SABANSenior IT consultantAuthor Commented:
I found the solution by myself.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 9
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now