What do I want to achieve?
My goal is to create a sudoku field programmatically, so I want to add 9x9 EditText-views to my existing TableLayout.
What is my problem?
Easy said: The EditText-views are not showing up.
What have I tried?
Well.. my google attempts could be recognized as a DDOS-Attack.. ;)
But seriously, I googled a lot, read some documentations etc. but could not find appropriate information solving my problem.
My Sudoku activiy code:
public class Sudoku : Activity
{
private EditText[,] tbs;
private TableLayout grid;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
//set view
SetContentView(Resource.Layout.Sudoku);
//initializations
tbs = new EditText[9,9];
grid = FindViewById<TableLayout> (Resource.Id.grid);
//preparation
prepareControls ();
}
private void prepareControls()
{
int size = Conversion.PixelsToDp(Resources.DisplayMetrics.WidthPixels, Resources.DisplayMetrics.Density) / 15;
int x_default = 10;
int x = x_default;
int y = x_default;
int margin = 4;
RelativeLayout.LayoutParams lparams = new RelativeLayout.LayoutParams (size, size);
for (int row = 0; row < 9; row++)
{
TableRow trow = new TableRow (this);
for (int col = 0; col < 9; col++)
{
//lparams.LeftMargin = x;
//lparams.TopMargin = y;
EditText tb = new EditText (this);
tb.SetHeight (size);
tb.SetWidth (size);
tb.Gravity = GravityFlags.Center;
tb.SetTextColor (Color.Argb (1, 75, 75, 75));
tb.SetBackgroundColor (Color.White);
tb.LayoutParameters = lparams;
tbs[col, row] = tb;
//layout.AddView (tb, lparams);
trow.AddView (tb);
x += size;
if ((col + 1) % 3 == 0)
{
x += margin;
}
if ((col + 1) % 9 == 0)
{
y += size;
x = x_default;
}
}
if ((row + 1) % 3 == 0)
{
y += margin;
}
grid.AddView (trow);
}
}
}
Additional information
Environment: Xamarin
Language: C#
API Level: API 15
I appreciate any help!
Related
I have TableLayoutPanel on windows form. I want mouse pointer cursor style is cross when the pointer on/near the cell border.
Edit I tried with mouse move event. I get the cell positions where the mouse point is moving.But I couldn't use this information and I was stuck. How can achieve that?
Edit: I fixed the problem. It is about size type. The code is working. I'm sharing it for those who have similar demands. Thanx.
bool calcCells = false;
List<float> XCoordinates = new List<float>();
List<float> YCoordinates = new List<float>();
public Form3()
{
InitializeComponent();
// Set the DoubleBuffered property via reflection (if needed)
var flags = BindingFlags.Instance | BindingFlags.NonPublic;
tlp1.GetType().GetProperty("DoubleBuffered", flags).SetValue(tlp1, true);
tlp1.Layout += tlp1_Layout;
tlp1.CellPaint += tlp1_CellPaint;
tlp1.MouseMove += tlp1_MouseMove;
}
// Added the x coordinates of cell borders in a List
private void CreateXCoordinateList()
{
XCoordinates.Clear();
// first and last column sizetype is SizeType.Absoulute.
float tlpWidth = tlp1.Width- tlp1.ColumnStyles[0].Width - tlp1.ColumnStyles[tlp1.ColumnCount-1].Width;
float x = 0;
for (int i = 0; i < tlp1.ColumnCount; i++)
{
if(tlp1.ColumnStyles[i].SizeType==SizeType.Absolute)
x += tlp1.ColumnStyles[i].Width;
else if(tlp1.ColumnStyles[i].SizeType == SizeType.Percent)
{
double k = tlpWidth * tlp1.ColumnStyles[i].Width * 0.01;
x += Convert.ToSingle(k);
}
XCoordinates.Add(x);
}
}
// Added the y coordinates of cell borders in a List
private void CreateYCoordinateList()
{
YCoordinates.Clear();
// first and last row sizetype is SizeType.Absoulute.
float tlpHeight = tlp1.Height - tlp1.RowStyles[0].Height - tlp1.RowStyles[tlp1.RowCount - 1].Height;
float y = 0;
for (int i = 0; i < tlp1.RowCount; i++)
{
if (tlp1.RowStyles[i].SizeType == SizeType.Absolute)
y += tlp1.RowStyles[i].Height;
else if (tlp1.RowStyles[i].SizeType == SizeType.Percent)
{
double k = tlpHeight * tlp1.RowStyles[i].Height*0.01;
y += Convert.ToSingle(k);
}
YCoordinates.Add(y);
}
}
private void tlp1_Layout(object sender, LayoutEventArgs e) => calcCells = true;
private void tlp1_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
{
if (calcCells)
{
CreateXCoordinateList();
CreateYCoordinateList();
if (e.Column == tlp1.ColumnCount - 1 &&
e.Row == tlp1.RowCount - 1)
calcCells = false;
}
}
private void tlp1_MouseMove(object sender, MouseEventArgs e)
{
//Comparing the mouse pointer position with the cellborder coordinates,
//if the difference is less than and equal to 4, change the cursor style.
float x = e.Location.X;
float y = e.Location.Y;
if (MouseNearCellBorderXAxis(e) || MouseNearCellBorderYAxis(e))
tlp1.Cursor = Cursors.Cross;
else
tlp1.Cursor = Cursors.Default;
}
private bool MouseNearCellBorderXAxis(MouseEventArgs e)
{
float x = e.Location.X;
for (int i = 0; i < XCoordinates.Count; i++)
{
float Border = XCoordinates[i];
double difference = Math.Abs(x - Border);
if (difference <= 4)
return true;
}
return false;
}
private bool MouseNearCellBorderYAxis(MouseEventArgs e)
{
float y = e.Location.Y;
for (int i = 0; i < YCoordinates.Count; i++)
{
float Border = YCoordinates[i];
double difference = Math.Abs(y - Border);
if (difference <= 4)
return true;
}
return false;
}
If I get what you're asking, provided you have controls in the cells of the TableLayoutPanel all one would have to do is set the different cursors one time for:
Main form (Arrow)
Table layout panel (Cross)
The controls therein contained (e.g. Hand)
Everything else should happen on its own.
public MainForm()
{
InitializeComponent();
// MainForm has ARROW
this.Cursor = Cursors.Arrow;
// TableLayoutPanel has CROSS
tableLayoutPanel.Cursor = Cursors.Cross;
int key = 0; string text;
for (int column = 0; column < tableLayoutPanel.ColumnCount; column++)
for (int row = 0; row < tableLayoutPanel.RowCount; row++)
{
switch (++key)
{
case 10: text = "*"; break;
case 11: text = "0"; break;
case 12: text = "#"; break;
default: text = $"{key}"; break;
}
tableLayoutPanel.Controls.Add(new Label
{
BackColor = Color.LightGreen,
Anchor = (AnchorStyles)0xF,
Margin = new Padding(10),
Text = text,
TextAlign = ContentAlignment.MiddleCenter,
// Controls in the table have HAND
Cursor = Cursors.Hand,
});
}
}
I am working on a game where a user moves around a 10x10 grid of buttons. The buttons are added to a 2d array and are displayed as shown below. Currently I have the starting position (black player tile) set to index 1 when the form loads. What I am trying to figure out is how I can introduce a button event method that I can use to navigate the tiles.
Here is what the grid looks like:
And here is the code:
private readonly int _xAxis = 10;
private readonly int _yAxis = 10;
private int _count = 1;
private void DrawButtonArray()
{
Button[] buttons = new Button[_xAxis * _yAxis];
int index = 0;
for (int i = 0; i < _xAxis; i++)
{
for (int j = 0; j < _yAxis; j++)
{
Button gridBtn = new Button
{
Size = new Size(60, 55),
Location = new Point(175 + j * 60, 55 + i * 55),
Text = _count.ToString()
};
gridBtn.ForeColor = Color.FromArgb(64, 64, 64);
buttons[index++] = gridBtn;
_count++;
Controls.Add(gridBtn);
if (index == 1)
{
gridBtn.BackColor = Color.Black;
}
}
}
}
What Id hope to achieve is a mouse click event (or possibly WASD key press) that moves the "player" from one button to another. The current idea I have is to set the next button that is clicked to the colour of the current position, then set the current positions colour to the default grey. I just need to know how I could add these event args to the method that doesn't contain them. How might I add them?
I created a method that works, but it might not be the best:
private void DrawButtonArray()
{
Button[] buttons = new Button[_xAxis * _yAxis];
int currentIndex = 0;
for (int i = 0; i < _xAxis; i++)
{
for (int j = 0; j < _yAxis; j++)
{
Button gridBtn = new Button
{
Size = new Size(60, 55),
Location = new Point(175 + j * 60, 55 + i * 55),
Text = _count.ToString()
};
gridBtn.ForeColor = Color.FromArgb(64, 64, 64);
if (currentIndex == 0)
{
gridBtn.BackColor = Color.FromArgb(0, 0, 0);
}
buttons[currentIndex++] = gridBtn;
_count++;
Controls.Add(gridBtn);
}
}
currentIndex = 1;
foreach (Button nextIndex in buttons)
{
nextIndex.Click += (s, e) =>
{
if (nextIndex.Text == (currentIndex + 1).ToString()
|| nextIndex.Text == currentIndex.ToString()
|| nextIndex.Text == (currentIndex - 1).ToString()
|| nextIndex.Text == (currentIndex + 10).ToString()
|| nextIndex.Text == (currentIndex - 10).ToString())
{
buttons[currentIndex - 1].BackColor = Color.FromArgb(64, 64, 64);
currentIndex = int.Parse(nextIndex.Text);
nextIndex.BackColor = Color.Black;
}
else
{
MessageBox.Show("Invalid Move");
}
};
}
}
i have a datagridview on my c# winforms and i want to merge some columns to enter data on it. how will i do that?
i tried some codes from the the net but there are errors and it says: No overload for datagridviewCellPainting that matches the delegate for event handler.
this is my code:
private void General_Inventory_Load(object sender, EventArgs e)
{
dgvGenInventory.Columns.Add("JanWin", "Win");
dgvGenInventory.Columns.Add("JanLoss", "Loss");
dgvGenInventory.Columns.Add("FebWin", "Win");
dgvGenInventory.Columns.Add("FebLoss", "Loss");
dgvGenInventory.Columns.Add("MarWin", "Win");
dgvGenInventory.Columns.Add("MarLoss", "Loss");
dgvGenInventory.Columns.Add("AprWin", "Win");
dgvGenInventory.Columns.Add("AprLoss", "Loss");
dgvGenInventory.Rows.Add("1", "2", "3", "2", "2", "2", "4", "2");
for (int i = 0; i < dgvGenInventory.ColumnCount - 1; i++)
{
dgvGenInventory.Columns[i].Width = 45;
}
this.dgvGenInventory.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
this.dgvGenInventory.ColumnHeadersHeight = this.dgvGenInventory.ColumnHeadersHeight * 2;
this.dgvGenInventory.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter;
this.dgvGenInventory.CellPainting += new DataGridViewCellPaintingEventHandler(dgvGenInventory_CellPainting);
this.dgvGenInventory.Paint += new PaintEventHandler(dgvGenInventory_Paint);
this.dgvGenInventory.Scroll += new ScrollEventHandler(dgvGenInventory_Scroll);
this.dgvGenInventory.ColumnWidthChanged += new DataGridViewColumnEventHandler(dgvGenInventory_ColumnWidthChanged);
}
private void dgvGenInventory_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex == -1 && e.ColumnIndex > -1)
{
Rectangle r2 = e.CellBounds;
r2.Y += e.CellBounds.Height / 2;
r2.Height = e.CellBounds.Height / 2;
e.PaintBackground(r2, true);
e.PaintContent(r2);
e.Handled = true;
}
}
I want to see merged columns on my datagridview
I think, it will be better if you merge data in table first and then bind DataGridview to that table.
try this:
private void Form1_Load(object sender, EventArgs e)
{
m_BuildGrid();
}
private void m_BuildGrid()
{
DataGridViewColumn pColumn;
int i, j;
String strTemp;
HMergedCell pCell;
int nOffset;
dataGridView2.Columns.Add(#"colGroup", #"");
dataGridView2.Columns.Add(#"colTask", #"Task");
pColumn = dataGridView2.Columns["colTask"];
pColumn.Frozen = true;
for (i = 0; i < 25; i++)
{
strTemp = "col" + i.ToString();
dataGridView2.Columns.Add(#strTemp, i.ToString());
pColumn = dataGridView2.Columns[strTemp];
pColumn.SortMode = DataGridViewColumnSortMode.NotSortable;
pColumn.Width = 40;
}
dataGridView2.Rows.Add(20);
nOffset = 2;
for (i = 0; i < 3; i++)
{
for (j = nOffset; j < nOffset + 7; j++)
{
dataGridView2.Rows[0].Cells[j] = new HMergedCell();
pCell = (HMergedCell)dataGridView2.Rows[0].Cells[j];
pCell.LeftColumn = nOffset;
pCell.RightColumn = nOffset + 6;
}
nOffset += 7;
}
for (i = 0; i < 20; i++)
for (j = 0; j < 22; j++)
{
dataGridView2.Rows[i].Cells[j].Value = "{" + i.ToString() + "," + j.ToString() + "}";
}
pColumn = null;
}
}
and add this class to your project
public class HMergedCell : DataGridViewTextBoxCell
{
private int m_nLeftColumn = 0;
private int m_nRightColumn = 0;
/// <summary>
/// Column Index of the left-most cell to be merged.
/// This cell controls the merged text.
/// </summary>
public int LeftColumn
{
get
{
return m_nLeftColumn;
}
set
{
m_nLeftColumn = value;
}
}
/// <summary>
/// Column Index of the right-most cell to be merged
/// </summary>
public int RightColumn
{
get
{
return m_nRightColumn;
}
set
{
m_nRightColumn = value;
}
}
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
try
{
int mergeindex = ColumnIndex - m_nLeftColumn;
int i;
int nWidth;
int nWidthLeft;
string strText;
Pen pen = new Pen(Brushes.Black);
// Draw the background
graphics.FillRectangle(new SolidBrush(SystemColors.Control), cellBounds);
// Draw the separator for rows
graphics.DrawLine(new Pen(new SolidBrush(SystemColors.ControlDark)), cellBounds.Left, cellBounds.Bottom - 1, cellBounds.Right, cellBounds.Bottom - 1);
// Draw the right vertical line for the cell
if (ColumnIndex == m_nRightColumn)
graphics.DrawLine(new Pen(new SolidBrush(SystemColors.ControlDark)), cellBounds.Right - 1, cellBounds.Top, cellBounds.Right - 1, cellBounds.Bottom);
// Draw the text
RectangleF rectDest = RectangleF.Empty;
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
sf.Trimming = StringTrimming.EllipsisCharacter;
// Determine the total width of the merged cell
nWidth = 0;
for (i = m_nLeftColumn; i <= m_nRightColumn; i++)
nWidth += this.OwningRow.Cells[i].Size.Width;
// Determine the width before the current cell.
nWidthLeft = 0;
for (i = m_nLeftColumn; i < ColumnIndex; i++)
nWidthLeft += this.OwningRow.Cells[i].Size.Width;
// Retrieve the text to be displayed
strText = this.OwningRow.Cells[m_nLeftColumn].Value.ToString();
rectDest = new RectangleF(cellBounds.Left - nWidthLeft, cellBounds.Top, nWidth, cellBounds.Height);
graphics.DrawString(strText, new Font("Arial", 10, FontStyle.Regular), Brushes.Black, rectDest, sf);
}
catch (Exception ex)
{
Trace.WriteLine(ex.ToString());
}
}
}
I spent a long time looking for this as my boss didn't want to buy any off-the-shelf components. This should be submitted into the .NET code: datagridvewtextboxcell-with-span-behaviour It just works and is soo simple to use. Works with VB/C# .NET 4.5 to 6. Spans rows and columns including headers.
DataGridView.Columns.Add(new DataGridViewTextBoxColumnEx());
var dataGridViewCell = (DataGridViewTextBoxCellEx)DataGridView[colIdx, rowIdx];
dataGridViewCell.ColSpan = 2;
dataGridViewCell.RowSpan = 6;
EDIT:
Okay so for clarity I will improve my information a bit more:
I have a TableLayoutView (I will call this tlv) that has 5 fixed columns, and x + 2 rows. The first row of tlv contains labels in each cell for header purposes. I dynamically add more rows onto tlv and so that it why it has a variable amount of rows (plus the initial header row which is never removed).
As another tiny small complication, I also keep an empty row entry at the bottom of tlv which I must keep because I use it for other functionality.
To visualise what I have just said, this is an example of tlv consisting with 4 entries (numbered), the header row (H's) and the placeholder row (P's).
HHHHH
11111
22222
33333
44444
PPPPP
I want to go from that, to say, if I wanted to swap entry 2 and 3 the output would be:
HHHHH
11111
33333
22222
44444
PPPPP
The code I have so far is as follows:
for (int j = 0; j < 5; j++)
{
TableLayoutPanelCellPosition tablePosition1 = new
TableLayoutPanelCellPosition(j, rowIndex + 1);
Control moveControl1 = queuedFiles.GetControlFromPosition(j, rowIndex);
queuedFiles.SetCellPosition(moveControl1, tablePosition1);
TableLayoutPanelCellPosition tablePosition2 = new
TableLayoutPanelCellPosition(j, rowIndex);
Control moveControl2 = queuedFiles.GetControlFromPosition(j, rowIndex + 1);
queuedFiles.SetCellPosition(moveControl2, tablePosition2);
if (j.Equals(0))
{
moveControl1.Text = (rowIndex + 1).ToString();
moveControl2.Text = (rowIndex).ToString();
}
}
However this code doesn't work and for the example above it produces:
HHHHH
11111
33222
22333
44444
PPPPP
What I believe is happening is tlv is automatically organising it's contents itself during the process of moving them around (maybe to fill vacant spaces?).
rowIndex above is the index of the target row which must be swapped with the row below it. I don't need to worry about checking if there is only 1 row or if it is the last row because I have done that already. Ignore changing the text too, I just need a pointer as to how I can achieve the intended result!
Thank you for absolutely any help you can give :)
The following code does the job:
Code
using System;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// some content
var panel = new TableLayoutPanel
{
Dock = DockStyle.Fill,
ColumnCount = 5,
RowCount = 2
};
for (var y = 0; y < 2; y++)
for (var x = 0; x < 5; x++)
{
var control = new Button {Text = $#"X = {x}, Y = {y}"};
panel.Controls.Add(control, x, y);
}
// swap button
var button = new Button
{
Dock = DockStyle.Fill,
Text = #"Clicky !"
};
button.Click += (o, args) =>
{
var dictionary = panel.Controls
.Cast<Control>()
.ToDictionary(k => k, v => panel.GetCellPosition(v));
foreach (var pair in dictionary)
{
var position = pair.Value;
position.Row ^= 1; // simple row swap
panel.SetCellPosition(pair.Key, position);
}
};
// add to form
var container = new SplitContainer
{
Dock = DockStyle.Fill,
Orientation = Orientation.Horizontal,
SplitterWidth = 5,
BorderStyle = BorderStyle.Fixed3D
};
container.Panel1.Controls.Add(panel);
container.Panel2.Controls.Add(button);
Controls.Add(container);
}
}
}
Before
After
Note
Next time you ask a question, post a Minimal, Complete, and Verifiable example to maximize your chances of getting an answer !
As on why your code didn't work, see previous sentence, e.g what was rowIndex etc ?
Edit
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
const int cols = 5;
const int rows = 6;
// setup layout
var tlp = new TableLayoutPanel
{
ColumnCount = cols,
RowCount = rows,
Dock = DockStyle.Fill,
GrowStyle = TableLayoutPanelGrowStyle.FixedSize
};
for (var i = 0; i < cols; i++)
tlp.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100.0f / cols));
// add header
var label = new Label
{
Text = #"My Header",
BackColor = Color.Red,
Dock = DockStyle.Fill,
TextAlign = ContentAlignment.MiddleCenter
};
tlp.Controls.Add(label);
tlp.SetColumn(label, 0);
tlp.SetRow(label, 0);
tlp.SetColumnSpan(label, cols);
// add some cells
var yMin = 1;
var yMax = 5;
var xMin = 0;
var xMax = cols;
for (var y = yMin; y < yMax; y++)
for (var x = xMin; x < xMax; x++)
{
var color = Color.FromArgb(
255 / (xMax - xMin) * (x - xMin),
128,
255 / (yMax - yMin) * (y - yMin)
);
var label1 = new Label
{
Text = $#"X = {x}, Y = {y}",
BackColor = color,
ForeColor = Color.White,
Dock = DockStyle.Fill,
TextAlign = ContentAlignment.MiddleCenter,
Margin = DefaultMargin
};
tlp.Controls.Add(label1, x, y);
}
// add swapper
var button = new Button
{
Text = #"Clicky !",
Dock = DockStyle.Fill
};
button.Click += (o, args) =>
{
var srcRow = 2;
var tgtRow = 3;
var controls = tlp.Controls.Cast<Control>().ToArray();
var array1 = controls.Where(s => tlp.GetRow(s) == srcRow).ToArray();
var array2 = controls.Where(s => tlp.GetRow(s) == tgtRow).ToArray();
foreach (var control in array1)
tlp.SetCellPosition(control, new TableLayoutPanelCellPosition(tlp.GetColumn(control), tgtRow));
foreach (var control in array2)
tlp.SetCellPosition(control, new TableLayoutPanelCellPosition(tlp.GetColumn(control), srcRow));
};
// pack things up
var sc = new SplitContainer
{
Orientation = Orientation.Horizontal,
BorderStyle = BorderStyle.Fixed3D,
Dock = DockStyle.Fill
};
sc.Panel1.Controls.Add(tlp);
sc.Panel2.Controls.Add(button);
Controls.Add(sc);
}
}
}
I have a standard panel which I add controls too, when the number of controls exceeds the panels size I want to clear the panel ready for the "next page" of controls which just is a clear and location reset of the buttons. Problem is when ever I clear the controls new ones will not add. Here is what I have:
// MDButList is the collection of controls
ButPosX = 2; // x position of button on panel
ButPosY = 2; // y position of button on panel
PageCount = 1; // page number
for (int i = 0; i <= MDButList.Count - 1; i++)
{
NewPOBut = MDButList[i]; // as cant ref a collection for some reason..
if (i % 14 == 0) // panel can only hold 14
{
if (i < 13) // for first item (0)
SetPOButPos(ref ButPosX, ref ButPosY, ref NewPOBut);
//sets the buttons point value and increments x & y
else
{
panMDItems.Controls.Clear();
ButPosX = 2;
ButPosY = 2;
PageCount++;
SetPOButPos(ref ButPosX, ref ButPosY, ref NewPOBut);
btnPrevPage.Visible = true;
btnNextPage.Visible = true;
labPageNum.Visible = true;
labPageNum.Text = PageCount.ToString() + " / " + PageCount.ToString();
}
}
else
{
SetPOButPos(ref ButPosX, ref ButPosY, ref NewPOBut);
}
}
Controls are being added to the collection and the code steps through as expected but after 14 controls I just get a blank panel nothing above a 14 control count will add? Ask if you need more info, thanks!
I was kind of bored, so i've made a sample of how i would do what you are asking for. This is my code, see if it fits you.
public partial class Form1 : Form
{
private int page = 1;
private int pageCount = 0;
List<Button> MDButList = new List<Button>();
public Form1()
{
InitializeComponent();
GenerateButtons(60);
SetButtons(page);
}
private void GenerateButtons(decimal number)
{
for (int i = 0; i < number; i++)
{
Button a = new Button();
a.Text = "But" + i;
MDButList.Add(a);
}
pageCount = Convert.ToInt32(Math.Ceiling(number / 14));
}
private void SetButtons(int page)
{
labPageNum.Text = page.ToString() + " / " + pageCount.ToString();
int ButPosX = 2;
int ButPosY = 2;
for (int i = panMDItems.Controls.Count - 1; i >= 0; --i)
panMDItems.Controls[i].Dispose();
int upperlimit=(page * 14) - 1;
if (upperlimit>MDButList.Count-1) upperlimit=MDButList.Count-1;
for (int i = (page-1) * 14; i <=upperlimit ; i++)
{
Button NewPOBut = MDButList[i];
SetPOButPos(ref ButPosX, ref ButPosY, ref NewPOBut);
if (i % 2 != 0)
{
ButPosX = 2;
ButPosY += NewPOBut.Height + 10;
}
else
{
ButPosX += NewPOBut.Width + 10;
}
}
}
private void SetPOButPos(ref int ButPosX, ref int ButPosY, ref Button NewPOBut)
{
NewPOBut.Location = new Point(ButPosX, ButPosY);
panMDItems.Controls.Add(NewPOBut);
}
private void btnPrevPage_Click(object sender, EventArgs e)
{
if (page > 1) page--;
SetButtons(page);
}
private void btnNextPage_Click(object sender, EventArgs e)
{
if (page < pageCount) page++;
SetButtons(page);
}
}