how can i delete the master slide from the ppt document - c#-3.0

Im beggineer in programming and i'm trying to delete the master slide usign the c# but it always throws an exception "Specified cast is not valid" Is there any way to delete the master slide or shapes on the master slide .. please suggest.
for (int i = 1; i <= SlideCount; i++)
{
int j=i;
slide = Slides[i];
//iterate over all the shapes of notespage of given slide to find the notespage's shape which has text.
for (int k = 1; k <= slide.NotesPage.Shapes.Count; k++)
{
var noteShape = slide.NotesPage.Shapes[k];
//check if the selected notespage has text or not
if (noteShape.Type ==MsoShapeType.msoPlaceholder)
{
if (noteShape.PlaceholderFormat.Type ==PpPlaceholderType.ppPlaceholderBody)
{
if (noteShape.HasTextFrame ==MsoTriState.msoTrue)
{
if (noteShape.TextFrame2.HasText ==MsoTriState.msoTrue)
{
//create a new slide
newslide = tempslides.AddSlide(++j, customLayout);
// set the title of newslide as the text of notepage of previous slide.
newslide.Shapes.Title.TextFrame.TextRange.Text = noteShape.TextFrame.TextRange.Text;
//delete the notepage text;
noteShape.TextFrame.TextRange.Delete();
//delete footer from slide.
//if (newslide.HeadersFooters.Footer.Visible == MsoTriState.msoTrue)
// newslide.HeadersFooters.Footer.Text = string.Empty;
//newslide.HeadersFooters.DateAndTime.Text = string.Empty;
//newslide.HeadersFooters.SlideNumber.Text = string.Empty;
newslide.HeadersFooters.Clear();
newslide.Master.Delete();
//jump to next slide
i++;
//increase the slide count becoz one slide has been added.
SlideCount = tempslides.Count;
}
}
}
}
}
}

You can't delete a master or layout that any slides are based on. Why do you want to delete the master slide?
To delete the shapes:
newslide.Master.Shapes.Range.Delete
That will delete the shapes from the slide master, but not the layout that the slide is based on, so it may not be exactly what you need.

Related

Hw to Freeze the Button in Scroll bar

