I would like to know how I can horizontally align to center textboxes and labels inside a Frame in VBA. Basically, I want each text box to be placed at the center of the Frame with the corresponding label next to it.
To do this, you need to gather :
UserForm.Width (same for all "rows")
TextBox.Width (different for each TextBox)
Label.Width (different for each Label)
And then :
Label.Left = (UserForm.Width - TextBox.Width - Label.Width) / 2
TextBox.Left = (UserForm.Width - TextBox.Width - Label.Width) / 2 + Label.Width
Related
I've created a textbox redaction on pymupdf that seems to work perfectly.
But when viewing it on Mac OS, the numbers appear incorrect and jumbled. Anyone have an idea what could change a pdf's view for an identical file across OS?
def apply_overlay(
page, new_area, variable, fontsize, color, align, font, is_column=False
):
col = fitz.utils.getColor("white")
variable_area = copy.deepcopy(new_area)
variable_area.y1 = new_area.y0 + fontsize + 3
redaction = page.addRedactAnnot(
variable_area, fill=col, text=" "
) # flags not available
else:
redaction = page.addRedactAnnot(
new_area, fill=col, text=" "
)
page.apply_redactions(images=fitz.PDF_REDACT_IMAGE_NONE)
writer = fitz.TextWriter(page.rect, color=color)
assignment
writer.fill_textbox(
new_area, variable, fontsize=fontsize, warn=True, align=align, font=font
)
writer.write_text(page)
# To show what happened, draw the rectangles, etc.
shape = page.newShape()
shape.drawRect(new_area) # the rect within which we had to stay
shape.finish(stroke_opacity=0) # show in red color
shape.commit()
shape = page.newShape()
shape.drawRect(writer.text_rect) # the generated TextWriter rectangle
shape.drawCircle(writer.last_point, 2) # coordinates of end of text
shape.finish(stroke_opacity=0) # show with blue color
shape.commit()
return shape
I need to fill this image with these values... I already done with "PrintDocument" but you can't automatically export it in PDF... So I'm migrating to iText, but rectangles referentes seens not be the same... While in "PrintDocument" Y value start from top, in iText, they start from bottom...
Old Code:
e.Graphics.DrawString(ParcelaAtual + 1 & " / " & tabParcelas.Rows.Count, Fonte1, Brushes.Black, x + 254, y + 34, Formato1)
New Code: (Not working properly)
PdfCanvas = New iText.Kernel.Pdf.Canvas.PdfCanvas(page)
retangulo = New iText.Kernel.Geom.Rectangle(x + 350, y + 84)
canvas = New iText.Layout.Canvas(PdfCanvas, pdf, retangulo)
texto = (New iText.Layout.Element.Text(ParcelaAtual + 1 & " / " & tabParcelas.Rows.Count).SetFontSize(12).SetBold) ' Fonte 1 | Formato 1
paragrafo = (New iText.Layout.Element.Paragraph().Add(texto))
canvas.Add(paragrafo)
canvas.Close()
So, I think I'll have to remake this... Catch all X/Y values again and etc etc etc....
I think the best way to do this is to draw an image (rectangle) and inside this image draw the texts, but taking the top/left image border as X/Y reference not the top/left from page border...
Sometimes I need only 1 image with values, sometimes I need 3 of them (as shown in imagem below)...
How can I achieve that? (This image below as drawn with "PrintDocument" but I want to draw it with iText to automatically export in PDF)
I would like to adjust the length/height ratio of the scale bar in an image by the DM scripting. As the following code shown, I can adjust the font size by changing "scalebar.componentsetfontinfo("Microsoft Sans Serif", 0, fontsize)", but I do not know how to change the shape (length/height ratio) of rectangle which constitute to the scale bar. Is there any code/command can achieve this? Thanks,
image front:=getfrontimage()
imagedisplay imgdisp=front.imagegetimagedisplay(0)
number nobar=imgdisp.componentcountchildrenoftype(31)
number fontsize=20
imgdisp.applydatabar(0)
component scalebar=imgdisp.componentgetnthchildoftype(31,0)
scalebar.componentsetfontinfo("Microsoft Sans Serif", 0, fontsize)
scalebar.componentsetdrawingmode(1)
When you select a scalebar, you will notice the green points showing that component's rectangle.
You control that rectangle like you control any component rectangle:
number kScaleBar = 31
image img := GetFrontImage()
imageDisplay disp = img.ImageGetImageDisplay(0)
component scaleBar = disp.ComponentGetNthChildOfType( kScaleBar, 0 )
number t,l,b,r
scaleBar.ComponentGetRect(t,l,b,r)
Result("\n Current rect: [" + t + "/" + l + "/" + b + "/" + r )
number sx, sy
img.GetSize( sx, sy )
// Set centered half at bottom
l = sx*1/4
r = sx*3/4
t = sy*17/20
b = sy*19/20
scaleBar.ComponentSetRect(t,l,b,r)
Note, that you can not explicitly specify the length of the scalebar, it will always "snap" to a meaningful fraction within the boundary box, depending on the image calibration.
Setting the bounding rect will also override the font-size, while setting the font-size will override the boundary rect's height.
How do you fade out/in a button in VB.NET properly? I can fadeout/in labels using:
Controls(i).ForeColor = Color.FromArgb(255, alpha, alpha, alpha)
(where Controls(i) is a label from a For Next loop through all controls in Me.Controls; alpha is the value of the RGB, also from a For Next loop).
This did not work for me with buttons because changing the ForeColor leaves the rest of the buttons' UIs visible!
So, the way I'm trying uses a saved Resource image of the button (from a screenshot) and creates a faded in/out version to be displayed as the image in a PictureBox:
Public Function SetImageOpacity(ByVal imgPic As Image, ByVal imgOpac As Double) As Image
Dim bmpPic As New Bitmap(imgPic.Width, imgPic.Height)
Dim grPic As Graphics = Graphics.FromImage(bmpPic)
Dim imgAtt As New ImageAttributes()
Dim cmxPic As New ColorMatrix()
cmxPic.Matrix33 = imgOpac
imgAtt.SetColorMatrix(cmxPic, ColorMatrixFlag.[Default], ColorAdjustType.Bitmap)
grPic.DrawImage(imgPic, New Rectangle(178, 144, bmpPic.Width, bmpPic.Height), imgPic.Width, imgPic.Height, imgPic.Width, imgPic.Height, GraphicsUnit.Pixel, imgAtt)
grPic.Dispose()
imgAtt.Dispose()
Return bmpPic
End Function
(where imgPic is the Resource image of the button, and imgOpac is the opacity on a scale of 1 to 0, where 0 is transparent).
I then use this image to set my PictureBox's image:
picbox.Image = SetImageOpacity(My.Resources.Nextbutton, 1)
However, I get a glitch where, even though the PictureBox is located at coordinates 178, 144, the image it is showing is displayed at the left edge of the form (i.e. wrong X coordinate), with the Y coordinate correct!
I have a feeling it may lie with my call of .DrawImage(...) (at line 8 of the function) - but the MSDN docs on this subject are very unclear to me.
Please link if this has been asked before!
The coordinates in the Graphics grPic are client coords relative to the image itself, not the Form. So (0, 0) is the top left of the image regardless of where that image ends up being displayed in some kind of control.
Try changing it to (0, 0):
grPic.DrawImage(imgPic, New Rectangle(0, 0, bmpPic.Width, bmpPic.Height), imgPic.Width, imgPic.Height, imgPic.Width, imgPic.Height, GraphicsUnit.Pixel, imgAtt)
why not just use a for loop to change the opacity of the button control from 1 to 0 in increments of say .01 ?
I am creating a text box using vba in powerpoint. For that I am using the following code:
Set survey = cSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, 20, 40, 400, 20)
survey.TextFrame.TextRange.text = Me.QuestionBox.text
survey.TextFrame.TextRange.font.SIZE = sh.GroupItems(1).TextFrame.TextRange.font.SIZE
survey.TextFrame.TextRange.font.name = sh.GroupItems(1).TextFrame.TextRange.font.name
survey.width = sh.GroupItems(1).width
survey.height = sh.GroupItems(1).height
survey.top = sh.GroupItems(1).top
survey.left = sh.GroupItems(1).left
As you can notice I am using the size of another shape to make it the same size as it. This is how the shape that I am using (above) and I created (below) looks:
I want it to appear in 2 lines instead of one. You can see that the width and height is correct but instead of going to the second line when it reach to the border of the shape it continues. If you just modify manually the shape below and give a bit more or less width it automatically put the second word in the second line but I cannot make it happen when I do it with vba. Is there something I can use to make it happen automatically?
When you add new shape to the slide, your shape default settings may be preventing wordwrap.
Please try:
survey.TextFrame.WordWrap = msoTrue