I want to be able to assign each checkbox to it's own richtextbox
I'm making the richtextboxes, then I'm making the checkboxes but how can I "link" them together?
for example :
// richtextbox 1 - > checkbox 1 = false
// richtextbox 2 - > checkbox 2 = true
// richtextbox 3 - > checkbox 3 = true
// richtextbox 4 - > checkbox 4 = false
this is my code:
int n = TodoItems.Count;
RichTextBox[] RichtextBoxes = new RichTextBox[n];
CheckBox[] Checkboxes = new CheckBox[n];
for (int i = 0; i < n; i++)
{
//creating the richtextbox
RichtextBoxes[i] = new RichTextBox();
RichtextBoxes[i].Name = "TB" + i.ToString();
RichtextBoxes[i].Text = TodoItems[i].ToString();
RichtextBoxes[i].Location = new System.Drawing.Point(130, (10 + (60 * i)));
RichtextBoxes[i].Size = new System.Drawing.Size(300, 50);
RichtextBoxes[i].Visible = true;
RichtextBoxes[i].ReadOnly = true;
RichtextBoxes[i].SelectionAlignment = HorizontalAlignment.Center;
RichtextBoxes[i].BackColor = Color.White;
TodoList.Controls.Add(RichtextBoxes[i]);
//creating the checkboxes
Checkboxes[i] = new CheckBox();
Checkboxes[i].Name = "CB" + i.ToString();
Checkboxes[i].Text = "";
Checkboxes[i].Location = new System.Drawing.Point(440, (30 + (60 * i)));
Checkboxes[i].Size = new System.Drawing.Size(18, 17);
Checkboxes[i].Visible = true;
Checkboxes[i].CheckedChanged += new EventHandler(this.CheckedChange);
TodoList.Controls.Add(Checkboxes[i]);
}
I have modified your code please see below, you can access your desired rich text box on checkbox click.
RichTextBox[] RichtextBoxes { get; set; }
CheckBox[] Checkboxes { get; set; }
private void Form1_Load(object sender, EventArgs e)
{
int n = TodoItems.Count;
RichtextBoxes = new RichTextBox[n];
Checkboxes = new CheckBox[n];
for (int i = 0; i < n; i++)
{
//creating the richtextbox
RichtextBoxes[i] = new RichTextBox();
RichtextBoxes[i].Name = "TB-" + i.ToString();
RichtextBoxes[i].Text = TodoItems[i].ToString();
RichtextBoxes[i].Location = new System.Drawing.Point(130, (10 + (60 * i)));
RichtextBoxes[i].Size = new System.Drawing.Size(300, 50);
RichtextBoxes[i].Visible = false;
RichtextBoxes[i].ReadOnly = true;
RichtextBoxes[i].SelectionAlignment = HorizontalAlignment.Center;
RichtextBoxes[i].BackColor = Color.White;
TodoList.Controls.Add(RichtextBoxes[i]);
//creating the checkboxes
Checkboxes[i] = new CheckBox();
Checkboxes[i].Name = "CB-" + i.ToString();
Checkboxes[i].Text = "";
Checkboxes[i].Location = new System.Drawing.Point(440, (30 + (60 * i)));
Checkboxes[i].Size = new System.Drawing.Size(18, 17);
Checkboxes[i].Visible = true;
Checkboxes[i].CheckedChanged += checkBox1_CheckedChanged;
TodoList.Controls.Add(Checkboxes[i]);
}
}
void checkBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox cb = sender as CheckBox;
string cbName = cb.Name;
int sbNumber = int.Parse(cbName.Split('-')[1]);
RichtextBoxes[sbNumber].Visible = true; // you can get desired richtextbox here and can any thing with it :)
}
I have found the answere, and I'll post it to make your life easyer
when I made the richtextboxes and the checkboxes I set there names to a number
Checkboxes[i].Name = i.ToString();
then I used the event that was provided for me by Mirza Danish Baig
Create and event void checkBox_CheckedChanged(object sender, EventArgs e) { } and then assign this event name Checkboxes[i].CheckedChanged += checkBox_CheckedChanged; –
and after that I started to try things eventualy I came to this :
private void checkBox_CheckedChanged(object sender, EventArgs e)
{
CheckBox ThisCheckbox = (CheckBox)sender;
if (ThisCheckbox.Checked == true)
{
//finding the richtextbox by id...
RichTextBox ThisRichtextbox = this.Controls.Find("TB" + ThisCheckbox.Name, true).FirstOrDefault() as RichTextBox;
try//try and catch for testing, this can be removed later.
{
MessageBox.Show(ThisRichtextbox.Text);
}
catch (Exception Exc)
{
MessageBox.Show(Exc.Message);
}
}
}
Related
I have a form like this. You can see my dynamic groupbox (30 groupbox) in Flowlayout on the right, and a picturebox to show questions on the left.
I'm worndering that How to use Click event for each groupbox to show the question equivalent in Picturebox?
Here's my code of groupbox
public GroupBox gbx(String name, int s, string i, string msch)
{
this.Name = int.Parse(i);
this.sda = s;
this.MsCauHoi = msch;
// gb
//
if (s == 2)
{
gb.Controls.Add(cb1);
gb.Controls.Add(cb2);
}
if (s == 3)
{
gb.Controls.Add(cb1);
gb.Controls.Add(cb2);
gb.Controls.Add(cb3);
}
if (s == 4)
{
gb.Controls.Add(cb1);
gb.Controls.Add(cb2);
gb.Controls.Add(cb3);
gb.Controls.Add(cb4);
}
gb.Location = new System.Drawing.Point(219, 44);
gb.Margin = new System.Windows.Forms.Padding(1, 1, 1, 1);
gb.Name = name;
gb.Padding = new System.Windows.Forms.Padding(1, 1, 1, 1);
gb.Size = new System.Drawing.Size(120, 45);
gb.TabIndex = 7;
gb.TabStop = false;
gb.Text = i;
gb.BackColor = Color.Silver;
//
// cb1
//
cb1.AutoSize = true;
cb1.CheckAlign = System.Drawing.ContentAlignment.BottomCenter;
cb1.Location = new System.Drawing.Point(15, 13);
cb1.Margin = new System.Windows.Forms.Padding(0);
cb1.Name = "cb1";
cb1.Size = new System.Drawing.Size(17, 31);
cb1.TabIndex = 0;
cb1.Text = "1";
cb1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
cb1.UseVisualStyleBackColor = true;
cb1.CheckedChanged += delegate (object sender, EventArgs e)
{
CheckBox b = new CheckBox();
b = (CheckBox)sender;
if (b.Checked == true)
{
gb.BackColor = Color.Turquoise;
}
};
//
// cb2
//
cb2.AutoSize = true;
cb2.CheckAlign = System.Drawing.ContentAlignment.BottomCenter;
cb2.Location = new System.Drawing.Point(35, 13);
cb2.Name = "cb2";
cb2.Size = new System.Drawing.Size(17, 31);
cb2.TabIndex = 1;
cb2.Text = "2";
cb2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
cb2.UseVisualStyleBackColor = true;
cb2.CheckedChanged += delegate (object sender, EventArgs e)
{
CheckBox b = new CheckBox();
b = (CheckBox)sender;
if (b.Checked == true)
{
gb.BackColor = Color.Turquoise;
}
};
//
// cb3
//
cb3.AutoSize = true;
cb3.CheckAlign = System.Drawing.ContentAlignment.BottomCenter;
cb3.Location = new System.Drawing.Point(58, 13);
cb3.Name = "cb3";
cb3.Size = new System.Drawing.Size(17, 31);
cb3.TabIndex = 2;
cb3.Text = "3";
cb3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
cb3.UseVisualStyleBackColor = true;
cb3.CheckedChanged += delegate (object sender, EventArgs e)
{
CheckBox b = new CheckBox();
b = (CheckBox)sender;
if (b.Checked == true)
{
gb.BackColor = Color.Turquoise;
}
};
//
// cb4
//
cb4.AutoSize = true;
cb4.CheckAlign = System.Drawing.ContentAlignment.BottomCenter;
cb4.Location = new System.Drawing.Point(81, 13);
cb4.Name = "cb4";
cb4.Size = new System.Drawing.Size(17, 31);
cb4.TabIndex = 3;
cb4.Text = "4";
cb4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
cb4.UseVisualStyleBackColor = true;
cb4.CheckedChanged += delegate (object sender, EventArgs e)
{
CheckBox b = new CheckBox();
b = (CheckBox)sender;
if (b.Checked == true)
{
gb.BackColor = Color.Turquoise;
}
};
return gb;
}
And here's the code of FormLoad
private void FrmThi_Load(object sender, EventArgs e)
{
droptable();
this.CauDaLam = 0;
if (dethi == null) setdethi();
Screen scr = Screen.PrimaryScreen; //đi lấy màn hình chính
this.Left = (scr.WorkingArea.Width - this.Width) / 2;
this.Top = (scr.WorkingArea.Height - this.Height) / 2;
int i = 0;
foreach (DataRow row in this.dethi.Rows)
{
String myValue = row["SoDA"].ToString();
String msch = row["MaCH"].ToString();
ptl = new FrmPhieuTraLoi();
pn_DeThi.Controls.Add(ptl.gbx("cau" + (i + 1).ToString(), int.Parse(myValue), (i + 1).ToString(), msch));
listptl.Add(ptl);
i++;
}
loadcauhoi(this.CauDangLam);
listptl[CauDangLam].setBackColorCDL();
Random r = new Random();
lbmade1.Text = r.Next(1, 4).ToString();
txt = lbSatHachBangLai.Text;
len = txt.Length;
lbSatHachBangLai.Text = "";
timer1.Start();
this.timer2.Start();
}
This is an example code:
private void Form1_Load(object sender, EventArgs e)
{
for(int idx = 0; idx < 5; idx++)
{
var gBox = new GroupBox();
gBox.Height = 50;
gBox.Width = 50;
gBox.Text = "Box: " + idx;
gBox.Tag = idx;
gBox.MouseClick += GBox_MouseClick;
this.Controls.Add(gBox);
}
}
private void GBox_MouseClick(object sender, MouseEventArgs e)
{
//var ctrl = sender as Control; -- Not required
int questionIdx = (int)(sender as Control).Tag;
}
I would extend the GroupBox control and add a property for the Question ID (Add new Item > Custom Control) and change the class to look like this:
public partial class QuestionGroupBox : GroupBox
{
public string QuestionID;
public QuestionGroupBox()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
}
Then populate your flowlayout and set the QuestionID and Click EventHandler, similar to this:
var gb = new QuestionGroupBox{ QuestionID = "44"};
gb.Click += new System.EventHandler(this.questionGroupBox_Click);
//add add to your flow layout
Finally create your event handler to get and display the question
private void questionGroupBox_Click(object sender, EventArgs e)
{
var questionID = ((QuestionGroupBox)sender).QuestionID;
//display your question
}
I have an add user button which dynamically adds a remove button and a username textbox when the user clicks it. The user can click the button as many times as they like and the controls will continue to add.
I am having trouble with the remove button that is created dynamically. It should removed the itself and the username textbox next to it. Instead it will always remove the top row that was added. Also when you click add a new user after you have clicked remove it doesn't automatically fill the blank space - it moves the new textbox and button to the bottom line.
Here is my code:
private void AddUserbtn_Click_1(object sender, EventArgs e)
{
TextBox[] Username = new TextBox[n];
Button[] Remove = new Button[n];
int UsernameX, UsernameY, RemoveX, RemoveY;
UsernameX = 346;
UsernameY = 45;
RemoveX = 946;
RemoveY = 45;
for (int i = 0; i < n; i++)
{
Username[i] = new TextBox();
Username[i].Size = new Size(233, 26);
Username[i].Location = new Point(UsernameX, UsernameY + space);
Username[i].Font = new Font("Arial", 10);
Username[i].Name = "Username" ;
Remove[i] = new Button();
Remove[i].Location = new Point(RemoveX, RemoveY + space);
Remove[i].Text = "Remove";
Remove[i].Font = new Font("Arial", 10);
Remove[i].Size = new Size(95, 23);
Remove[i].UseVisualStyleBackColor = true;
Remove[i].Click += new EventHandler(Remove_Click);
Remove[i].Name = "Remove";
space += 35;
}
for (int i = 0; i < n; i++)
{
CaeUsersPanel.Controls.Add(Username[i]);
CaeUsersPanel.Controls.Add(Remove[i]);
}
}
private void Remove_Click(object sender, EventArgs e)
{
CaeUsersPanel.Controls.Remove(CaeUsersPanel.Controls[("Username")]);
CaeUsersPanel.Controls.Remove(CaeUsersPanel.Controls[("Remove")]);
}
Put a class variant to store Button - TextBox pair, and delete respectively. Quick tested code below - not fine tuned for memory leak / logic etc, just a sample code that fulfills your requirement.
Dictionary<Button, TextBox> pair = new Dictionary<Button, TextBox>(); // A dictionary to store the Button - TextBox pair
private void button1_Click(object sender, EventArgs e) {
int n = 3; // Added for testing
int space = 0; // Added for testing
int UsernameX, UsernameY, RemoveX, RemoveY;
UsernameX = 100; // Modified for testing
UsernameY = 45;
RemoveX = 400; // Modified for testing
RemoveY = 45;
for (int i = 0; i < n; i++) {
var Username = new TextBox();
Username.Size = new Size(233, 26);
Username.Location = new Point(UsernameX, UsernameY + space);
Username.Font = new Font("Arial", 10);
Username.Name = "Username";
var Remove = new Button();
Remove.Location = new Point(RemoveX, RemoveY + space);
Remove.Text = "Remove";
Remove.Font = new Font("Arial", 10);
Remove.Size = new Size(95, 23);
Remove.UseVisualStyleBackColor = true;
Remove.Click += new EventHandler(Remove_Click);
Remove.Name = "Remove";
Controls.Add(Username);
Controls.Add(Remove);
pair.Add(Remove, Username);
space += 35;
}
}
private void Remove_Click(object sender, EventArgs e) {
Controls.Remove((Button)sender); // Removes the delete button
Controls.Remove(pair[(Button)sender]); // Removes the textbox
pair.Remove((Button)sender); // Removes the entry in dictionary
}
Update: Another version for better memory and logic matters. Also shifts up the rest of controls up if it's the OP's desire.
int n = 3; // Added for testing, probably you already have it somewhere
int space = 0; // Added for testing, probably you already have it somewhere
// Moved for logic
// Value modified for testing
int UsernameX = 100;
int UsernameY = 45;
int RemoveX = 400;
int RemoveY = 45;
int SpaceDelta = 35; // Added for logic
List<Button> RemoveButtons = new List<Button>();
List<TextBox> UsernameTextBoxes = new List<TextBox>();
private void button1_Click(object sender, EventArgs e) {
Random rnd = new Random((int)DateTime.Now.Ticks); // Added for testing
for (int i = 0; i < n; i++) {
var Username = new TextBox();
Username.Size = new Size(233, 26);
Username.Location = new Point(UsernameX, UsernameY + space);
Username.Font = new Font("Arial", 10);
Username.Name = "Username";
Username.Text = $"{(int)(rnd.NextDouble() * 100000)}"; // Added for testing
var Remove = new Button();
Remove.Location = new Point(RemoveX, RemoveY + space);
Remove.Text = $"{(int)(rnd.NextDouble() * 100000)}"; // Modified for testing
Remove.Font = new Font("Arial", 10);
Remove.Size = new Size(95, 23);
Remove.UseVisualStyleBackColor = true;
Remove.Click += new EventHandler(Remove_Click);
Remove.Name = "Remove";
Controls.Add(Username);
Controls.Add(Remove);
RemoveButtons.Add(Remove);
UsernameTextBoxes.Add(Username);
space += SpaceDelta;
}
}
private void Remove_Click(object sender, EventArgs e) {
int idx = RemoveButtons.IndexOf((Button)sender);
// Remove button
RemoveButtons[idx].Dispose();
RemoveButtons.RemoveAt(idx);
// Remove textbox
UsernameTextBoxes[idx].Dispose();
UsernameTextBoxes.RemoveAt(idx);
// Shift controls up
for (int i = idx; i < RemoveButtons.Count; i ++) {
RemoveButtons[i].Top -= SpaceDelta;
UsernameTextBoxes[i].Top -= SpaceDelta;
}
space -= SpaceDelta;
}
Remove the two last created :
private void Remove_Click(object sender, EventArgs e)
{
this.Controls.Remove(this.Controls[this.Controls.Count - 1]);
this.Controls.Remove(this.Controls[this.Controls.Count - 1]);
}
I have a split container panel in GUI Form.When a button is clicked in left panel,it pulls out information along with multiple checkboxes on dynamically created panels on the right panel using a loop.Each panel on the right side can have multiple checkboxes based on some condition.For example, the first panel has one checkbox and the second panel below the first has got 8 checkboxes in the same row.When one of the checkboxes in second panel is clicked, I have to get the index of the that panel to do some manipulation. Tab index does not help me to get one as each panel can have any number of checkboxes.I spent a day to get around the problem with no luck. Your help will be much appreciated. I have posted the code below.
for (int j = 0; j < numOfSensors.Count; j++)
{
sensorpanel = new Panel();
sensorpanel.Size = new Size(800, 60);
sensorpanel.Location = new Point(0, Y);
sensorpanel.BackColor = Color.LightGray;
sensorpanel.Paint += new PaintEventHandler(panel_Paint);
Button sensor = new Button();
sensor.Size = new Size(200, 50);
sensor.Location = new Point(1, 1);
sensor.FlatStyle = FlatStyle.Flat;
sensor.FlatAppearance.BorderColor = Color.LightGray;
String sensorType = "Occupancy";
sensor.TextAlign = ContentAlignment.MiddleLeft;
sensor.BackColor = Color.LightGray;
sensor.ForeColor = Color.Black;
sensorpanel.Controls.Add(sensor);
if (sensorType.Equals("Occupancy"))
{
CheckBox cb = new CheckBox();
cb.Location = new Point(380, 15);
cb.Size = new Size(20, 17);
cb.Checked = checkBox(j,0);
cb.Text = "Occupancy";
checksensorbuttons.Add(cb);
cb.CheckedChanged += new EventHandler(cb_CheckChanged);
sensorpanel.Controls.Add(cb);
}
else if (sensorType.Equals("Multi-input:Digital"))
{
int xLoc = 210;
int yLoc = 15;
for (int k = 16; k <32; k+=2)
{
CheckBox cb = new CheckBox();
cb.Location = new Point(xLoc, yLoc);
cb.Size = new Size(20, 17);
cb.Checked = checkBox(j,k);
cb.Text = "Multi-input";
cb.CheckedChanged += new EventHandler(cb_CheckChanged);
sensorpanel.Controls.Add(cb);
xLoc += 30;
}
splitContainer.panel2.Controls.Add(sensorpanel);
}
//checkedchanged eventhandler
private void cb_CheckChanged(object sender, EventArgs e)
{
CheckBox checkbox = (CheckBox)sender;
if (checkbox.Text.Equals("Occupancy"))
{
// How to get the index of the panel when a checkbox in corresponding panel is checked?
if (checkbox.Checked == true)
{
//some manipulation
}
else
{
//some manipulation
}
}
else if (checkbox.Text.Equals("Multi-input"))
{
//get index of the panel where one of the checkboxes are clicked
if (checkbox.Checked == true)
{
//do some manipulation
}
else
{
//do some manipulation
}
}
There are multiple ways
Use Name property of the checkbox. When the checkbox is created assign it a logical name which makes it easier to identify it. Only string can be used here.
Use Tag property of the checkbox to preserve the data you want to refer it. Its good place to store any object and not just string.
Use Parent property of the checkbox to access checkbox's parent properties.
As a best practice, assign a logical name to the dynamic controls. This is the best way to identify the control.
sensorpanel.Name = "panel" + j.ToString();
this.Controls.Add(sensorpanel);
:
:
cb.Text = "Occupancy";
cb.Tag = "panel Index = " + j.ToString();
cb.Name = "panel" + j.ToString() + "_" + "cb_" + cb.Text;
sensorpanel.Controls.Add(cb);
void cb_CheckedChanged(object sender, EventArgs e)
{
CheckBox checkbox = (CheckBox)sender;
string mssg;
mssg = "Name = " + checkbox.Name;
mssg = "tag = " + checkbox.Tag;
mssg = "Parent text = " + checkbox.Parent.Text;
mssg = "Parent name = " + checkbox.Parent.Name;
MessageBox.Show(mssg);
}
I have a checkedListBox in a TabControl
What I want is to create a label and NumericUpDown dynamically, when User check an item of checkedListBox it will show the new label and NumericUpDown
Then , when it Unchecked this item ,The numericUpDown will be clear (empty).
Conclusion: As many checked items , as many w've create labels and NumericUpDowns.
Please, how will I do that ??
For each checkbox item in your checkedListBox in properties switch to events and create subscriber checkBoxName_CheckStateChanged for event CheckStateChanged.
The code in the sucriber can be like this:
private void checkBox1_CheckStateChanged(object sender, EventArgs e)
{
var source = sender as CheckBox;
if (source.Checked == true)
{
this.numericUpDown1.Text = "TextWhenChecked";
this.labelAtTheNumericUpDown.Text = "TextWhenChecked";
}
else
{
this.numericUpDown1.Text = "TextWhenUnchecked";
this.label1.Text = "TextWhenUnchecked";
}
}
You fill the strings as you want. These are only examples.
To have only checkBox checked at a time look at here: https://stackoverflow.com/a/24693858/6650581.
What you need to do is creating Label and NumericUpDown manually and show it by adding to Controls collection. A TableLayoutPanel can help you arranging controls without setting Size and calculate Location manually.
Here is an example:
public class MainForm : Form
{
private CheckedListBox checkedListBox;
private TableLayoutPanel tableLayoutPanel;
public MainForm()
{
InitializeComponent();
//Fill checkedListBox and create controls
for( int i = 0; i <= 5; i++ )
{
checkedListBox.Items.Add( i.ToString() );
Label lbl = new Label()
{
Name = "lbl" + i,
Text = "Label " + i,
Visible = false
};
NumericUpDown num = new NumericUpDown()
{
Name = "num" + i,
Value = i,
Visible = false
};
tableLayoutPanel.Controls.Add( lbl, 0, i );
tableLayoutPanel.Controls.Add( num, 1, i );
}
}
private void checkedListBox_ItemCheck( object sender, ItemCheckEventArgs e )
{
if( e.NewValue == CheckState.Checked )
{
tableLayoutPanel.Controls["lbl" + e.Index].Visible = true;
tableLayoutPanel.Controls["num" + e.Index].Visible = true;
}
else
{
tableLayoutPanel.Controls["lbl" + e.Index].Visible = false;
((NumericUpDown)tableLayoutPanel.Controls["num" + e.Index]).Value = 0M;
}
}
private void InitializeComponent()
{
this.checkedListBox = new System.Windows.Forms.CheckedListBox();
this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
this.SuspendLayout();
//
// checkedListBox
//
this.checkedListBox.Location = new System.Drawing.Point(8, 8);
this.checkedListBox.Name = "checkedListBox";
this.checkedListBox.Size = new System.Drawing.Size(200, 100);
this.checkedListBox.TabIndex = 1;
this.checkedListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.checkedListBox_ItemCheck);
//
// tableLayoutPanel
//
this.tableLayoutPanel.AutoScroll = true;
this.tableLayoutPanel.ColumnCount = 2;
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel.Location = new System.Drawing.Point(8, 112);
this.tableLayoutPanel.Name = "tableLayoutPanel";
this.tableLayoutPanel.Size = new System.Drawing.Size(200, 100);
this.tableLayoutPanel.TabIndex = 2;
//
// MainForm
//
this.ClientSize = new System.Drawing.Size(223, 227);
this.Controls.Add(this.tableLayoutPanel);
this.Controls.Add(this.checkedListBox);
this.Name = "MainForm";
this.ResumeLayout(false);
}
}
I am trying to build a grid of companies generated from my database.
I set my flowlayout as topdown. Is it possible to put a line between rows like this http://data.worldbank.org/country
If needed, my code posted below.
public void createLinks(string[] groupNames)
{
for (int i = 0; i < groupNames.Length; i++)
{
LinkLabel obj = new LinkLabel();
obj.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline;
obj.LinkColor = Color.Black;
obj.Name = groupNames[i];
obj.Text = groupNames[i];
obj.Click += delegate(object sender, EventArgs e)
{LinkLabel ss = sender as LinkLabel;
frmCompanyReport test = new frmCompanyReport(ss.Name);
test.Show();
};
flowLayoutPanel1.Controls.Add(obj);
}
}
One solution is to use a Label to act as a line. Set AutoSize to False, Height to 1, and BorderStyle to FixedSingle. Then set the Width to the same as the FlowLayoutPanel.
Something like:
public void createLinks(string[] groupNames)
{
for (int i = 0; i < groupNames.Length; i++)
{
LinkLabel obj = new LinkLabel();
obj.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline;
obj.LinkColor = Color.Black;
obj.Name = groupNames[i];
obj.Text = groupNames[i];
obj.Click += delegate(object sender, EventArgs e)
{
LinkLabel ss = sender as LinkLabel;
frmCompanyReport test = new frmCompanyReport(ss.Name);
test.Show();
};
flowLayoutPanel1.Controls.Add(obj);
Label line = new Label();
line.AutoSize = false;
line.BorderStyle = BorderStyle.FixedSingle;
line.Height = 1;
line.Width = flowLayoutPanel1.Width;
flowLayoutPanel1.Controls.Add(line);
}
}