Creating Settings form using TreeView in C# - c#

I am developing the settings form for the software developed in C#. I was looking at how different software have implemented their settings form.
In most of the cases that I came across, they seem to be using Treeview on the left pane of the form and configuration settings on the right pane.
Ref URL : http://2.bp.blogspot.com/-nMfQoLurxwM/UDXfiZKd4DI/AAAAAAAAAME/IRf6kmxay4w/s1600/bild1.jpg
I was wondering, how the different controls are designed/displayed on the right pane. Do they hide all the controls depending which node is selected in the TreeView something like this :
if (treeView1.SelectedNode == treeView1.Nodes[0])
{
this.groupBox1.Visible = true;
this.button1.Visible = true;
this.textBox1.Visible = true;
this.textBox2.Visible = true;
this.label1.Visible = true;
this.label2.Visible = true;
this.label3.Visible = true;
}
else
{
this.groupBox1.Visible = false;
this.button1.Visible = false;
this.textBox1.Visible = false;
this.textBox2.Visible = false;
this.label1.Visible = false;
this.label2.Visible = false;
this.label3.Visible = false;
this.groupBox2.Visible = true;
this.button2.Visible = true;
this.textBox3.Visible = true;
this.textBox3.Visible = true;
this.labe4.Visible = true;
this.label5.Visible = true;
this.label6.Visible = true;
// bool success = selectColor();
}
Is my understanding correct ? Or do we have a better design approach for creating a settings form.
Thanks

You can create panels and swap their visibility. So depending on what setting is selected, you fill the controls and display a particular panel.

There are many ways but you can have a combination of Treeview control and Tab control. Check this link. This may help. In this link, the tabpages of tabcontrol are used as treeview control nodes.
Have a look at this link too.

Related

Need to hide rows of a table depending on the permission

I have a table that is being use to hold link and image buttons that link the user to other pages on a web site. I want to hide some of these rows depending on the permission the use has. Right now I have:
// Disable buttons if user does not have admin security level
if (Session["SecurityLevel"] != "A")
{
linkbtnNewEmployee.Visible = false;
imgbtnNewEmployee.Visible = false;
linkbtnViewUserActivity.Visible = false;
imgbtnViewUserActivity.Visible = false;
linkbtnEditEmployees.Visible = false;
imgbtnEditEmployees.Visible = false;
linkbtnManageUsers.Visible = false;
imgbtnManageUsers.Visible = false;
}
which will hide the links and buttons, but the table rows still exist. So I have a row or 2 of space between links. I have tried naming rows and using the "rowToHide.style.display = 'none';" command which does not work because it will not recognize the row. The row id shows up in the source code fine, and I use the same ID in the command. Any suggestions? Thanks for your help!
In markup add an Id for the <tr> and runat="server" tag , like this:
<tr id="rowToHide" runat="server>
<!-- Contents here -->
</tr>
And in the code set the visible property to false, like this:
// Disable buttons if user does not have admin security level
if (Session["SecurityLevel"] != "A")
{
rowToHide.Visible = false;
linkbtnNewEmployee.Visible = false;
imgbtnNewEmployee.Visible = false;
linkbtnViewUserActivity.Visible = false;
imgbtnViewUserActivity.Visible = false;
linkbtnEditEmployees.Visible = false;
imgbtnEditEmployees.Visible = false;
linkbtnManageUsers.Visible = false;
imgbtnManageUsers.Visible = false;
}

How to disable zoom in chart control in C#?

How can i disable zoom after mouse selection in System.Windows.Forms.DataVisualization.Charting.Chart control in a .Net 4.0 WinForms application? Actually I want to use selected area in other case but not for zooming.
Just set:
chart.ChartAreas["ChartAreaName"].AxisX.ScaleView.Zoomable = false;
chart.ChartAreas["ChartAreaName"].AxisY.ScaleView.Zoomable = false;
I have the same problem,this helpfull for me.
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = false;
chart1.ChartAreas[0].AxisY.ScaleView.Zoomable = false;

Why does auto Zoom/Scroll not work for my Chart?

