[C#] AceInfoBox Class - Application Info Display Form

AceInfinity

Emeritus, Contributor
Joined
Feb 21, 2012
Posts
1,728
Location
Canada
Use The Namespace:
Code:
using AceUtilities;

My InfoBox Information:
Code:
private infoStrings infoStrs = new infoStrings
{
	programName = "AceProgram",
	developerName = "AceInfinity",
	companyName = "TechLifeForum",
	creationDate = "June 2012",
	descriptionText = "This is a simple test to see how my AceInfoBox looks like. Testing Testing Testing Testing, TEST, TEST, TEST."
};

To Test:
Code:
private void button1_Click(object sender, EventArgs e)
{
	new AceInfoBox(infoStrs).ShowDialog();
}

My Full Class:
Code:
using System;
using System.Linq;
using System.Drawing;
using System.Windows.Forms;

namespace AceUtilities
{
	public class infoStrings
	{
		private string programN, devN, companyN, creationD, descText;

		public string programName
		{
			get { return programN; }
			set { programN = CheckLength(value); }
		}

		public string developerName
		{
			get { return devN; }
			set { devN = CheckLength(value); }
		}

		public string companyName
		{
			get { return companyN; }
			set { companyN = CheckLength(value); }
		}

		public string creationDate
		{
			get { return creationD; }
			set { creationD = CheckLength(value); }
		}

		public string descriptionText
		{
			get { return descText; }
			set { descText = CheckLength(value); }
		}


		private const int Maxlen = 75;
		private string CheckLength(string value)
		{
			return value.Length > Maxlen ? string.Concat(value.Take(75).ToArray()) + "..." : value;
		}
	}

	public class AceInfoBox : Form
	{

		public AceInfoBox(infoStrings InformationStrs, Icon icon = null, string FormTitle = "Application Information")
		{
			this.Text = FormTitle;
			this.Size = new Size(475, 150);
			this.FormBorderStyle = FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.Icon = icon ?? SystemIcons.Information;
			SetLabels(InformationStrs);
		}

		private void SetLabels(infoStrings StrInfo)
		{
			int disp = 15;
			int dispY = 20;

			for (int i = 0; i < 5; i++)
			{
				Label lbl = new Label();
				switch (i)
				{
					case 0:
						lbl.Text = string.Format("Program Name - {0}", StrInfo.programName);
						break;
					case 1:
						lbl.Text = string.Format("Developer Name - {0}", StrInfo.developerName);
						break;
					case 2:
						lbl.Text = string.Format("Company Name - {0}", StrInfo.companyName);
						break;
					case 3:
						lbl.Text = string.Format("Creation Date - {0}", StrInfo.creationDate);
						break;
					case 4:
						lbl.Text = string.Format("Description - {0}", StrInfo.descriptionText);
						break;

				}

				lbl.Location = new Point(15, disp);
				disp += dispY;

				lbl.Size = new Size(this.Width, 15);
				this.Controls.Add(lbl);
			}
		}

	}
}

Very very basic outcome, but it was just a firsthand test without doing anything fancy. Use it to better your understanding and get to making your own if you want!

SBdTB.png


With this you can:
• Have your own infobox icon
• Change the infobox form text & all the label details

(I have a preventative function on each string property to add "..." to the end of the string after shortening it if it becomes too long, but perhaps, you could create a function or method to shorten and divide up into lines kind of like an auto-wrapping feature? You'd have to extend the form height though if the description is long enough to extend the bounds of the infobox form without modifying it's size though.)

Good example of the C# null coalescing operator in here as well! (??)

:beerchug2:
 

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top