Here is my code for setting properties of chart which is attached above:
chart2.ChartAreas[0].CursorX.IsUserEnabled = true;
chart2.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
chart2.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chart2.ChartAreas[0].AxisX.Title = "t";
chart2.ChartAreas[0].AxisY.Title = "w(t)";
chart2.ChartAreas[0].AxisX.Minimum = classes[0].First();
chart2.ChartAreas[0].AxisX.Maximum = classes[m - 1].Last();
chart2.ChartAreas[0].AxisX.Interval = delta_t;
chart2.ChartAreas[0].AxisX.LabelStyle.Format = "{0:0.####}";
I need to add right border of grid so that it will be as it is shown below:
The right border is missing since your data don't nicely fit into the area.
There are many ways to fix this.
Here is the simplest one:
chart2.ChartAreas[0].AxisY2.Enabled = AxisEnabled.True;
chart2.ChartAreas[0].AxisY2.LabelStyle.Enabled = false;
This adds a secondary Y-Axis and turns off its labels.
You can style it as needed:
chart2.ChartAreas[0].AxisY2.MajorTickMark.Enabled = false;
chart2.ChartAreas[0].AxisY2.LineWidth = 3;
You could also draw a line or add an annotation but this is by far the easiest solution.
Related
Is there a way overlap say three images to have them overlap. I am have a case where I bring the top element to the top but it is showing the base layer underneath instead of the second.
Here is what I mean:
Should be this:
The code for it:
// Bottom Box
this.BottomBox.BackColor = Color.Transparent;
this.BottomBox.BackgroundImage = Resource.BottomBox;
this.BottomBox.Name = "BottomBox";
// Middle Box
this.Middle.BackColor = Color.Transparent;
this.Middle.BackgroundImage = Resource.MiddleBox;
this.Middle.Parent = BottomBox;
this.Middle.Name = "Middle";
// Top Box
this.TopBox.BackkColor = Color.Transparent;
this.TopBox.BackgroundImage = Resource.TopBox;
this.TopBox.Parent = MiddleBox;
this.TopBox.Name = "TopBox";
The easiest way to overlap controls/views (images, etc) in WPF is to put them inside a Canvas or a Grid...
In a Canvas, you can alter there relative positions using the attached properties Canvas.Top and Canvas.Left.
In a Grid, you can alter their relative positions using margins...
You can do this in the Constructor of the views immediately below the InitializeComponent method.
Sample Code:
// Bottom Box
this.BottomBox.BackColor = Color.Transparent;
this.BottomBox.BackgroundImage = Resource.BottomBox;
this.BottomBox.Name = "BottomBox";
// Middle Box
this.Middle.BackColor = Color.Transparent;
this.Middle.BackgroundImage = Resource.MiddleBox;
this.Middle.Parent = BottomBox;
this.Middle.Name = "Middle";
// Top Box
this.TopBox.BackkColor = Color.Transparent;
this.TopBox.BackgroundImage = Resource.TopBox;
this.TopBox.Parent = MiddleBox;
this.TopBox.Name = "TopBox";
var canvas = new Canvas();
canvas.Children.Add(this.BottomBox);
canvas.Children.Add(this.TopBox);
canvas.Children.Add(this.Middle);
Canvas.SetLeft(this.BottomBox, 50);
Canvas.SetTop(this.BottomBox, 100);
Canvas.SetLeft(this.Middle, 50);
Canvas.SetTop(this.Middle, 50);
Canvas.SetLeft(this.TopBox, 50);
Canvas.SetTop(this.TopBox, 0);
//put canvas as the main element to display in the view
Try it out and leave a comment if you have any further issue.
I am trying to change the top border of a table in PowerPoint via OpenXml, but it has not worked for me. The cell currently has a left, right, and bottom border, but when I try to copy the bottom border and add it to the top border, PowerPoint does not reflect the change.
What do I need to change or am I doing wrong to make it work?
I currently have the following code to copy the bottom border and replace it.
BottomBorderLineProperties btp = (BottomBorderLineProperties)celda.TableCellProperties.BottomBorderLineProperties.CloneNode(true);
TopBorderLineProperties tbp = new TopBorderLineProperties()
{
Alignment = btp.Alignment,
CapType = btp.CapType,
CompoundLineType = btp.CompoundLineType,
MCAttributes = btp.MCAttributes,
Width = btp.Width
};
foreach(OpenXmlElement element in btp.ChildElements)
{
tbp.Append(element.CloneNode(true));
}
celda.TableCellProperties.TopBorderLineProperties = tbp;
Thanks!
PS: Sorry for my english
In order to set the top border of a cell in the middle of a PowerPoint table, you have to complete 2 steps:
Step 1: set the bottom border of the cell directly above the cell in question and
Step 2: set the top border of the cell in question (you have that part)
I determined this by using the OpenXML Productivity Tool. I took a simple 1 slide PowerPoint file named Before.pptx with a table cell that had the left, bottom and right borders.
Then I added the top border (using PowerPoint 2016) and saved the file as After.pptx. I then used the Productivity Tool to diff the 2 files and reverse engineer the C# code required to make Before.pptx look like After.pptx. The important code you need is displayed here:
//STEP 1 CODE STARTS HERE
A.Table table1=graphicData1.GetFirstChild<A.Table>();
A.TableRow tableRow1=table1.GetFirstChild<A.TableRow>();
A.TableRow tableRow2=table1.Elements<A.TableRow>().ElementAt(1);
A.TableCell tableCell1=tableRow1.Elements<A.TableCell>().ElementAt(2);
A.TableCellProperties tableCellProperties1=tableCell1.GetFirstChild<A.TableCellProperties>();
A.BottomBorderLineProperties bottomBorderLineProperties1 = new A.BottomBorderLineProperties(){ Width = 12700, CapType = A.LineCapValues.Flat, CompoundLineType = A.CompoundLineValues.Single, Alignment = A.PenAlignmentValues.Center };
A.SolidFill solidFill1 = new A.SolidFill();
A.SchemeColor schemeColor1 = new A.SchemeColor(){ Val = A.SchemeColorValues.Text1 };
solidFill1.Append(schemeColor1);
A.PresetDash presetDash1 = new A.PresetDash(){ Val = A.PresetLineDashValues.Solid };
A.Round round1 = new A.Round();
A.HeadEnd headEnd1 = new A.HeadEnd(){ Type = A.LineEndValues.None, Width = A.LineEndWidthValues.Medium, Length = A.LineEndLengthValues.Medium };
A.TailEnd tailEnd1 = new A.TailEnd(){ Type = A.LineEndValues.None, Width = A.LineEndWidthValues.Medium, Length = A.LineEndLengthValues.Medium };
bottomBorderLineProperties1.Append(solidFill1);
bottomBorderLineProperties1.Append(presetDash1);
bottomBorderLineProperties1.Append(round1);
bottomBorderLineProperties1.Append(headEnd1);
bottomBorderLineProperties1.Append(tailEnd1);
tableCellProperties1.Append(bottomBorderLineProperties1);
//STEP 1 CODE ENDS HERE
//STEP 2 CODE STARTS HERE
A.TableCell tableCell2=tableRow2.Elements<A.TableCell>().ElementAt(2);
A.TableCellProperties tableCellProperties2=tableCell2.GetFirstChild<A.TableCellProperties>();
A.BottomBorderLineProperties bottomBorderLineProperties2=tableCellProperties2.GetFirstChild<A.BottomBorderLineProperties>();
A.TopBorderLineProperties topBorderLineProperties1 = new A.TopBorderLineProperties(){ Width = 12700, CapType = A.LineCapValues.Flat, CompoundLineType = A.CompoundLineValues.Single, Alignment = A.PenAlignmentValues.Center };
A.SolidFill solidFill2 = new A.SolidFill();
A.SchemeColor schemeColor2 = new A.SchemeColor(){ Val = A.SchemeColorValues.Text1 };
solidFill2.Append(schemeColor2);
A.PresetDash presetDash2 = new A.PresetDash(){ Val = A.PresetLineDashValues.Solid };
A.Round round2 = new A.Round();
A.HeadEnd headEnd2 = new A.HeadEnd(){ Type = A.LineEndValues.None, Width = A.LineEndWidthValues.Medium, Length = A.LineEndLengthValues.Medium };
A.TailEnd tailEnd2 = new A.TailEnd(){ Type = A.LineEndValues.None, Width = A.LineEndWidthValues.Medium, Length = A.LineEndLengthValues.Medium };
topBorderLineProperties1.Append(solidFill2);
topBorderLineProperties1.Append(presetDash2);
topBorderLineProperties1.Append(round2);
topBorderLineProperties1.Append(headEnd2);
topBorderLineProperties1.Append(tailEnd2);
tableCellProperties2.InsertBefore(topBorderLineProperties1,bottomBorderLineProperties2);
I ran the code above against my Before.pptx file and the border was complete.
In an effort to double check that the two steps are necessary, I commented out the Step 1 code and ran it against a fresh version of Before.pptx file and the top border was missing. This verifies the problem you were seeing. Therefore, the two steps are necessary to paint the one border.
I'm trying to fit image to button perfectly.
But the image is cropped on its right and bottom faces, see attached print screen:
I edited the button as follows:
var l_oStopImage = Image.FromFile(#"C:\Users\AmitL\Downloads\Button-2-stop-icon72p.png");
var l_oStopPic = new Bitmap(l_oStopImage , new Size(btnStopOperation.Width, btnStopOperation.Height));
btnStopOperation.Image = l_oStopPic ;
btnStopOperation.ImageAlign = System.Drawing.ContentAlignment.MiddleCenter;
btnStopOperation.TabStop = false;
btnStopOperation.FlatStyle = FlatStyle.Flat;
btnStopOperation.FlatAppearance.BorderSize = 0;
I also tried to edit the BackgroundImageLayout but none of the ImageLayouts fixed the problem..
Any suggestions?
Thanks in advance
1https://msdn.microsoft.com/en-us/library/system.windows.forms.imagelayout(v=vs.110).aspx
You should use stretch, I suggest in designtime (this is not java where you have to add elements by code):
this.buttonOk.BackColor = System.Drawing.SystemColors.MenuHighlight;
this.buttonOk.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonOk.BackgroundImage")));
this.buttonOk.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonOk.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonOk.Location = new System.Drawing.Point(475, 15);
this.buttonOk.Name = "buttonOk";
this.buttonOk.Size = new System.Drawing.Size(50, 50);
this.buttonOk.TabIndex = 11;
this.buttonOk.UseVisualStyleBackColor = false;
this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
And it will work, done it many times before
I got this code from my own working Form1.Designer.cs but because of that: please use the Visual Studio designer and don't try to write all this code / logic in your constructor or something.
The problem is because you are showing an image with the same size as your button.
When you want an image fit in your button, the width and height of image should be at least 1 point less than your button size. (or in other word, you can set your button width and height 1 point more than the image size).
So you can change your code to this:
var l_oStopPic = new Bitmap(l_oStopImage ,
new Size(btnStopOperation.Width-1, btnStopOperation.Height-1));
On my Chart, I want to put an obvious red vertical bar which goes from a specific point on the plot down to the x-axis. Is there a way to do this? Based on the documentation, it doesn't seem like this option is available or perhaps I'm looking in the wrong area.
The most obvious way is to add a VerticalLineAnnotation.
Here is an example:
First I set up a few things:
int yourPointIndex = 635;
Series S1 = chart1.Series[0];
ChartArea CA1 = chart1.ChartAreas[0];
Now I create the Annotation and style it a little:
VerticalLineAnnotation LA = new VerticalLineAnnotation();
LA.LineColor = Color.Red;
LA.LineWidth = 9;
LA.IsInfinitive = false;
LA.AnchorDataPoint = S1.Points[yourPointIndex]; ;
Now I position it with the Point in question:
LA.X = S1.Points[yourPointIndex].XValue;
LA.Y = S1.Points[yourPointIndex].YValues[0];
// this makes the bar go down to the zero axis
LA.Height = LA.Y;
// this makes it go down all the way to the x-axis:
LA.Height = LA.Y - CA1.AxisY.Minimum;
// we should clip it to our chartarea:
LA.ClipToChartArea = CA1.Name;
Finally it is added to the Annotations collection of the Chart.
chart1.Annotations.Add(LA);
Note that Annotations can be adorned and made to be moveable..
Note: The code above was written for and tested with Winforms but the MS Chart control is rather similar in all its versions..
I am using MSChart in my C# program to create line graphs, and am unable to find any options to create "drop lines" i.e. lines dropping down from each data point to the X-Axis.
Can anyone help?
Thanks.
I solved my problem using the LineAnnotation object:
int index = 1;
foreach (DataPoint _point in series1.Points)
{
LineAnnotation annotation = new LineAnnotation();
annotation.LineColor = Color.Black;
annotation.LineWidth = 4;
annotation.LineDashStyle = ChartDashStyle.Dot;
annotation.AxisX = chartArea1.AxisX;
annotation.AxisY = chartArea1.AxisY;
annotation.AnchorX = index;
annotation.AnchorY = 0;
annotation.Height = _point.YValues[0];
annotation.Width = 0;
annotation.IsSizeAlwaysRelative = false;
annotation.ClipToChartArea = "ChartArea1";
chart1.Annotations.Add(annotation);
index++;
}
Funnily enough, the above code behaved strangely when I anchored the annotation to the data point itself, drawing some lines up and some lines down even though all my points are in the same quadrant. After a lot of playing around, I managed to solve the problem by anchoring the annotation to the appropriate "dropped" point on the X-axis.