I am using unity 2018.3.7. In my project I have instantiate 25 buttons in the scroll bar..I am scrolling the button. It is working well.
Actually i want freeze the 12 the button.When i scroll the button. The 12 th button should be constantly should be there and other button should scroll go up.
scrolling should be done but the freeze button should be constantly there.
Like Excel. If we freeze the top row. The top row is constantly there and scrolling is happened.
Like that i have to do in unity.
How to Freeze the button in scroll bar.
Edit:
Actually I have uploaded new gif file. In that gif file 2 row is freezed (Row Heading1,Row Heading2, Row Heading3,RowHeading4).
2nd row is constantly there. Rest of the the rows 4 to 100 rows are going up.
Like that i have to do ...
How can i do it..
Though your question still is very broad I guess I got now what you want. This will probably not be exactly the solution you want since your question is quite vague but it should give you a good idea and starting point for implementing it in the way you need it.
I can just assume Unity UI here is the setup I would use. Since it is quite complex I hope this image will help to understand
so what do we have here:
Canvas
has the RowController script attached. Here reference the row prefab and adjust how many rows shall be added
Panel is the only child of Canvas. I just used it as a wrapper for having a custom padding etc - it's optional
FixedRowPanel
Here we will add the fixed rows on runtime
Initially has a height of 0!
Uses anchore pivot Y = 1! This is later important for changing the height on runtime
Uses a Vertical Layout Group for automatically arranging added children
ScrollView - Your scrollview as you had it but
Uses streched layout to fill the entire Panel (except later the reduced space for the fixed rows)
Uses anchor pivot Y = 1! Again important for changing the height and position on runtime later
Viewport afaik it should already use streched anchors by default but not sure so make it
Content
Uses a Vertical Layout Group
Initially has a height of 0 (but I set this in the code anyway) and will grow and shrink accordingly when adding and removing rows
And finally RowPrefab
I didn't add its hierachy in detail but it should be clear. It has a Toggle and a Text as childs ;)
Has the Row script attached we use for storing and getting some infos
Now to the scripts - I tried to comment everything
The Row.cs is quite simple
public class Row : MonoBehaviour
{
// Reference these via the Inspector
public Toggle FixToggle;
public Text FixTogText;
public Text RowText;
public RectTransform RectTransform;
// Will be set by RowController when instantiating
public int RowIndex;
private void Awake()
{
if (!RectTransform) RectTransform = GetComponent<RectTransform>();
if (!FixToggle) FixToggle = GetComponentInChildren<Toggle>(true);
if (!FixTogText) FixTogText = FixToggle.GetComponentInChildren<Text>(true);
}
}
And here is the RowController.cs
public class RowController : MonoBehaviour
{
public Row RowPrefab;
public RectTransform ScrollView;
public RectTransform Content;
public RectTransform FixedRowParent;
public int HowManyRows = 24;
public List<Row> CurrentlyFixedRows = new List<Row>();
public List<Row> CurrentlyScrolledRows = new List<Row>();
// Start is called before the first frame update
private void Start()
{
// initially the content has height 0 since it has no children yet
Content.sizeDelta = new Vector2(Content.sizeDelta.x, 0);
for (var i = 0; i < HowManyRows; i++)
{
// Create new row instances and set their values
var row = Instantiate(RowPrefab, Content);
// store the according row index so we can later sort them on it
row.RowIndex = i;
row.RowText.text = $"Row Number {i + 1}";
// add a callback for the Toggle
row.FixToggle.onValueChanged.AddListener(s => HandleToggleChanged(row, s));
// increase the content's size to fit the children
// if you are using any offset/padding between them
// you will have to add it here as well
Content.sizeDelta += Vector2.up * row.RectTransform.rect.height;
// don't forget to add them to this list so we can easily access them
CurrentlyScrolledRows.Add(row);
}
}
// called every time a row is fixed or unfixed via the Toggle
private void HandleToggleChanged(Row row, bool newState)
{
if (newState)
{
// SET FIXED
// Update the button text
row.FixTogText.text = "Unfix";
// Move this row to the fixedRow panel
row.transform.SetParent(FixedRowParent);
// be default we assume we want the first position
var targetIndex = 0;
// if there are other fixed rows already find the first child of FixedRowParent that has a bigger value
if (CurrentlyFixedRows.Count > 0) targetIndex = CurrentlyFixedRows.FindIndex(r => r.RowIndex > row.RowIndex);
// handle case when no elements are found -> -1
// this means this row is the biggest and should be the last item
if (targetIndex < 0) targetIndex = CurrentlyFixedRows.Count;
// and finally in the hierachy move it to that position
row.transform.SetSiblingIndex(targetIndex);
// insert it to the fixed list and remove it from the scrolled list
CurrentlyFixedRows.Insert(targetIndex, row);
CurrentlyScrolledRows.Remove(row);
// Make the fixed Panel bigger about the height of one row
FixedRowParent.sizeDelta += Vector2.up * row.RectTransform.rect.height;
// Make both the scrollView and Content smaller about one row
Content.sizeDelta -= Vector2.up * row.RectTransform.rect.height;
ScrollView.sizeDelta -= Vector2.up * row.RectTransform.rect.height;
// Move the scrollView down about one row in order to make space for the fixed panel
ScrollView.anchoredPosition -= Vector2.up * row.RectTransform.rect.height;
}
else
{
// SET UNFIXED - Basically the same but the other way round
// Update the button text
row.FixTogText.text = "Set Fixed";
// Move this row back to the scrolled Content
row.transform.SetParent(Content);
// be default we assume we want the first position
var targetIndex = 0;
// if there are other scrolled rows already find the first child of Content that has a bigger value
if (CurrentlyScrolledRows.Count > 0) targetIndex = CurrentlyScrolledRows.FindIndex(r => r.RowIndex > row.RowIndex);
// handle case when no elements are found -> -1
// this means this row is the biggest and should be the last item
if (targetIndex < 0) targetIndex = CurrentlyScrolledRows.Count;
// and finally in the hierachy move it to that position
row.transform.SetSiblingIndex(targetIndex);
// insert it to the scrolled list
CurrentlyScrolledRows.Insert(targetIndex, row);
// and remove it from the fixed List
CurrentlyFixedRows.Remove(row);
// shrink the fixed Panel about ne row height
FixedRowParent.sizeDelta -= Vector2.up * row.RectTransform.rect.height;
// Increase both Content and Scrollview height by one row
Content.sizeDelta += Vector2.up * row.RectTransform.rect.height;
ScrollView.sizeDelta += Vector2.up * row.RectTransform.rect.height;
// Move scrollView up about one row height to fill the empty space
ScrollView.anchoredPosition += Vector2.up * row.RectTransform.rect.height;
}
}
}
Result:
As you can see I can now fix and unfix rows dynamically while keeping their correct order within both according panels.

Winform chart label wrong position

