Button image sides cropped - c#

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));

Related

How to add border to cell with openxml in PowerPoint?

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.

Image doesn't show in picturebox c#

I want copy image from one picturebox to another. The code below:
PictureBox pictureBoxRain1 = new PictureBox();
pictureBoxRain1.Size = size;
//pictureBoxRain1.Image = (Image)Properties.Resources.kaplja;
pictureBoxRain1.Image = Image.FromFile(#"C:\images\kaplja.png");
//pictureBoxRain1.ImageLocation = pictureBoxRain.I;
//pictureBoxRain1.Image = Graphics.FromImage();
//pictureBoxRain1.InitialImage = Properties.Resources.kaplja;
//pictureBoxRain1.BackgroundImage = Properties.Resources.kaplja;
pictureBoxRain1.Location = new Point(pictureBoxRain.Location.X + pictureBoxGrass.Size.Width + 10, pictureBoxRain.Location.Y);
Controls.Add(pictureBoxRain1);
All anothers properties copy perfectly to pictureBoxRain1 from pictureBoxRain, but image doesn't want show. Where is problem? I checked many variants such as copy image from Properties.Resources, and reading direct from file and some others(look comments in code above), but nothing works.
EDIT
Check the pictureBoxRain1.SizeMode.

XRLabel.Angle at Runtime

iam using DevExpress v.10.2 and want to show a XRLabel on XtraReport with Angle. If iam using the Designer it is working fine. But now i want to do this at runtime, because the Label.Text is dynamic. My Problem is that the Report doesnt show my Label. I read some DevExpress Support article, which descripe that it is just working on PDF-Format. But in my case i just see a small grey line.
I tried following to just populating my XRLabel for the first:
XRLabel druckinfo = new XRLabel();
druckinfo.Text = string.Format("SB{0} {1} EMAIL {2}", _Sachbearbeiter.Sbnr, _Kennung,
_Sachbearbeiter.Email1); //The values are filled and working.
druckinfo.Visible = true;
druckinfo.AutoWidth = false;
druckinfo.Angle = 90;
druckinfo.Font = new Font("Arial", 6f);
band.Controls.Add(druckinfo); //This is the DetailBand where i add other Labels too and its working fine.
druckinfo.HeightF = 500f; //Setting Height very high, because the text turns and i thought this is working. But seems to have no effect :(
druckinfo.LocationF = new PointF(400f, 400f);
druckinfo.Borders = DevExpress.XtraPrinting.BorderSide.All;
If i delete following line:
druckinfo.Angle = 90;
the Label becomes show fine but without Angle for sure.
Here a Screenshot which shows the Label with top settings on the PDF:
This are the settings of my Report:
_Report.PaperKind = PaperKind.A4;
_Report.ReportUnit = ReportUnit.HundredthsOfAnInch;
_Report.ShowPrintMarginsWarning = false;
_Report.Margins = new Margins(0, 0, 0, 0);
All other Properties are on default value. The Bands which exists are following:
PageHeaderBand
DetailBand
PageFooterBand
regards
This seems to be working :) I am not sure why this works and my top post dont. But i copied the code which is generated by designer and now it works.
XRLabel druckinfo = new XRLabel();
druckinfo.Angle = 90F;
druckinfo.Padding = new PaddingInfo(2, 2, 0, 0, 96F);
druckinfo.SizeF = new SizeF(29.16666F, 500F);
druckinfo.Font = new Font("Arial",8f);
druckinfo.Text = text;
_Band.Controls.Add(druckinfo);
druckinfo.LocationF = new PointF(0F, 500F);

Can't make PictureBox to be visible- C#

I'm trying to use PictureBox object in order to display an image, but i get some "errors" . If i just add the PictureBox attributes (location, image, size, backColor etc... ) i don't see any image
I then read i need to add the PictureBox to the Form Controller.
I added it and yet, still nothing ... is there any priority of the layers (what in the back what in the front ?, how can i change it ?)
here is the attributes set of the PictureBox:
imageFile = new PictureBox();
imageFile.Top = 200;
imageFile.Left = 400;
imageFile.Height = 100;// furnitureSize.Height;
imageFile.Width = 100;// furnitureSize.Width;
imageFile.ImageLocation = (Application.StartupPath + "\\ball4.gif");
imageFile.Image = Image.FromFile(Application.StartupPath + "\\lamp3.jpg");
imageFile.Visible = true;
imageFile.BackColor = Color.Black;
imageFile.SizeMode = PictureBoxSizeMode.StretchImage;
ownerForm.Controls.Add(imageFile);
imageFile.Show();
Please help.
Hmm... are you sure you meant
ownerForm.Controls.Add(imageFile);
and not
this.Controls.Add(imageFile);
?
The problem was as i thought ( the pictureBox wasn't in the front)
adding : imageFile.BringToFront(); solved the issue
Thank you all.
You must define size to your picturebox
imageFile.ClientSize = new Size(100, 100);

How do I resize a System.Windows.Forms.ToolBar?

I've not bothered with panels, docking, or anchors. I've simply thrown together a ToolBar control (not ToolStrip) and seem unable to size it.
System.Windows.Forms.ToolBar tb = new System.Windows.Forms.ToolBar();
// Reports 292x28 (approx) if I check width and height
// Basically the width of the form and I assume a default height
tb.Size = new System.Drawing.Size(195, 48);
// Reports 48x48, but does not actually create buttons of that size
// (It reports 48x48 because I'm retrieving 48x48 icons from a ResourceManager (resx))
tb.ButtonSize = new System.Drawing.Size(48, 48); //
The closest thing I found to making my ToolBar taller was:
http://bytes.com/topic/c-sharp/answers/241614-changing-height-toolbar-button
Although it's rather dated. And I didn't understand it. ToolBarButtons don't have Height, Width, or Size properties.
I'm using SharpDevelop, coding completely by hand on Vista, with all the .NET frameworks.
EDIT:
Here is the EXACT code that I am currently using.
#region ImageList/Toolbar
ImageList toolbarImages = new ImageList();
Image wizardToolbarImage = (Bitmap) rm.GetObject("wizard");
Image optionsToolbarImage = (Bitmap) rm.GetObject("configure");
toolbarImages.Images.Add(wizardToolbarImage);
toolbarImages.Images.Add(optionsToolbarImage);
ToolBar toolbarMain = new ToolBar();
toolbarMain.Size = new Size(195, 25); // no effect
ToolBarButton wizardToolbarButton = new ToolBarButton();
ToolBarButton optionsToolbarButton = new ToolBarButton();
wizardToolbarButton.ImageIndex = 0;
wizardToolbarButton.ToolTipText = "Wizard!";
optionsToolbarButton.ImageIndex = 1;
optionsToolbarButton.ToolTipText = "Options!";
toolbarMain.Buttons.Add(wizardToolbarButton);
toolbarMain.Buttons.Add(optionsToolbarButton);
toolbarMain.Appearance = ToolBarAppearance.Normal;
toolbarMain.ButtonSize = new System.Drawing.Size(48, 48); // no effect
toolbarMain.ImageList = toolbarImages;
toolbarMain.ButtonClick += new ToolBarButtonClickEventHandler(toolbarMain_Click);
Controls.Add(toolbarMain);
#endregion
In just about every winforms application I've written, regardless of language or framework, the toolbar could only be made taller by using larger icons.
You can also put the toolstrip inside a Panel and set the Dock property of the tool strip to Fill. And then you can size the Panel to whatever size you need.

Categories