Scrolling TableLayoutPanel to button click - c#

I set this to make the scrollbar invisble to my tablelayoutpanel:
tableLayoutPanel1.AutoScroll = false;
tableLayoutPanel1.HorizontalScroll.Visible = false;
tableLayoutPanel1.HorizontalScroll.Maximum = 0;
tableLayoutPanel1.VerticalScroll.Maximum = 0;
tableLayoutPanel1.VerticalScroll.Visible = false;
tableLayoutPanel1.AutoScroll = true;
How Can I set to button click scrolling to right and left?
I tried this:
int change = tableLayoutPanel1.HorizontalScroll.Value + tableLayoutPanel1.HorizontalScroll.SmallChange * 40; tableLayoutPanel1.AutoScrollPosition = new Point(change, 0);
but it's scrolled only once time.

Do it this way instead:
int change = tableLayoutPanel1.HorizontalScroll.SmallChange * 40;
tableLayoutPanel1.AutoScrollPosition = new Point(Math.Abs(tableLayoutPanel1.AutoScrollPosition.X) + change , 0);
We need Math.Abs() since the values returned by AutoScrollPosition are negative.

Related

How to set default zoom on chart using Windows Forms - C#

I want to set default zoom only on Axis X but when I use this code my chart looks like:
My first value is way ahead.
This is the code:
var ca = chart1.ChartAreas["ChartArea1"];
ca.CursorX.IsUserEnabled = true;
ca.CursorX.IsUserSelectionEnabled = true;
ca.CursorX.AutoScroll = true;
chart1.Series["Temp"].XValueType = ChartValueType.DateTime;
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Days;
chart1.ChartAreas[0].AxisX.Interval = 1;
chart1.ChartAreas[0].AxisX.IntervalOffset = 1;
chart1.ChartAreas[0].CursorX.Interval = 0;
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Zoom(chart1.Series[0].Points.Count - 10, chart1.Series[0].Points.Count);
chart1.Series["Temp"].MarkerSize = 10;
chart1.Series["Temp"].IsValueShownAsLabel = true;
So I want to set default zoom on chart only on AxisX when I use mouse to zoom twice the chart looks good. Like that:

Microsoft chart with chart type is Column

I tried to decrease space between space between columns and also wanted to decrease width of columns, but I was only able to adjust width of columns not space between columns.
please help for solution. I really appreciate the effort.
Code snap: `
for (int i = 0; i < dss.Tables[1].Rows.Count; i++)
{
yValues[i] = Convert.ToDouble(dss.Tables[1].Rows[i]["admission"].ToString());
if (isDateRange == 1)
{
xValues[i] = dss.Tables[1].Rows[i]["mth"].ToString().Substring(0, dss.Tables[1].Rows[i]["mth"].ToString().IndexOf(" "));
}
else
{
xValues[i] = dss.Tables[1].Rows[i]["mth"].ToString();
}
zValues[i] = Convert.ToDouble(dss.Tables[1].Rows[i]["readmission"].ToString());
}
chart1.Series[0].Points.DataBindXY(xValues, yValues);
chart1.Series[0].ToolTip = "#AXISLABEL: #VALY";
chart1.Series[0]["PieLabelStyle"] = "Outside";
chart1.Series[0]["PieDrawingStyle"] = "Concave";
chart1.Series[1].Points.DataBindXY(xValues, zValues);
chart1.Series[1].ToolTip = "#AXISLABEL: #VALY";
var chartArea_chart1 = chart1.ChartAreas[chart1.Series[0].ChartArea];
// enable autoscroll
chartArea_chart1.CursorY.AutoScroll = true;
// let's zoom to [0,blockSize] (e.g. [0,100])
chartArea_chart1.AxisX.ScaleView.Zoomable = true;
chartArea_chart1.AxisX.ScaleView.SizeType = DateTimeIntervalType.Number;
//chartArea_chart1.AxisY.ScaleView.Zoomable = true;
//chartArea_chart1.AxisY.ScaleView.SizeType = DateTimeIntervalType.Auto;
//chart1.Series[0].CustomProperties ="PixelPointWidth = 10";
//chart1.Series[0].CustomProperties = "PointWidth = 0.1";
int position = 0;
int size = 30;
chartArea_chart1.AxisX.ScaleView.Zoom(position, size);
// disable zoom-reset button (only scrollbar's arrows are available)
chartArea_chart1.AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;`

DataGridView showing some extra space after last row

I have a Panel control on which I have placed a DataGridView control, showing data from SQL server. It works perfectly except that there is an unnecessary space appearing when I move the scrollbar to the bottom. I shortened the height, but the space still stays there.
My DataGridView was programatically created like:
_myDgv = new DataGridView();
_myDgv.Width = 300;
_myDgv.Height = 500;
_myDgv.Top = 20;
_myDgv.Left = 20;
_myDgv.RowHeadersVisible = false;
_myDgv.AllowUserToAddRows = false;
_myDgv.ColumnHeadersVisible = false;
_myDgv.EnableHeadersVisualStyles = false;
_myDgv.RowTemplate.Height = 30;
_myDgv.AllowUserToResizeColumns = false;
_myDgv.AllowUserToResizeRows = false;
_myDgv.ScrollBars = ScrollBars.None;
_myPanel.Controls.Add(_myDgv);
Can someone tell me how to get rid of the space below the last row when the scrollbar is at the bottom?