See Image. The £12,845.63 is 1st columns label. I've tried running below code on a blank, fresh chart, with all default settings (white background too) it does the same thing.
I'm populating chart like this:
private void InitializeData()
{
chart1.Series.Clear();
double i = 0;
double spacing = 0.1;
foreach (DataRow rows in DailyBarChartT.Rows)
{
Series series = chart1.Series.Add(rows[0].ToString());
series.Points.AddXY(i, rows[1]);
series.IsValueShownAsLabel = true;
series.LabelFormat = "C";
series.LabelForeColor = Color.White;
i = i + spacing;
}
chart1.Update();
}
I'm guessing the number doesn't fit above the blue bar? how could I fix this?
I've tried setting label margins to 0 and a few other things.
EDIT:
setting my "spacing" variable to 0, sets the label to correct position.
How can I have it in a correct position with spacing?
You create a new series for every value, which is not how you are supposed to do it. The spacing works properly if you make one single series for all values.
Quick sample code (works on default chart):
string[] values =
{
"12845.63", "1174.89",
"344.04", "180.83",
"82.50", "55.00"
};
chart1.ChartAreas[0].BackColor = Color.Black;
chart1.Series.Clear();
Series series = new Series();
series.IsValueShownAsLabel = true;
series.LabelFormat = "C";
series.LabelForeColor = Color.White;
foreach (var value in values)
{
var pointIndex = series.Points.AddY(value);
series.Points[pointIndex].AxisLabel = "Custom label for each value here";
}
chart1.Series.Add(series);

#officewriter note section is not getting copied while coping slides

I am using below code to add a slide in PPT file at run time:
Presentation pres = ppta.Open(#"C:\Users\prabhat.kumar.yadav\Desktop\PPT\ParentPlan.pptx");
DataPrepration dataObject = new DataPrepration();//Populating Data
int noOfChildSlids = 19;//No of slide we need to add
int sildeInsertPosition = 22;//position where we need to insert child slide
int NoOfChilds = 2;
for (int j = 0; j < NoOfChilds - 1; j++)
{
int sildeCopyPosition = 3;//POstion from where we need to start copy slide
for (int i = 0; i < noOfChildSlids; i++)
{
Slide slideToCopy = pres.Slides[sildeCopyPosition++];
pres.Slides.CopySlide(slideToCopy, (sildeInsertPosition++));
}
}
But the section is not getting copied in the slide added at run time.
There was a bug in SoftArtisan's PowerPointWriter. This was fixed in version 10.1.2.350 of PowerPointWriter. This fix allows the notes of a slide to be copied when copying a slide.

ActiveReport3 subReport iteration

how can I
walk cycle for details subreport(2 textboxes) for make a second textbox strictly under the first but right allign.
Or how else would be a way to indicate that the second textbox has been located under the first but right(allign right)
example
good name
price
another good
name
price
`public void Goods_BeforePrint()
{
Section sec;
sec = rpt.Sections["Goods"];
for(int y= 0; y <= sec.Controls.Count - 1;y++)
{
if( y%2> 0)
{
sec.Controls[y].Height += sec.Controls[y-1].Height;
((TextBox)sec.Controls[y]).Text = System.Convert.ToString(sec.Controls.Count);
}
}`
For now I have 0.25 value of Height in every row.
Problem not in allign but in size of rows, because here not have iteration what I expect and each rows is same size = size of first row.
Your question is not very clear; however on the basis of the expected output, I would suggest you to handle the Format event of the SubReport's detail section and access the control which you want to change the alignment for. So if you want it to appear left aligned twice and right aligned for every third row, the following code should work:
int counter = 0;
private void detail_Format(object sender, EventArgs e)
{
counter++;
if (counter % 3 == 0)
{
this.txtCountry1.Alignment = GrapeCity.ActiveReports.Document.Section.TextAlignment.Right;
}
else
{
this.txtCountry1.Alignment = GrapeCity.ActiveReports.Document.Section.TextAlignment.Left;
}
}
Here is a screenshot from my machine showing a basic example with similar implementation.

Android Dynamic Checkbox

I am in the process of trying to add dynamic checkbox to my activity. However being a beginner i cant get round the basics of being able to add checkboxes and remove them. Here is my code....
private void createCheckbox() {
for(int i=0; i<5; i++){
cb = new CheckBox(this);
ll.addView(cb);
cb.setText("Test");
}
ll.addView(submit);
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
for(int i = 0; i < 5; i++) {
ll.removeView(cb);
}
ll.removeView(submit);
Questions();
}});
}
ll is a linerlayout object. The idea is when the code runs, 5 checkboxes appear and then once the user clicks on the submit button they get removed.
Currently the boxes are being seen, but when the submit button is pressed only one of the five is being removed. I don't understand what i am doing wrong?
For loop not ending correctly, curly bracket wrong place