471,605 Members | 1,406 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,605 software developers and data experts.

Breaking from ListArray [C# WindowForms]

Hiya Everyone,

Hopefully someone can help.

I've created a ListArray and I am putting my data into custom buttons. The
background is this, The amount of data in the ListArray will very. The max
amount of buttons I will have is 15. If there is more than 15 items in the
ListArray then the 15th button will be a more button to cycle through and
display more items from the ListArray.

What I will need to do is break out of my function if there is "MORE" button
being displayed, and to check what the user button click/press is going to
be. If the user clicks on the "MORE" button then I need to continue with the
"foreach loop" of my ListArray, clear the controls and add a new amount of
buttons with more data from the ListArray, if not I will use the existing
button information for my application.

At this point I am unsure of the best syntax to be using for this. Any and
all help is appreciated. My Code is as follows:

private void Get_ArrayList()
{
ArrayList_Load_Data myArrayList_Load_Data = new ArrayList_Load_Data();
myArrayList = myArrayList_Load_Data.Test;

//*****If There Is Not Data Present
if(myArrayList.Count == 0)
{
MessageBox.Show("You have no Data");

while(btnCounter <= MaxButtonCount)
{
if(btnCounterTotal <= MaxColumnCount)
{
btnName = "";
btnText = "";
btnTabIndex = 0;
btnColor = System.Drawing.Color.Gray;

AddControl(new Button(), new Point(ColumnPlacement,RowPlacement), new
Size(100,50), btnName, btnText, btnTabIndex, btnColor);

ColumnPlacement = ColumnPlacement + 105;
btnCounter = btnCounter + 1;
btnCounterTotal = btnCounterTotal + 1;
}
else
{
btnName = "";
btnText = "";
btnTabIndex = 0;
btnColor = System.Drawing.Color.Gray;

RowPlacement = RowPlacement + 55;
ColumnPlacement = 0;

AddControl(new Button(), new Point(ColumnPlacement,RowPlacement), new
Size(100,50), btnName, btnText, btnTabIndex, btnColor);

ColumnPlacement = ColumnPlacement + 105;
btnCounterTotal = 2;
btnCounter = btnCounter + 1;
}
}
}
//*****If There Is Data Present. Display Data
else
{
foreach(DataItem myItem in myArrayList)
{
if(myItem.Index == btnCounterTotal)
{
btnName = "btn" + myItem.Name;
btnText = myItem.Name;
btnTabIndex = myItem.Index;
btnColor = System.Drawing.Color.FromName(myItem.Color);
Load_Default_Button();

myBlankCounter += 1;
}
else
{
while(myItem.Index != btnCounterTotal)
{
btnName = "";
btnText = "";
btnTabIndex = 0;
btnColor = System.Drawing.Color.Gray;
Load_Default_Button();

myBlankCounter += 1;
}
btnName = "btn" + myItem.Name;
btnText = myItem.Name;
btnTabIndex = myItem.Index;
btnColor = System.Drawing.Color.FromName(myItem.Color);
Load_Default_Button();

myBlankCounter += 1;
}
}
if(myArrayList.Count < MaxButtonCount)
{
while(myBlankCounter != MaxButtonCount)
{
btnName = "";
btnText = "";
btnTabIndex = 0;
btnColor = System.Drawing.Color.Gray;
Load_Default_Button();

myBlankCounter += 1;
}
}
}
private void Load_Default_Button()
{
if(btnCounter <= MaxButtonCount)
{
if(btnCounter <= MaxColumnCount)
{
if(btnCounterTotal == MaxButtonCount)
{
btnText1 = btnText;
btnName1 = btnName;
btnColor1 = btnColor;
btnTabIndex1 = btnTabIndex;

btnText = "MORE";
btnName = "";
btnColor = System.Drawing.Color.FromName("Gold");
btnTabIndex = 0;
AddControl(new Button(), new Point(ColumnPlacement,RowPlacement), new
Size(100,50), btnName, btnText, btnTabIndex, btnColor);

MaxButtonCount += MaxButtonCount;
}
else //If btnCounterTotal Does Not equal MaxButtonCount
{
AddControl(new Button(), new Point(ColumnPlacement,RowPlacement), new
Size(100,50), btnName, btnText, btnTabIndex, btnColor);
ColumnPlacement = ColumnPlacement + 105;
btnCounter = btnCounter + 1;
btnCounterTotal = btnCounterTotal + 1;
}
}
else //If ColumnCounter is Greater Than MaxColumnCount
{ //Create a new Row
ColumnPlacement = 0;
RowPlacement = RowPlacement + 55;

AddControl(new Button(), new Point(ColumnPlacement,RowPlacement), new
Size(100,50), btnName, btnText, btnTabIndex, btnColor);

ColumnPlacement = ColumnPlacement + 105;
btnCounter = 2;
btnCounterTotal += 1;
}
}
else //If BtnCounter is Greater Than MaxButtonCount
{
}
}
private void AddControl(Control aControl, Point btnLocation, Size btnSize,
string btnName, String btnText, int btnTabIndex, System.Drawing.Color
btnColor)
{
aControl = new Test_Button.CustomButtons();
aControl.Name = btnName;
aControl.Text = btnText;
aControl.Font = new System.Drawing.Font("Tahoma", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
aControl.TabIndex = btnTabIndex;
aControl.BackColor = btnColor;
aControl.Location = btnLocation;
aControl.Size = btnSize;
aControl.Click += new System.EventHandler(MYTEST);
this.Controls.Add(aControl);
}
private void MYTEST(object sender, System.EventArgs e)
{
Button mystring = (Button)sender;
if(mystring.Text == "MORE")
{
Controls.Clear();
btnText = btnText1;
btnName = btnName1;
btnColor = btnColor1;
btnTabIndex = btnTabIndex1;
btnCounter = 1;
ColumnPlacement = 0;
RowPlacement = 0;

AddControl(new Button(), new Point(ColumnPlacement,RowPlacement), new
Size(100,50), btnName, btnText, btnTabIndex, btnColor);

ColumnPlacement = 0;
RowPlacement = 0;
btnCounter += 1;
btnCounter += 1;
btnTabIndex += btnTabIndex1;
AddControl(new Button(), new Point(ColumnPlacement,RowPlacement), new
Size(100,50), btnName, btnText, btnTabIndex, btnColor);

Load_Default_Button();
}
else
{
MessageBox.Show("TEXT: " + " " + mystring.Text + "\n" +
"NAME: " + " " + mystring.Name + " " + "\n" +
"BACKCOLOUR: " + " " + mystring .BackColor + "\n" +
"INDEX: " + " " + mystring.TabIndex.ToString());
}
}
Feb 15 '06 #1
0 3264

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

27 posts views Thread by The Bicycling Guitarist | last post: by
22 posts views Thread by stevenkobes | last post: by
49 posts views Thread by elmar | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.