Rectangle is showing after clicking on text or checkbox

I have a window application that has some checkboxes. These checkboxes has a image and appearance is set to button.
My problem is when I click on checkbox, a rectangle appears around the checkbox as shown below. I am not getting what property should I set for avoiding this rectangle.
this.chkboxReportSelect.Appearance = System.Windows.Forms.Appearance.Button;
this.chkboxReportSelect.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(215)))), ((int)(((byte)(221)))), ((int)(((byte)(228)))));
this.chkboxReportSelect.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(215)))), ((int)(((byte)(221)))), ((int)(((byte)(228)))));
this.chkboxReportSelect.FlatAppearance.BorderSize = 0;
this.chkboxReportSelect.FlatAppearance.CheckedBackColor = System.Drawing.Color.Transparent;
this.chkboxReportSelect.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Transparent;
this.chkboxReportSelect.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;
this.chkboxReportSelect.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.chkboxReportSelect.Image = global::M3.AKFRW.UI.Properties.Resources.checkmark;
this.chkboxReportSelect.Location = new System.Drawing.Point(3, 3);
this.chkboxReportSelect.Name = "chkboxReportSelect";
this.chkboxReportSelect.Size = new System.Drawing.Size(124, 24);
this.chkboxReportSelect.TabIndex = 27;
this.chkboxReportSelect.Text = "Select Report ";
this.chkboxReportSelect.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
this.chkboxReportSelect.UseCompatibleTextRendering = true;
this.chkboxReportSelect.UseVisualStyleBackColor = false;
I assue you are using FlatStyle. Rectangle you see is the FlatStyle's border, you can get rid of it by setting BorderSize of FlatAppearance to 0
checkbox.FlatAppearance.BorderSize = 0;

C# Add Controls To Panel In a Loop

I wish to add a button for every line in a file to a panel.
My code so far is:
StreamReader menu = new StreamReader("menu.prefs");
int repetition = 0;
while(!menu.EndOfStream)
{
Button dynamicbutton = new Button();
dynamicbutton.Click += new System.EventHandler(menuItem_Click);
dynamicbutton.Text = menu.ReadLine();
dynamicbutton.Visible = true;
dynamicbutton.Location = new Point(4+repetition*307, 4);
dynamicbutton.Height = 44;
dynamicbutton.Width = 203;
dynamicbutton.BackColor = Color.FromArgb(40,40,40);
dynamicbutton.ForeColor = Color.White;
dynamicbutton.Font = new Font("Lucida Console", 16);
dynamicbutton.Show();
menuPanel.Controls.Add(dynamicbutton);
repetition++;
MessageBox.Show(dynamicbutton.Location.ToString());
}
menu.Close();
The problem is that only the first control gets created.
The code looks fine but there could be a following situations.
1.You might have only one entry in the file, so you are experiencing only One Button added to the panel.
2.Your panel width is smaller than the sum of all the dynamic buttons width.
I suspect no 2 is the main reason that is causing problem.
So, I recommend that you use FlowLayoutPanel. To add a dynamic content as it automatically layout all the child controls.
Each time it is generating the same name for dynamic controls. That's the reason why it is showing only the last one. It simply overwrites the previous control each time.
int x = 4;
int y = 4;
foreach(PhysicianData pd in listPhysicians)
{
x = 4;
y = panPhysicians.Controls.Count * 30;
RadioButton rb = new RadioButton();
rb.CheckedChanged += new System.EventHandler(rbPhysician_CheckedChanged);
rb.Text = pd.name;
rb.Visible = true;
rb.Location = new Point(x, y);
rb.Height = 40;
rb.Width = 200;
rb.BackColor = SystemColors.Control;
rb.ForeColor = Color.Black;
rb.Font = new Font("Microsoft Sans Serif", 10);
rb.Show();
rb.Name = "rb" + panPhysicians.Controls.Count;
panPhysicians.Controls.Add(rb);
}
Try this code
StreamReader menu = new StreamReader("menu.prefs");
var str = menu.ReadToEnd();
var items = str.Split(new string[] {"\r\n" } , StringSplitOptions.RemoveEmptyEntries);
foreach (var item in items)
{
Button dynamicbutton = new Button();
dynamicbutton.Click += new System.EventHandler(menuItem_Click);
dynamicbutton.Text = item;
dynamicbutton.Visible = true;
dynamicbutton.Location = new Point(4+repetition*307, 4);
dynamicbutton.Height = 44;
dynamicbutton.Width = 203;
dynamicbutton.BackColor = Color.FromArgb(40,40,40);
dynamicbutton.ForeColor = Color.White;
dynamicbutton.Font = new Font("Lucida Console", 16);
dynamicbutton.Show();
menuPanel.Controls.Add(dynamicbutton);
repetition++;
}
The problem with Panel and similar controls other than the FlowLayoutPanel is when you create a control and a second one, the second is created at the same position if you are not changing it's location dynamically or setting it according to the other already added controls. Your control is there, it's in the back of the first control.
A flowLayoutPanel is better as it will add the controls next to each other as you add them while compromising more finer control at their positioning.
I also have similar problems with panels. For what you are doing it could be useful to just add strings to a listbox rather than using labels and a panel. That should be simpler.

Categories