I'm creating slides for a PowerPoint Presentation using C#. I've so far managed to create tables for a slide using Shape.AddTable method, and the table is created with a default style. I want to be able to change color and line weight for each cell, but I can't seem to find the method to add borders to the cells.
I've tried using learn.microsoft for help, but no luck:
https://learn.microsoft.com/en-us/previous-versions/office/office-12/ff760048(v=office.12)
My code:
int n_rows = 28;
int n_cols = 8;
int row_height = 12;
int font_size = 6;
int top_margin = 1;
int left_margin = 3;
PowerPoint.Shape tb = slide.Shapes.AddTable(n_rows, n_cols, 40, 150, 870, 200);
for (int i = 1; i < n_cols + 1; i++)
{
for(int j=1;j< n_rows + 1;j++)
{
tb.Table.Cell(j, i).Shape.TextFrame.TextRange.Font.Size = font_size;
tb.Table.Cell(j, i).Shape.TextFrame.TextRange.Font.Bold = Office.MsoTriState.msoFalse;
tb.Table.Cell(j, i).Shape.TextFrame.TextRange.Text = "test";
tb.Table.Cell(j, i).Shape.TextFrame.MarginBottom = 0;
tb.Table.Cell(j, i).Shape.TextFrame.MarginTop = top_margin;
tb.Table.Cell(j, i).Shape.TextFrame.MarginLeft = left_margin;
tb.Table.Cell(j, i).Shape.TextFrame.MarginRight = 0;
tb.Table.Cell(j, i).Shape.Fill.ForeColor.RGB = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);
}
}
I found out I had to add Dashstyle and Forecolor property to the Borders like this:
tb.Table.Cell(j, i).Borders[PowerPoint.PpBorderType.ppBorderTop].DashStyle = Office.MsoLineDashStyle.msoLineSolid;
tb.Table.Cell(j, i).Borders[PowerPoint.PpBorderType.ppBorderTop].ForeColor.RGB = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
tb.Table.Cell(j, i).Borders[PowerPoint.PpBorderType.ppBorderTop].Weight = 0.2f;
Now it works!
Related
I want to create a tablelayoutpanel use C#. This is my codes:
private void create_table()
{
table = new TableLayoutPanel();
table.Size = new Size(500, 500);
table.RowCount = rows; //10
table.ColumnCount = cols; //10
table.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
this.table.Location = new System.Drawing.Point(10, 10);
TableLayoutRowStyleCollection rowStyles = this.table.RowStyles;
TableLayoutColumnStyleCollection colStyles = this.table.ColumnStyles;
foreach(RowStyle rowStyle in rowStyles)
{
rowStyle.SizeType = SizeType.Percent;
rowStyle.Height = 10;
}
foreach (ColumnStyle colStyle in colStyles)
{
colStyle.SizeType = SizeType.Percent;
colStyle.Width = 10;
}
this.Controls.Add(table);
}
But it doesn't work. Did I miss something?
enter image description here
Thanks.
What do I want to achieve?
My goal is to create a sudoku field programmatically, so I want to add 9x9 EditText-views to my existing TableLayout.
What is my problem?
Easy said: The EditText-views are not showing up.
What have I tried?
Well.. my google attempts could be recognized as a DDOS-Attack.. ;)
But seriously, I googled a lot, read some documentations etc. but could not find appropriate information solving my problem.
My Sudoku activiy code:
public class Sudoku : Activity
{
private EditText[,] tbs;
private TableLayout grid;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
//set view
SetContentView(Resource.Layout.Sudoku);
//initializations
tbs = new EditText[9,9];
grid = FindViewById<TableLayout> (Resource.Id.grid);
//preparation
prepareControls ();
}
private void prepareControls()
{
int size = Conversion.PixelsToDp(Resources.DisplayMetrics.WidthPixels, Resources.DisplayMetrics.Density) / 15;
int x_default = 10;
int x = x_default;
int y = x_default;
int margin = 4;
RelativeLayout.LayoutParams lparams = new RelativeLayout.LayoutParams (size, size);
for (int row = 0; row < 9; row++)
{
TableRow trow = new TableRow (this);
for (int col = 0; col < 9; col++)
{
//lparams.LeftMargin = x;
//lparams.TopMargin = y;
EditText tb = new EditText (this);
tb.SetHeight (size);
tb.SetWidth (size);
tb.Gravity = GravityFlags.Center;
tb.SetTextColor (Color.Argb (1, 75, 75, 75));
tb.SetBackgroundColor (Color.White);
tb.LayoutParameters = lparams;
tbs[col, row] = tb;
//layout.AddView (tb, lparams);
trow.AddView (tb);
x += size;
if ((col + 1) % 3 == 0)
{
x += margin;
}
if ((col + 1) % 9 == 0)
{
y += size;
x = x_default;
}
}
if ((row + 1) % 3 == 0)
{
y += margin;
}
grid.AddView (trow);
}
}
}
Additional information
Environment: Xamarin
Language: C#
API Level: API 15
I appreciate any help!
I am new to Windows app developemnt:
I have a scenario where i need to display matrix of button with text below that, i am able to do that but the issue here is the matrix can be of any thing 2x2,2x3,2x4 or 2x6.
but the button should be square and not rectangle, if i add image to it then the image looks stretched.
here is my code :
public partial class MainPage : PhoneApplicationPage
{
int numberOfColumns = 2;
int numberOfRows = 3;
public double cellWidth;
public double cellHeight;
// Constructor
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(SetGridCellWidthAndHeight);
}
void SetGridCellWidthAndHeight(object sender, RoutedEventArgs e)
{
cellWidth = GridWindows.ActualHeight / numberOfColumns;
cellHeight = GridWindows.ActualHeight / numberOfRows;
this.GridWindows.Children.Add(SetUpGridLayout());
}
private Grid SetUpGridLayout()
{
Grid grid = new Grid();
grid.Background = new SolidColorBrush(Colors.White);
// Create column and row definitions.
ColumnDefinition[] columnDefinition = new ColumnDefinition[numberOfColumns];
RowDefinition[] rowDefinition = new RowDefinition [numberOfRows];
for (int i = 0; i < columnDefinition.Count(); i++)
{
columnDefinition[i] = new ColumnDefinition();
grid.ColumnDefinitions.Add(columnDefinition[i]);
}
for (int i = 0; i < rowDefinition.Count(); i++)
{
rowDefinition[i] = new RowDefinition();
grid.RowDefinitions.Add(rowDefinition[i]);
}
int count = 1;
for (int row = 0; row < numberOfRows; row++)
{
for (int column = 0; column < numberOfColumns; column++)
{
StackPanel gridViewStackPlanel = new StackPanel();
gridViewStackPlanel.Background = new SolidColorBrush(Colors.White);
Button button = new Button();
button.Width = cellWidth*0.8;
button.Height = cellHeight *0.8;
//topicButton.Background = new SolidColorBrush(Colors.Red);
button.VerticalAlignment = VerticalAlignment.Center;
button.HorizontalAlignment = HorizontalAlignment.Center;
button.Background = new SolidColorBrush(Colors.Red);
//To display the Topic name
TextBlock name= new TextBlock();
name.Text = " Value" + count;
name.Foreground = new SolidColorBrush(Colors.Black);
name.HorizontalAlignment = HorizontalAlignment.Center;
gridViewStackPlanel.Children.Add(button);
gridViewStackPlanel.Children.Add(name);
count++;
grid.Children.Add(gridViewStackPlanel);
Grid.SetColumn(gridViewStackPlanel, column);
Grid.SetRow(gridViewStackPlanel, row);
}
}
return grid;
}
When you write a code like this:
button.Width = cellWidth * 0.8;
button.Height = cellHeight * 0.8;
You would get a square only if cellWidth == cellHeight. And that is most likely not true. So your widths and heights are different. Consider replacing the above with something like this:
cellWidth = Math.Min(GridWindows.ActualHeight / numberOfColumns, GridWindows.ActualHeight / numberOfRows);
button.Width = cellWidth * 0.8;
button.Height = cellWidth * 0.8;
Now it will be square.
i have a working DLL where i have one function to add arrays to a list and another function that shows all list-arrays in a ZED-Graph-diagram. All arrays have the same size.
Currently the x-axis is shown in points from 0 to 1024.
Question is: What do i have to change to display the x-axis in time?
I have the value "Intervall" (time between two points) that i can pass into the function.
Thanks for the help.
Here is what i have so far:
public void AddGraph(double[] Values, string LegendName)
{
int i = 0;
PointPairList list = new PointPairList();
for (i = 0; i < Values.Length; i++)
{
list.Add(i, Values[i]);
}
if (i > MaxXAxis)
MaxXAxis = i;
SList.Add(list);
SListColor.Add(Color.Black);
SListName.Add(LegendName);
}
public void ShowDiagram(string Title, string XAxisName, string YAxisName, int Timeout_ms)
{
ZedGraph.ZedGraphControl zgc = new ZedGraphControl();
GraphPane myPane = zgc.GraphPane;
LineItem myCurve = null;
// Set the titles and axis labels
myPane.Title.Text = Title;
myPane.XAxis.Title.Text = XAxisName;
myPane.YAxis.Title.Text = YAxisName;
for (int i = 0; i < SList.Count(); i++)
{
myCurve = myPane.AddCurve(SListName[i], SList[i], SListColor[i], SymbolType.None);
myCurve.Line.Width = 2;
}
// Add gridlines to the plot, and make them gray
myPane.XAxis.MinorGrid.IsVisible = true;
myPane.YAxis.MinorGrid.IsVisible = true;
myPane.XAxis.MinorGrid.Color = Color.LightGray;
myPane.YAxis.MinorGrid.Color = Color.LightGray;
myPane.XAxis.MinorGrid.DashOff = 0;
myPane.YAxis.MinorGrid.DashOff = 0;
myPane.XAxis.MajorGrid.IsVisible = true;
myPane.YAxis.MajorGrid.IsVisible = true;
myPane.XAxis.MajorGrid.Color = Color.Gray;
myPane.YAxis.MajorGrid.Color = Color.Gray;
myPane.XAxis.MajorGrid.DashOff = 0;
myPane.YAxis.MajorGrid.DashOff = 0;
// Move Legend to buttom
myPane.Legend.Position = LegendPos.Bottom;
zgc.AxisChange();
myPane.XAxis.Scale.Max = MaxXAxis;
zgc.Location = new Point(0, 0);
zgc.Size = new Size(panel_diagramm.ClientRectangle.Width, panel_diagramm.ClientRectangle.Height);
panel_diagramm.Controls.Add(zgc);
}
This is my first time posting so I apologize for not putting it in a better format.
The following allows you to setup your x-axis to display time:
myPane.XAxis.Type = AxisType.Date;
myPane.XAxis.Title.Text = "Time (HH:MM:SS)";
myPane.XAxis.Scale.Format = "HH:mm:ss";
myPane.XAxis.Scale.MajorUnit = DateUnit.Minute;
myPane.XAxis.Scale.MinorUnit = DateUnit.Minute;
myPane.XAxis.Scale.Min = DateTime.Now.Subtract(new TimeSpan(0, 0, 10, 0, 0).ToOADate();
myPane.XAxis.Scale.Max = DateTime.Now.ToOADate();
I'd like to know how could I change the color of the date time axis of my d3 chartplotter.
The color that I want to change is the brown color and the white background color between the two bars.
If i do that :
It only changes the thing above the first brown bar.
Is it possible to change the color of these two bars ?
Curiously, I've happened to be trying to do the same thing. It turns out those colours are hard-coded in MayorDateTimeLabelProvider.cs (I've noted the lines in comments below). If you're using the compiled DLL then there is no way to change the values. Personally, D3 is so immature that I keep my own build of it and make changes to extend it as needed (such as in this case!).
public override UIElement[] CreateLabels(ITicksInfo<DateTime> ticksInfo)
{
object info = ticksInfo.Info;
var ticks = ticksInfo.Ticks;
UIElement[] res = new UIElement[ticks.Length - 1];
int labelsNum = 3;
if (info is DifferenceIn)
{
DifferenceIn diff = (DifferenceIn)info;
DateFormat = GetDateFormat(diff);
}
else if (info is MayorLabelsInfo)
{
MayorLabelsInfo mInfo = (MayorLabelsInfo)info;
DifferenceIn diff = (DifferenceIn)mInfo.Info;
DateFormat = GetDateFormat(diff);
labelsNum = mInfo.MayorLabelsCount + 1;
//DebugVerify.Is(labelsNum < 100);
}
DebugVerify.Is(ticks.Length < 10);
LabelTickInfo<DateTime> tickInfo = new LabelTickInfo<DateTime>();
for (int i = 0; i < ticks.Length - 1; i++)
{
tickInfo.Info = info;
tickInfo.Tick = ticks[i];
string tickText = GetString(tickInfo);
Grid grid = new Grid
{
Background = Brushes.Beige // **** HARD CODED HERE
};
Rectangle rect = new Rectangle
{
Stroke = Brushes.Peru, // **** AND HERE
StrokeThickness = 2
};
Grid.SetColumn(rect, 0);
Grid.SetColumnSpan(rect, labelsNum);
for (int j = 0; j < labelsNum; j++)
{
grid.ColumnDefinitions.Add(new ColumnDefinition());
}
grid.Children.Add(rect);
for (int j = 0; j < labelsNum; j++)
{
var tb = new TextBlock
{
Text = tickText,
HorizontalAlignment = HorizontalAlignment.Center,
Margin = new Thickness(0, 3, 0, 3)
};
Grid.SetColumn(tb, j);
grid.Children.Add(tb);
}
ApplyCustomView(tickInfo, grid);
res[i] = grid;
}
return res;
}