Is there a way to add real padding to migradoc table cells? The options that they currently have (LeftPadding and RightPadding) actually work like margins and not like padding. And if you use it, it pushes the background color as well instead of pushing the content only.
This is what happens when you add "padding" to the whole row or individual cells (added it to the first row):
By default it looks like this:
If you wish to remove the white space between the columns, it seems like you have to do it by setting these padding properties to 0 and then you get this:
..which is almost what I want, but I want to push the content of the cell a bit to towards the centre of the cell from all 4 sides so that it looks like this and has a little room to "breathe":
It was even asked on their forums a long time ago about whether this could be done, but the answer doesn't solve the issue at all. It simply mentions the padding properties which work the exact opposite way of what the OP in that thread asked for (which is the same thing I want to do).
I'm using PDFsharp-MigraDoc-gdi v1.50.4000-beta3b nuget package.
Any ways to hack around this odd behaviour? Thanks.
EDIT: updated with a piece of code I use and with added bit recommended by PDFsharp Novice
var table = new Table();
var columnCount = 4;
for (int i = 0; i < columnCount; i++)
{
table.AddColumn();
}
var hedingRow= table.AddRow();
hedingRow.Format.Font.Bold = true;
hedingRow.Format.Font.Color = Color.Parse("0xFFFFFFFF");
hedingRow.Format.Shading.Color = Color.Parse("0xFF005aa0");
hedingRow.HeadingFormat = true;
hedingRow.Cells[0].AddParagraph("Field");
hedingRow.Cells[1].AddParagraph("Type");
hedingRow.Cells[2].AddParagraph("Default");
hedingRow.Cells[3].AddParagraph(String.Empty);
// Doesn't work as I would assume it should based on PDFsharp Novice
hedingRow.Cells[0].Format.LeftIndent = 4;
hedingRow.Cells[0].Format.RightIndent = 4;
hedingRow.Cells[0].Format.Shading.Color = Color.Parse("0xFF005aa0");
You can set the background color for the cell and/or for the text in the cell.
If you set the color for the cell, the padded area will also have the color.
If you set the color the text only, the padded area will have no color.
Related
My sample code to change the cell color is this. range refers to a cell range.
range.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
If i try to change the cell color back to white. Im using this.
range.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);
But this erases my cell range grid lines(default color of the lines are grey) and everything becomes white. i.e.only 'range' grid lines becomes white and all other cells have the default excel grid color.
Thanks
System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);The problem is occuring because the interior colour of the range of cells is not actually white (it just appears white). Each cell by default is actually transparent (-4142).
So do this when you want to set it back to "normal":
range.Interior.Color = -4142
Edit: Best to use Constants and -4142 is equal to xlNone.
Anonymous Type
I don't understand why this doesn't work for you? Can you please refine your question? I tried the following and it worked just fine..
const Int32 transparent_Color = -4142;
//Set Yellow
var Rng = ActiveSheet.Range["D5:E7"];
Rng.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
//Set transparent (gridlines come back, so long as you haven't got other code that is interacting with your cells)
var Rng = ActiveSheet.Range["D5:E7"];
Rng.Interior.Color = transparent_Color;
Trick: Open Excel > Developer Toolbar > Record Macro > select/highlight range > change backcolor to yellow > change backcolor to white. Now set the Style to Normal.
Stop the Macro from recording.
Then press Alt + F11 to go into VBA Editor and look at the code in Module 1.
Simply convert that code to C# - it is almost the exact same Object Model in C# as it is with VB.
It appears as though the PDfPCell class does have a border property on it but not the PdfPTable class.
Is there some property on the PdfPTable class to set the borders of all its contained cells in one statement?
Borders are defined at the level of the cell, not at the level of the table. Hence: if you want to remove the borders of the table, you need to remove the borders of each cell.
By default, each cell has a border. You can change this default behavior by changing the border of each cell. For instance: if you create PdfPCell objects, you use:
cell.setBorder(Rectangle.NO_BORDER);
In case the cells are created internally, you need to change that property at the level of the default cell. See What is the PdfPTable.DefaultCell property used for?
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
For special borders, for instance borders with rounded corners or a single border for the whole table, or double borders, you can use either cell events or table events, or a combination of both. In Chapter 5 of my book "iText in Action - Second Edition", you'll find a PDF with double borders. See the PressPreviews example to see how this was done. Note that all examples from the book were ported to C#. You can find these examples here.
The official site also has examples where the borders are dotted lines, have rounded corners, and so on.
iTextSharp has no setBorder() method.
I tried the following:
cell.HasBorder(Rectangle.NO_BORDER); // <= this did nothing
cell.BorderColor = BaseColor.WHITE; // <= this works for me, but if your document's background is not white, you might not like it
cell.BorderWidth = 0; // <= this works like gangbusters
So it seems the "safest" way to go is to set BorderWidth to zilch AKA nada.
The following worked for me.
cell.Border = Rectangle.NO_BORDER;
How does one set the alignment of text within a chart legend object? I've tried using:
myChartName.Legends["mySeriesName"].Alignment = stringAlignment.Near
With no effect. I've also tried to create custom legend items, again resulting in no effect. Text is ALWAYS centered (along with the series marker) in the legend "box". The only text I have been able to align is the title, but I don't need titles in my application.
My research to date says the legend object is basically a table with (by default) two cells. If that is the case there should be a way to access those cells and manipulate them as table cells. So, what gives? Why can't I access the text alignment properties of the legend object? Clearly, there is something I'm missing, but for the life of me I can't seem to figure this out. Quite frustrating.
Problem solved. The CustomItem approach wasn't working either, so I tried using the LegendCellColumn Class.
I changed the LegendStyle from Column to Row, then added two CellColumns, one for the series symbol and one for the legend text. Set the alignment, margins, and column widths (that turned out to be the trick), and voila; a legend that looks like I want. Here's the code for anyone with a similar issue.
chartSel.Legends[ySeries.Name].CellColumns.Add(new LegendCellColumn("", LegendCellColumnType.SeriesSymbol, ""));
chartSel.Legends[ySeries.Name].CellColumns[0].Alignment = ContentAlignment.TopLeft;
chartSel.Legends[ySeries.Name].CellColumns[0].Margins = new System.Windows.Forms.DataVisualization.Charting.Margins(0, 0, 1, 1);
chartSel.Legends[ySeries.Name].CellColumns[0].MinimumWidth = 250;
chartSel.Legends[ySeries.Name].CellColumns[0].MaximumWidth = 250;
chartSel.Legends[ySeries.Name].CellColumns.Add(new LegendCellColumn("", LegendCellColumnType.Text, ySeries.Name));
chartSel.Legends[ySeries.Name].CellColumns[1].Alignment = ContentAlignment.MiddleLeft;
chartSel.Legends[ySeries.Name].CellColumns[1].Margins = new System.Windows.Forms.DataVisualization.Charting.Margins(0, 0, 1, 1);
chartSel.Legends[ySeries.Name].CellColumns[1].MinimumWidth = 1500;
chartSel.Legends[ySeries.Name].CellColumns[1].MaximumWidth = 1500;
It's probably not the most efficient way to do it, but it works. Technically, the legend symbol and text are still centered in the object, but because I'm forcing the widths of the two columns it has the appearance of being left-justified.
Hopefully, this may help another newbie like me avoid days of consternation.
My understanding is that Legend alignment relates to the Docking property, not really how the text is aligned within the legend. So setting Alignment to Near means positioning the legend box near the Docking direction.
It is quite hard to explain this textually. The MS Chart Samples have a subsection named Chart features -> Legends -> Style and Auto Positioning which will help you play with those two properties and understand how they are meant to work.
For inner legend alignment, you may need to use Legend.CustomItems and define LegendCell individually.
chart.Legends["Default"].CustomItems.Clear();
chart.Legends["Default"].CustomItems.Add(new LegendItem("LegendItem", Color.Red, ""));
chart.Legends["Default"].CustomItems[0].Cells.Add(new LegendCell(LegendCellType.Text, "My text", ContentAlignment.MiddleLeft));
This is described inside the Chart features -> Legends -> Legend Cells section of the samples.
While continuing to try to figure this out I stumbled on this tidbit of info from the following MSDN library page:
http://msdn.microsoft.com/en-us/library/dd456711(v=vs.100).aspx
"NOTE: You cannot adjust the individual legend items and cells in the Chart.Legends collection. To adjust them, use custom legend items."
So, back to the CustomItem route. I've got this code gleaned from several sources (including you, Dominique, thanks):
chartSel.Legends.Add(ySeries.Name);
chartSel.Series[ySeries.Name].IsVisibleInLegend = false;
chartSel.Legends[ySeries.Name].CustomItems.Clear();
LegendItem li = new LegendItem();
li.ImageStyle = LegendImageStyle.Line;
li.Cells.Add(LegendCellType.SeriesSymbol, "", ContentAlignment.TopLeft);
li.Cells[0].BackColor = Color.CornflowerBlue; //color is only to see the cell bounds
li.Cells.Add(LegendCellType.Text, ySeries.Name, ContentAlignment.TopLeft);
li.Cells[1].BackColor = Color.Aquamarine; //color is only to see the cell bounds
chartSel.Legends[ySeries.Name].CustomItems.Add(li);
From what I can find it should work, but it doesn't. It results in a legend object with two cells; the first is empty and the second has left-justified text. I tried to post an image of it, but the system says I'm not yet worthy.
Why there is no line for the series symbol is also a mystery, but that's another problem to solve. The text justification issue is my main concern at the moment. It looks like the text within the cells is left-justified as desired, but the cells themselves are centered in the legend object; not what I wanted. I want those cells to be left-justified in the object too, so the first cell is against the left edge of the legend object.
Ideas?
When the Microsoft chart control is zoomed in, the values of the labels and grid lines often looks like 38.2, 39.2, 40.2, 41.2 ... rather than 38,39,40,41. I tried to set the interval offset to correct this by using the code shown below without success.
myChart.ChartAreas[0].AxisX.MinorGrid.IntervalOffset = myChart.ChartAreas[0].AxisY.ScaleView.ViewMinimum % 1;
myChart.ChartAreas[0].AxisX.IntervalOffset = myChart.ChartAreas[0].AxisY.ScaleView.ViewMinimum % 1;
What is the proper way to get the major and minor grid-lines and labels to be drawn starting at a specific value?
Your problems might be caused by margins being added. Make sure you set
myChart.ChartArea[0].AxisX.IsMarginVisible = false;
I have a DataGrid with some template columns that contain another DataGrid. My problem is that if some rows have a lot of content in them their height doesn't adjust so the whole content is visible, but rather it's cut off, giving the impression that the rows overlap. However, as soon as I add a new row to the grid or add a new row to the mini-grid inside one of the main grid's rows, the layout gets updated and the row heights are resized correctly.
So the problem is only when loading the grid the first time.
Is there a way to force the grid to size the rows heights to their content?
Thanks
I had some serious trouble with this (bug?) today, so I'll share what I tried and what almost worked... (And hope that someone knows an actual fix)
In my case the bug only appeared when there were 10 or more rows. Out of the rows, ten first rows would in some cases have too small height for the contents. (I first thought that the nine items were drawn on top of each other, which was stupid of me.) There are quite many columns, so there's a scrollbar. Clicking on the scrollbar resizes the heights to proper values.
Some things that in my experience do not work:
Changing virtualization settings had no effect.
InvalidateVisual() and InvalidateArrange() don't work. Tried both datagrid and its parent.
Changing the height of datagrid did not work (although I'm not quite happy with my tests here)
Forcing the datatemplates of the cells to a specific size did not have an effect.
Placing the datagrid inside a scrollviewer (so that the datagrid would have all the space it could ever need...) did not work.
However:
The one thing (I found) that the datagrid seems to respect is MinRowHeight-setting, so now I've got there a moronic value and I'm hoping that this won't cause problems later on when the datatemplates are modified.
I experienced the same bug with the DataGrid that comes with the .NET Framework 4.0.
Under certain circumstances (no horizontal scrollbar, window is bigger than a specific size, ...) the rows were not displayed correctly but placed on top of another (with a small offset), so just the last row was completely visible.
First I tried to perform a UI-action automatically after the rows are filled in the DataGrid, so the layout is updated. But then I found out, that you can just re-render the control using the dispatcher, which, in my case, fixed the bug eventually.
My whole code-change basically is this (right after filling the DataGrid):
Action emptyAction = delegate() { };
myDataGrid.Dispatcher.Invoke(DispatcherPriority.Render, emptyAction);
I'm not sure what is this, but you could try call InvalidateVisual(), some time later, when element is loaded. This forces complete new layout pass...
The DataGrid in my UserControl is doing the same thing. In this example, there are only 32 rows of data with five DataGridTemplateColumns consisting of an <Image> and four <TextBlock>s.
My control shows search results, if I rerun the same search it does not always do this. In addition, the cropping only occurs, roughly, on the first pageful of results. Rows further down are ok.
Using InvalidateVisual() does not help.
If anyone has any ideas on how to solve this or can indicate if this is a known issue with that control, I'd be interested in hearing about it.
In my case I just needed to add the first row before the loop adding extras.
I wanted 4 columns and n rows like this:
private void InitToList() {
Grid wp = new Grid();
wp.Margin = new Thickness(0);
wp.ColumnDefinitions.Add(new ColumnDefinition());
wp.ColumnDefinitions.Add(new ColumnDefinition());
wp.ColumnDefinitions.Add(new ColumnDefinition());
wp.ColumnDefinitions.Add(new ColumnDefinition());
wp.RowDefinitions.Add(new RowDefinition()); // adding this fixed the overlapping
int curCol = 0;
int curRow = 0;
foreach (string name in toIds) {
if (curCol >= wp.ColumnDefinitions.Count()) {
wp.RowDefinitions.Add(new RowDefinition());
curCol = 0;
curRow++;
}
CheckBox cb = new CheckBox();
cb.Name = String.Format("{0}Check", name.ToLower().Replace(" ", ""));
cb.IsChecked = false;
cb.Margin = new Thickness(5, 5, 5, 5);
cb.Content = name;
Grid.SetColumn(cb, curCol);
Grid.SetRow(cb, curRow);
wp.Children.Add(cb);
curCol++;
}