to make it short I checked on the "WinFormsChartSamples" provided by Microsoft. What I wanted to know is how to enable zooming and scrolling for Chartcontrols. The example which is shown there is pretty short.
using System.Windows.Forms.DataVisualization.Charting;
...
// Set automatic zooming
chart1.ChartAreas["Default"].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas["Default"].AxisY.ScaleView.Zoomable = true;
// Set automatic scrolling
chart1.ChartAreas["Default"].CursorX.AutoScroll = true;
chart1.ChartAreas["Default"].CursorY.AutoScroll = true;
...
I tried this and nothing happened, no zooming and no scrolling. I tried two things:
In Form1.Designer.cs I added that information to the chart.
chartArea1.Name = "ChartArea1";
chartArea1.CursorX.AutoScroll = true;
chartArea1.CursorY.AutoScroll = true;
chartArea1.AxisX.ScaleView.Zoomable = true;
chartArea1.AxisY.ScaleView.Zoomable = true;
this.chart1.ChartAreas.Add(chartArea1);
this.chart1.Cursor = System.Windows.Forms.Cursors.Cross;
legend1.Name = "Legend1";
this.chart1.Legends.Add(legend1);
this.chart1.Location = new System.Drawing.Point(297, 62);
this.chart1.Name = "chart1";
series1.ChartArea = "ChartArea1";
series1.Legend = "Legend1";
series1.Name = "Series1";
this.chart1.Series.Add(series1);
this.chart1.Size = new System.Drawing.Size(963, 668);
this.chart1.TabIndex = 6;
this.chart1.Text = "chart1";
I tried to add it directly into the constructor in Form1.cs.
Perhaps it is important to mention that I am using OpenFileDialog in order to add data to the series:
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
Stream fileStream = null;
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Open File..";
//First the description of the file separated by "|"
fDialog.Filter = "((ASC files)| *.asc";
fDialog.InitialDirectory = #"C:\";
//Show Messagebox if the file was loaded (Source: MSDN - FileDialog.FilterProperty)
if (fDialog.ShowDialog() == DialogResult.OK)
{
MessageBox.Show("The File was loaded successfully.");
try
{
if ((fileStream = fDialog.OpenFile()) != null)
{
using (fileStream)
{
//Insert code for reading the stream here.
Spectrum newSpectrum = new Spectrum(chart1.Series.Count, fDialog.FileName,
fDialog.SafeFileName, DataHandler.readSpectrumFromFile(fileStream));
addSpectrumToView(newSpectrum);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Any advice is welcome, thanks in advance,
BC++
I think you were actually really looking for this:
chart1.ChartAreas["Default"].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas["Default"].CursorY.IsUserSelectionEnabled = true;
used in conjunction with what you already have should work well, which should look like this:
// Set automatic zooming
chart1.ChartAreas["Default"].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas["Default"].AxisY.ScaleView.Zoomable = true;
// Set automatic scrolling
chart1.ChartAreas["Default"].CursorX.AutoScroll = true;
chart1.ChartAreas["Default"].CursorY.AutoScroll = true;
// Allow user selection for Zoom
chart1.ChartAreas["Default"].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas["Default"].CursorY.IsUserSelectionEnabled = true;
Have a look here: http://archive.msdn.microsoft.com/mschart There is an example there which does zooming/scrolling and much, much more! :)
To enable easy zooming, add a trackbar and use it to zoom:
private void trackBar1_Scroll(object sender, EventArgs e)
{
chart1.ChartAreas[0].AxisX.ScaleView.Size = trackBar1.Maximum - trackBar1.Value;
chart1.ChartAreas[1].AxisX.ScaleView.Size = trackBar1.Maximum - trackBar1.Value;
(etc for however many chart areas you have)
}
the "maximium - value" is to so that the higher the trackbar value, the fewer points are shown (closer zoom)
and make sure that in designer the 'chart1->ChartAreas->Axes->(whichever axes)->scaleview->zoomable' is set to true
A scroll bar will normally appear when a datapoint exceeds the scaleview size of an axis, if it has been set (scrolling doesn't really work reliably if left at 'auto'), if it hasn't, set it, if a scrollbar doesn't appear, a trackbar can yet again be used:
private void trackBar2_ValueChanged(object sender, EventArgs e)
{
chart1.ChartAreas[0].AxisX.ScaleView.Position = trackBar2.Value;
chart1.ChartAreas[1].AxisX.ScaleView.Position = trackBar2.Value;
(etc for however many chart areas you have)
}
Make sure you set the "Maximum" in the trackbars to a nice high number (eg 5000) and "Value" to what you desire it to load at.
Have yet to notice too much of a difference between "trackBar_Scroll" and "trackBar_ValueChanged", except "ValueChanged" works if the trackbar is moved by the program or user mouse click, whereas "Scoll" only works if moved by users mouse click.
Anything I missed?
My users dislikes the standard behavior of the mschart zooming and scrolling. That's why I implement a mouse based zoom/scroll that use dragging and mousewheel on axises.
The source code is here: https://bitbucket.org/controlbreak/mschartfriend
It is very simple and short, you can change it very quickly if you need.

When changing tab selections, child panels are not redrawn unless widnow screen is minimized, maximized or restored

I'm having an issue with a Windows Forms project. I change tabs but the change does not reflect unless I maximize,minimize,or restore the entire window. After that the newly selected tab will show it's child contents.
I've narrowed the issue down to my trying to programmatic create and name a datagridview
I can do this:
logs_datagrid.Name = "datagrid_logs";
logs_datagrid.AutoSize = true;
logs_datagrid.Dock = DockStyle.Fill;
logs_datagrid.Font = new Font("Microsoft Sans Serif", 8.25F);
logs_datagrid.DataSource = dt_logs_google;
logs_datagrid.AllowUserToAddRows = false;
logs_datagrid.BackColor = System.Drawing.Color.White;
logs_datagrid.BringToFront();
splitContainer2.Panel2.Controls.Add(logs_datagrid);
but as soon as I try to programatically apply edits to the datagridview columns the issue occurs. Just uncommenting the top line here will cause the error.
DataGridViewColumn dvg_col_1 = logs_datagrid.Columns[0];
// DataGridViewColumn dgv_col_2 = logs_datagrid.Columns[1];
// DataGridViewColumn dgv_col_3 = logs_datagrid.Columns[3];
//dgv_col_1.ReadOnly = true;
// dgv_col_1.MinimumWidth = 200;
//dgv_col_2.ReadOnly = true;
//dgv_col_2.MinimumWidth = 200;
//dgv_col_3.ReadOnly = true;
//dgv_col_3.MinimumWidth = 200;
// dgv_col_3.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
[edit] Thank you for the help!
Perhaps Update();.
(Didn't check this case, but I've seen Update(); work, when Invalidate(); didn't.)
Try this.Invalidate() of your control
http://windowsclient.net/articles/windowsformspainting.aspx

Troubles with setting ToolTip duration programmatically

I've come across a situtation where I need to create a tooltip object and show it when the user hovers over specific areas in my application.
I can get the tooltip to show up just fine. The problem is I need it to go poof after a few seconds have passed. I'm aware of the ToolTipService.SetShowDuration and I've tried using it, but I have not been met with much luck.
Here's what I got in my MouseMove event handler:
_toolTip.Placement = PlacementMode.Relative;
_toolTip.Horizontal = e.X;
_toolTip.VerticalOffset = e.Y;
_toolTip.Content = stuffs;
_toolTip.IsOpen = true;
I've tried setting the following:
someObject.ToolTip = _toolTip;
ToolTipService.SetShowDuration(someObject, 5);
Nothing changes with the last two lines. The tooltip still is visible and stays visible. Am I using the service wrong or something? Any thoughts would be much appreciated!
Try this.
<Border Name="border" ToolTip="some message" MouseEnter="border_MouseEnter" Background="red" Margin="50"/>
ToolTip tool = new ToolTip();
private void border_MouseEnter(object sender, MouseEventArgs e)
{
tool.Placement = PlacementMode.Relative;
tool.HorizontalOffset = 100;
tool.VerticalOffset = 200;
tool.Content = "stuffs";
tool.IsOpen = true;
border.ToolTip = tool;
ToolTipService.SetShowDuration(border, 5000);
}
I developed a workaround for the issue.
To give a little more background, I have a 3D model of an aircraft inside of a WindowsFormsHost object. When the user hovers over a identified part, I needed a tooltip to appear.
I created an instance of tooltip and in my MouseMove event and I do something like this:
// selectedPart will be null if no part is selected
if(selectedPart != null && prevSelectedPart != selectedPart)
{
toolTip.IsOpen = false;
host.ToolTip = toolTip;
toolTip.IsOpen = true;
}
else if (prevSelectedPart == selectedPart && prevSelectedPart != null)
{
toolTip.IsOpen = true;
}
else
toolTip.IsOpen = false;
That does the trick for me.

Categories

Resources